Skip to content

Commit 695d9a7

Browse files
SrividyaKamakshiMaxrovr
authored andcommitted
Added - Support for APM - Scheduled Backend Queries - UI & API
1 parent 6ee98e4 commit 695d9a7

22 files changed

+2822
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "apm_domain_id" {}
10+
11+
variable "attribute_auto_activate_status_data_key_type" {
12+
default = "PRIVATE_DATA_KEY"
13+
}
14+
15+
16+
17+
provider "oci" {
18+
tenancy_ocid = var.tenancy_ocid
19+
user_ocid = var.user_ocid
20+
fingerprint = var.fingerprint
21+
private_key_path = var.private_key_path
22+
region = var.region
23+
}
24+
25+
data "oci_apm_traces_attribute_auto_activate_status" "test_attribute_auto_activate_status" {
26+
#Required
27+
apm_domain_id = var.apm_domain_id
28+
data_key_type = var.attribute_auto_activate_status_data_key_type
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "apm_domain_id" {}
10+
11+
variable "log_log_key" {
12+
default = "logKey"
13+
}
14+
15+
variable "log_time_log_ended_less_than" {
16+
default = "2025-05-23T00:00:00Z"
17+
}
18+
19+
variable "log_time_log_started_greater_than_or_equal_to" {
20+
default = "2025-05-18T00:00:00Z"
21+
}
22+
23+
24+
25+
provider "oci" {
26+
tenancy_ocid = var.tenancy_ocid
27+
user_ocid = var.user_ocid
28+
fingerprint = var.fingerprint
29+
private_key_path = var.private_key_path
30+
region = var.region
31+
}
32+
33+
data "oci_apm_traces_log" "test_log" {
34+
#Required
35+
apm_domain_id = var.apm_domain_id
36+
log_key = var.log_log_key
37+
time_log_ended_less_than = var.log_time_log_ended_less_than
38+
time_log_started_greater_than_or_equal_to = var.log_time_log_started_greater_than_or_equal_to
39+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
variable "apm_domain_id" {}
10+
11+
variable "scheduled_query_defined_tags_value" {
12+
default = "value"
13+
}
14+
15+
variable "scheduled_query_display_name" {
16+
default = "displayName"
17+
}
18+
19+
variable "scheduled_query_freeform_tags" {
20+
default = { "bar-key" = "value" }
21+
}
22+
23+
variable "scheduled_query_opc_dry_run" {
24+
default = "opcDryRun"
25+
}
26+
27+
variable "scheduled_query_scheduled_query_description" {
28+
default = "scheduledQueryDescription"
29+
}
30+
31+
variable "scheduled_query_scheduled_query_maximum_runtime_in_seconds" {
32+
default = 10
33+
}
34+
35+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_compartment" {
36+
default = "compartment"
37+
}
38+
39+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_description" {
40+
default = "description"
41+
}
42+
43+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_is_anomaly_detection_enabled" {
44+
default = false
45+
}
46+
47+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_is_metric_published" {
48+
default = false
49+
}
50+
51+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_name" {
52+
default = "name"
53+
}
54+
55+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_namespace" {
56+
default = "namespace"
57+
}
58+
59+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_resource_group" {
60+
default = "resourceGroup"
61+
}
62+
63+
variable "scheduled_query_scheduled_query_processing_configuration_custom_metric_unit" {
64+
default = "unit"
65+
}
66+
67+
variable "scheduled_query_scheduled_query_processing_configuration_object_storage_bucket" {
68+
default = "bucket"
69+
}
70+
71+
variable "scheduled_query_scheduled_query_processing_configuration_object_storage_name_space" {
72+
default = "nameSpace"
73+
}
74+
75+
variable "scheduled_query_scheduled_query_processing_configuration_object_storage_object_name_prefix" {
76+
default = "objectNamePrefix"
77+
}
78+
79+
variable "scheduled_query_scheduled_query_processing_sub_type" {
80+
default = "OBJECT_STORAGE"
81+
}
82+
83+
variable "scheduled_query_scheduled_query_processing_type" {
84+
default = "EXPORT"
85+
}
86+
87+
variable "scheduled_query_scheduled_query_retention_criteria" {
88+
default = "UPDATE"
89+
}
90+
91+
variable "scheduled_query_scheduled_query_retention_period_in_ms" {
92+
default = 10
93+
}
94+
95+
variable "scheduled_query_scheduled_query_schedule" {
96+
default = "SCHEDULE STARTING AFTER 2025-06-20T21:20:00Z EVERY 60 MINUTES"
97+
}
98+
99+
variable "scheduled_query_scheduled_query_text" {
100+
default = "SHOW SPANS time_bucket_start(1,apmdbInsertTime2) AS metricStartTime,1 MINUTE AS metricDuration,serviceName,operationName,count(*) AS metricValue WHERE apmdbinserttime2>=TimeTruncate(now(),'minute') - 5 MINUTES GROUP BY time_bucket_start(1,apmdbInsertTime2),serviceName,operationName FIRST 10000 ROWS BETWEEN now() - 2 HOURS AND now()"
101+
}
102+
103+
variable "scheduled_query_scheduled_query_name" {
104+
default = "scheduledQueryName"
105+
}
106+
107+
108+
provider "oci" {
109+
tenancy_ocid = var.tenancy_ocid
110+
user_ocid = var.user_ocid
111+
fingerprint = var.fingerprint
112+
private_key_path = var.private_key_path
113+
region = var.region
114+
}
115+
116+
resource "oci_apm_traces_scheduled_query" "test_scheduled_query" {
117+
#Required
118+
apm_domain_id = var.apm_domain_id
119+
120+
#Optional
121+
#defined_tags = map(oci_identity_tag_namespace.tag-namespace1.name.oci_identity_tag.tag1.name, var.scheduled_query_defined_tags_value)
122+
freeform_tags = var.scheduled_query_freeform_tags
123+
opc_dry_run = var.scheduled_query_opc_dry_run
124+
scheduled_query_description = var.scheduled_query_scheduled_query_description
125+
scheduled_query_maximum_runtime_in_seconds = var.scheduled_query_scheduled_query_maximum_runtime_in_seconds
126+
scheduled_query_name = var.scheduled_query_scheduled_query_name
127+
scheduled_query_processing_configuration {
128+
129+
#Optional
130+
custom_metric {
131+
#Required
132+
name = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_name
133+
134+
#Optional
135+
compartment = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_compartment
136+
description = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_description
137+
is_anomaly_detection_enabled = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_is_anomaly_detection_enabled
138+
is_metric_published = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_is_metric_published
139+
namespace = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_namespace
140+
resource_group = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_resource_group
141+
unit = var.scheduled_query_scheduled_query_processing_configuration_custom_metric_unit
142+
}
143+
object_storage {
144+
145+
#Optional
146+
bucket = var.scheduled_query_scheduled_query_processing_configuration_object_storage_bucket
147+
name_space = var.scheduled_query_scheduled_query_processing_configuration_object_storage_name_space
148+
object_name_prefix = var.scheduled_query_scheduled_query_processing_configuration_object_storage_object_name_prefix
149+
}
150+
streaming {
151+
152+
#Optional
153+
#stream_id = oci_streaming_stream.test_stream.id
154+
}
155+
}
156+
scheduled_query_processing_sub_type = var.scheduled_query_scheduled_query_processing_sub_type
157+
scheduled_query_processing_type = var.scheduled_query_scheduled_query_processing_type
158+
scheduled_query_retention_criteria = var.scheduled_query_scheduled_query_retention_criteria
159+
scheduled_query_retention_period_in_ms = var.scheduled_query_scheduled_query_retention_period_in_ms
160+
scheduled_query_schedule = var.scheduled_query_scheduled_query_schedule
161+
scheduled_query_text = var.scheduled_query_scheduled_query_text
162+
}
163+
164+
data "oci_apm_traces_scheduled_queries" "test_scheduled_queries" {
165+
#Required
166+
apm_domain_id = var.apm_domain_id
167+
168+
#Optional
169+
display_name = var.scheduled_query_display_name
170+
}

