Skip to content

Add AnalysisRule resource for contactcenterinsights #13430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1dccc60
Add AnalysisRule resource for contactcenterinsights
scawful Mar 18, 2025
1d03442
Merge branch 'GoogleCloudPlatform:main' into analysis_rule
scawful Mar 19, 2025
3ee5752
Add create test for AnalysisRule
scawful Mar 20, 2025
117e8f5
Update product name to match service name
scawful Mar 20, 2025
b62be87
rename create test templates to match service name
scawful Mar 20, 2025
432525f
Add resource update test for AnalysisRule
scawful Mar 21, 2025
259a039
fix formatting for AnalysisRule
scawful Mar 21, 2025
0fbbcfd
fix formatting for AnalysisRule properties
scawful Mar 21, 2025
2f7945a
Fix qaConfig AnalysisRule formatting and template name
scawful Mar 21, 2025
43fc3f3
add contactcenterinsights to teamcity configs
scawful Mar 24, 2025
0c26d5a
Fix missing comma in services_beta.kt
scawful Mar 24, 2025
499d90c
add missing fields to AnalysisRule resource tests
scawful Mar 25, 2025
f631250
Fix summarization model enum and remove name field from update test
scawful Mar 28, 2025
c296d30
Remove name from test templates
scawful Apr 23, 2025
b08303c
Fix string lists in test template
scawful Apr 23, 2025
7f72713
Fix string lists in AnalysisRule go test
scawful Apr 23, 2025
758857c
Merge branch 'GoogleCloudPlatform:main' into analysis_rule
scawful Apr 24, 2025
73d1cb0
Add resource name to acceptance tests
scawful Apr 30, 2025
df7c479
Remove name from basic test
scawful May 6, 2025
9a6a41d
Fix product name in go test
scawful May 6, 2025
3c8b9e7
Add AnalysisRuleId to test
scawful May 6, 2025
ca92003
Remove name from full resource test template
scawful May 7, 2025
563ca70
Remove analysis_rule_id, does not exist on create
scawful May 7, 2025
998c9d8
Fix summarization config in update full test
scawful May 7, 2025
2c7de56
Fix summarization config in resource test
scawful May 7, 2025
44aa2e6
Add conversation_profile to separate analysis rule test
scawful May 7, 2025
8615982
Remove location_name argument from AnalysisRule yaml, hardcode locati…
scawful May 13, 2025
658343f
Update conversation filter in analysis rule tests
scawful May 14, 2025
9e2f8b9
Add acceptance test for conversation profile source
scawful May 14, 2025
5d87eb3
Fix test template file extension
scawful May 15, 2025
1b3fdbb
Add display_name to analysis rule template test
scawful May 16, 2025
6ce3c9f
Add delete_url to AnalysisRule
scawful May 16, 2025
fbce373
update annotator selector fields to use proper resource names in tests
scawful May 19, 2025
1691a23
update example vars to match resource name structure
scawful May 20, 2025
aa6e1e2
update phrase matcher ID format to numerical in tests
scawful May 20, 2025
44d6b75
Add custom_flatten: name_from_self_link to AnalysisRule YAML and upda…
scawful May 20, 2025
cfb5287
fix test_env_vars in AnalysisRule
scawful May 20, 2025
b7ecab5
fix AnalysisRule resource name flattener
scawful Jun 5, 2025
5ee062c
Update AnalysisRule resource name handling
scawful Jun 12, 2025
4187038
Merge branch 'main' into analysis_rule
scawful Jun 13, 2025
94c82a8
Disable annotators for new AnalysisRules in tests
scawful Jun 13, 2025
3fec4d0
Update analysis rule primary resource IDs
scawful Jun 13, 2025
e7d39e5
Fix AnalysisRule test errors
scawful Jun 16, 2025
ecf5f07
Fix AnalysisRule summarizationModel enum
scawful Jun 16, 2025
11e04fd
Add project_number and annotator for default test
scawful Jun 16, 2025
8ce2384
Add project_number test_env_vars
scawful Jun 17, 2025
6fcc00f
Remove unnecessary analysis_rule_id field from tests
scawful Jun 17, 2025
72ff246
Rename test file and add mock issue model resource
scawful Jun 17, 2025
45e93bf
Disable issue model annotator
scawful Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions mmv1/products/contactcenterinsights/AnalysisRule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Copyright 2024 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
name: AnalysisRule
description: |
The CCAI Insights project wide analysis rule.
This rule will be applied to all conversations that match the filter defined in the rule.
For a conversation matches the filter, the annotators specified in the rule will be run.
If a conversation matches multiple rules, a union of all the annotators will be run.
One project can have multiple analysis rules.
references:
guides:
'Configure analysis rules using the API': 'https://cloud.google.com/contact-center/insights/docs/analysis-rule'
api: 'https://cloud.google.com/contact-center/insights/docs/reference/rest/v1/projects.locations.analysisRules'
base_url: projects/{{project}}/locations/{{location}}/analysisRules
self_link: projects/{{project}}/locations/{{location}}/analysisRules/{{name}}
create_url: projects/{{project}}/locations/{{location}}/analysisRules
delete_url: projects/{{project}}/locations/{{location}}/analysisRules/{{name}}
update_verb: 'PATCH'
update_mask: true
id_format: projects/{{project}}/locations/{{location}}/analysisRules/{{name}}
import_format:
- projects/{{project}}/locations/{{location}}/analysisRules/{{name}}
examples:
- name: 'contact_center_insights_analysis_rule_basic'
primary_resource_id: 'analysis_rule_basic'
- name: 'contact_center_insights_analysis_rule_full'
primary_resource_id: 'analysis_rule_full'
test_env_vars:
project_name: 'PROJECT_NAME'
project_number: 'PROJECT_NUMBER'
- name: 'contact_center_insights_analysis_rule_profile'
primary_resource_id: 'analysis_rule_profile'
test_env_vars:
project_name: 'PROJECT_NAME'
project_number: 'PROJECT_NUMBER'
parameters:
- name: location
type: String
description: Location of the resource.
immutable: true
url_param_only: true
required: true
properties:
- name: name
type: String
description: |-
The resource name of the analysis rule. Randomly generated by Insights.
output: true
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
- name: createTime
type: String
description: Output only. The time at which this analysis rule was created.
output: true
- name: updateTime
type: String
description: Output only. The most recent time at which this analysis rule was updated.
output: true
- name: displayName
type: String
description: Display Name of the analysis rule.
- name: conversationFilter
type: String
description: |-
Filter for the conversations that should apply this analysis
rule. An empty filter means this analysis rule applies to all
conversations.
Refer to https://cloud.google.com/contact-center/insights/docs/filtering
for details.
- name: annotatorSelector
type: NestedObject
description: Selector of all available annotators and phrase matchers to run.
properties:
- name: runInterruptionAnnotator
type: Boolean
description: Whether to run the interruption annotator.
- name: phraseMatchers
type: Array
description: |-
The list of phrase matchers to run. If not provided, all active phrase
matchers will be used. If inactive phrase matchers are provided, they will
not be used. Phrase matchers will be run only if
run_phrase_matcher_annotator is set to true. Format:
projects/{project}/locations/{location}/phraseMatchers/{phrase_matcher}
item_type:
type: String
- name: runEntityAnnotator
type: Boolean
description: Whether to run the entity annotator.
- name: issueModels
type: Array
description: |-
The issue model to run. If not provided, the most recently deployed topic
model will be used. The provided issue model will only be used for
inference if the issue model is deployed and if run_issue_model_annotator
is set to true. If more than one issue model is provided, only the first
provided issue model will be used for inference.
item_type:
type: String
- name: runQaAnnotator
type: Boolean
description: Whether to run the QA annotator.
- name: runSilenceAnnotator
type: Boolean
description: Whether to run the silence annotator.
- name: runPhraseMatcherAnnotator
type: Boolean
description: Whether to run the active phrase matcher annotator(s).
- name: runSentimentAnnotator
type: Boolean
description: Whether to run the sentiment annotator.
- name: runIntentAnnotator
type: Boolean
description: Whether to run the intent annotator.
- name: runIssueModelAnnotator
type: Boolean
description: |-
Whether to run the issue model annotator. A model should have already been
deployed for this to take effect.
- name: runSummarizationAnnotator
type: Boolean
description: Whether to run the summarization annotator.
- name: summarizationConfig
type: NestedObject
description: Configuration for summarization.
properties:
- name: conversationProfile
type: String
description: |-
Resource name of the Dialogflow conversation profile.
Format:
projects/{project}/locations/{location}/conversationProfiles/{conversation_profile}
- name: summarizationModel
type: Enum
description: |-
Default summarization model to be used.
Possible values:
SUMMARIZATION_MODEL_UNSPECIFIED
BASELINE_MODEL
BASELINE_MODEL_V2_0
enum_values:
- 'BASELINE_MODEL'
- 'BASELINE_MODEL_V2_0'
- name: qaConfig
type: NestedObject
description: Configuration for the QA feature.
properties:
- name: scorecardList
type: NestedObject
description: Container for a list of scorecards.
properties:
- name: qaScorecardRevisions
type: Array
description: List of QaScorecardRevisions.
item_type:
type: String
- name: analysisPercentage
type: Double
description: |-
Percentage of conversations that we should apply this analysis setting
automatically, between [0, 1]. For example, 0.1 means 10%. Conversations
are sampled in a determenestic way. The original runtime_percentage &
upload percentage will be replaced by defining filters on the conversation.
- name: active
type: Boolean
description: |-
If true, apply this rule to conversations. Otherwise, this rule is
inactive and saved as a draft.
1 change: 1 addition & 0 deletions mmv1/products/contactcenterinsights/product.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2025 Google Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "google_contact_center_insights_analysis_rule" "{{$.PrimaryResourceId}}" {
location = "us-central1"
display_name = "analysis-rule-display-name"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "google_contact_center_insights_analysis_rule" "{{$.PrimaryResourceId}}" {
location = "us-central1"
display_name = "analysis-rule-display-name"
conversation_filter = "agent_id = \"1\""
annotator_selector {
run_interruption_annotator = false
issue_models = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/issueModels/some_issue_model_id"]
phrase_matchers = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/phraseMatchers/123"]
qa_config {
scorecard_list {
qa_scorecard_revisions = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/qaScorecards/*/revisions/some_scorecard_revision_id"]
}
}
run_entity_annotator = false
run_intent_annotator = false
run_issue_model_annotator = false
run_phrase_matcher_annotator = false
run_qa_annotator = false
run_sentiment_annotator = false
run_silence_annotator = true
run_summarization_annotator = false
summarization_config {
summarization_model = "BASELINE_MODEL"
}
}
analysis_percentage = 0.5
active = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "google_contact_center_insights_analysis_rule" "{{$.PrimaryResourceId}}" {
location = "us-central1"
display_name = "analysis-rule-display-name"
conversation_filter = "agent_id = \"1\""
annotator_selector {
run_interruption_annotator = false
issue_models = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/issueModels/some_issue_model_id"]
phrase_matchers = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/phraseMatchers/123"]
qa_config {
scorecard_list {
qa_scorecard_revisions = ["projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/qaScorecards/*/revisions/some_scorecard_revision_id"]
}
}
run_entity_annotator = false
run_intent_annotator = false
run_issue_model_annotator = false
run_phrase_matcher_annotator = false
run_qa_annotator = false
run_sentiment_annotator = false
run_silence_annotator = true
run_summarization_annotator = false
summarization_config {
conversation_profile = "projects/{{index $.TestEnvVars "project_number"}}/locations/us-central1/conversationProfiles/some_conversation_profile"
}
}
analysis_percentage = 0.5
active = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package contactcenterinsights_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccContactCenterInsightsAnalysisRule_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"project_name": envvar.GetTestProjectFromEnv(),
"project_number": envvar.GetTestProjectNumberFromEnv(),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccInsightsAnalysisRule(context),
},
{
ResourceName: "google_contact_center_insights_analysis_rule.default",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContactCenterInsightsAnalysisRule_full(context),
},
{
ResourceName: "google_contact_center_insights_analysis_rule.basic_analysis_rule",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"analysis_rule_id", "location"},
},
{
Config: testAccContactCenterInsightsAnalysisRule_update(context),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_contact_center_insights_analysis_rule.basic_analysis_rule", plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: "google_contact_center_insights_analysis_rule.basic_analysis_rule",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"analysis_rule_id", "location"},
},
},
})
}

func testAccInsightsAnalysisRule(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_contact_center_insights_analysis_rule" "default" {
display_name = "default-analysis-rule-display-name-%{random_suffix}"
location = "us-central1"
conversation_filter = "agent_id = \"1\""
analysis_percentage = 0.5
annotator_selector {
run_silence_annotator = true
}
active = true
}
`, context)
}

func testAccContactCenterInsightsAnalysisRule_full(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_contact_center_insights_analysis_rule" "basic_analysis_rule" {
display_name = "analysis-rule-display-name-%{random_suffix}"
location = "us-central1"
conversation_filter = "agent_id = \"1\""
annotator_selector {
run_interruption_annotator = false
issue_models = ["projects/%{project_number}/locations/us-central1/issueModels/some_issue_model_id"]
phrase_matchers = ["projects/%{project_number}/locations/us-central1/phraseMatchers/123"]
qa_config {
scorecard_list {
qa_scorecard_revisions = ["projects/%{project_number}/locations/us-central1/qaScorecards/*/revisions/some_scorecard_revision_id"]
}
}
run_entity_annotator = false
run_intent_annotator = false
run_issue_model_annotator = false
run_phrase_matcher_annotator = false
run_qa_annotator = false
run_sentiment_annotator = false
run_silence_annotator = true
run_summarization_annotator = false
summarization_config {
summarization_model = "BASELINE_MODEL"
}
}
analysis_percentage = 0.5
active = true
}
`, context)
}

func testAccContactCenterInsightsAnalysisRule_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_contact_center_insights_analysis_rule" "basic_analysis_rule" {
display_name = "analysis-rule-display-name-%{random_suffix}-updated"
location = "us-central1"
conversation_filter = "agent_id = \"1\""
annotator_selector {
run_interruption_annotator = true
issue_models = ["projects/%{project_number}/locations/us-central1/issueModels/alt_issue_model_id"]
phrase_matchers = ["projects/%{project_number}/locations/us-central1/phraseMatchers/123"]
qa_config {
scorecard_list {
qa_scorecard_revisions = ["projects/%{project_number}/locations/us-central1/qaScorecards/*/revisions/alt_scorecard_revision_id"]
}
}
run_entity_annotator = true
run_intent_annotator = true
run_issue_model_annotator = false
run_phrase_matcher_annotator = true
run_qa_annotator = true
run_sentiment_annotator = true
run_silence_annotator = true
run_summarization_annotator = true
summarization_config {
summarization_model = "BASELINE_MODEL_V2_0"
}
}
analysis_percentage = 0.0
active = false
}
`, context)
}
Loading