internal/client/apm_traces_clients.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,32 @@ import (
1010
)
1111

1212
func init() {
13+
RegisterOracleClient("oci_apm_traces.AttributesClient", &OracleClient{InitClientFn: initApmtracesAttributesClient})
1314
RegisterOracleClient("oci_apm_traces.QueryClient", &OracleClient{InitClientFn: initApmtracesQueryClient})
15+
RegisterOracleClient("oci_apm_traces.ScheduledQueryClient", &OracleClient{InitClientFn: initApmtracesScheduledQueryClient})
1416
RegisterOracleClient("oci_apm_traces.TraceClient", &OracleClient{InitClientFn: initApmtracesTraceClient})
1517
}
1618

19+
func initApmtracesAttributesClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
20+
client, err := oci_apm_traces.NewAttributesClientWithConfigurationProvider(configProvider)
21+
if err != nil {
22+
return nil, err
23+
}
24+
err = configureClient(&client.BaseClient)
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
if serviceClientOverrides.HostUrlOverride != "" {
30+
client.Host = serviceClientOverrides.HostUrlOverride
31+
}
32+
return &client, nil
33+
}
34+
35+
func (m *OracleClients) AttributesClient() *oci_apm_traces.AttributesClient {
36+
return m.GetClient("oci_apm_traces.AttributesClient").(*oci_apm_traces.AttributesClient)
37+
}
38+
1739
func initApmtracesQueryClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
1840
client, err := oci_apm_traces.NewQueryClientWithConfigurationProvider(configProvider)
1941
if err != nil {
@@ -34,6 +56,26 @@ func (m *OracleClients) QueryClient() *oci_apm_traces.QueryClient {
3456
return m.GetClient("oci_apm_traces.QueryClient").(*oci_apm_traces.QueryClient)
3557
}
3658

59+
func initApmtracesScheduledQueryClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
60+
client, err := oci_apm_traces.NewScheduledQueryClientWithConfigurationProvider(configProvider)
61+
if err != nil {
62+
return nil, err
63+
}
64+
err = configureClient(&client.BaseClient)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
if serviceClientOverrides.HostUrlOverride != "" {
70+
client.Host = serviceClientOverrides.HostUrlOverride
71+
}
72+
return &client, nil
73+
}
74+
75+
func (m *OracleClients) ScheduledQueryClient() *oci_apm_traces.ScheduledQueryClient {
76+
return m.GetClient("oci_apm_traces.ScheduledQueryClient").(*oci_apm_traces.ScheduledQueryClient)
77+
}
78+
3779
func initApmtracesTraceClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
3880
client, err := oci_apm_traces.NewTraceClientWithConfigurationProvider(configProvider)
3981
if err != nil {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package integrationtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
ApmTracesAttributeAutoActivateStatusSingularDataSourceRepresentation = map[string]interface{}{
20+
"apm_domain_id": acctest.Representation{RepType: acctest.Required, Create: `${var.apm_domain_id}`},
21+
"data_key_type": acctest.Representation{RepType: acctest.Required, Create: `PRIVATE_DATA_KEY`},
22+
}
23+
24+
//ApmTracesAttributeAutoActivateStatusResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_apm_apm_domain", "test_apm_domain", acctest.Required, acctest.Create, apmDomainRepresentation)
25+
)
26+
27+
// issue-routing-tag: apm_traces/default
28+
func TestApmTracesAttributeAutoActivateStatusResource_basic(t *testing.T) {
29+
httpreplay.SetScenario("TestApmTracesAttributeAutoActivateStatusResource_basic")
30+
defer httpreplay.SaveScenario()
31+
32+
config := acctest.ProviderTestConfig()
33+
34+
//This is a manual test. It requires apm_domain_id and trace_key as environment variables.
35+
apmDomainId := utils.GetEnvSettingWithBlankDefault("apm_domain_id")
36+
37+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
38+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
39+
40+
if apmDomainId == "" {
41+
t.Skip("Set apm_domain_id and data_key_type to run this test")
42+
}
43+
44+
apmDomainIdVariableStr := fmt.Sprintf("variable \"apm_domain_id\" { default = \"%s\" }\n", apmDomainId)
45+
46+
singularDatasourceName := "data.oci_apm_traces_attribute_auto_activate_status.test_attribute_auto_activate_status"
47+
48+
acctest.SaveConfigContent("", "", "", t)
49+
50+
acctest.ResourceTest(t, nil, []resource.TestStep{
51+
// verify singular datasource
52+
{
53+
Config: config + apmDomainIdVariableStr + compartmentIdVariableStr +
54+
acctest.GenerateDataSourceFromRepresentationMap("oci_apm_traces_attribute_auto_activate_status", "test_attribute_auto_activate_status", acctest.Required, acctest.Create, ApmTracesAttributeAutoActivateStatusSingularDataSourceRepresentation),
55+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
56+
resource.TestCheckResourceAttrSet(singularDatasourceName, "apm_domain_id"),
57+
resource.TestCheckResourceAttr(singularDatasourceName, "data_key_type", "PRIVATE_DATA_KEY"),
58+
59+
resource.TestCheckResourceAttrSet(singularDatasourceName, "data_key"),
60+
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
61+
),
62+
},
63+
})
64+
}

0 commit comments

Comments
 (0)