Skip to content

Commit 29cb961

Browse files
sagarp337NagendraNigade
authored andcommitted
Added - Support for apm traces
1 parent a30a142 commit 29cb961

18 files changed

+1773
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2017, 2021, 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+
12+
provider "oci" {
13+
tenancy_ocid = var.tenancy_ocid
14+
user_ocid = var.user_ocid
15+
fingerprint = var.fingerprint
16+
private_key_path = var.private_key_path
17+
region = var.region
18+
}
19+
20+
21+
data "oci_apm_traces_query_quick_picks" "test_query_quick_picks" {
22+
#Required
23+
apm_domain_id = var.apm_domain_id
24+
}
25+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2017, 2021, 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 "trace_trace_key" {
12+
default = "traceKey"
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_trace" "test_trace" {
26+
#Required
27+
apm_domain_id = var.apm_domain_id
28+
trace_key = var.trace_trace_key
29+
}
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2017, 2021, 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 "trace_aggregated_snapshot_data_trace_key" {
12+
default = "traceKey"
13+
}
14+
15+
16+
provider "oci" {
17+
tenancy_ocid = var.tenancy_ocid
18+
user_ocid = var.user_ocid
19+
fingerprint = var.fingerprint
20+
private_key_path = var.private_key_path
21+
region = var.region
22+
}
23+
24+
data "oci_apm_traces_trace_aggregated_snapshot_data" "test_trace_aggregated_snapshot_data" {
25+
#Required
26+
apm_domain_id = var.apm_domain_id
27+
trace_key = var.trace_aggregated_snapshot_data_trace_key
28+
}
29+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2017, 2021, 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 "trace_snapshot_data_is_summarized" {
12+
default = false
13+
}
14+
15+
variable "trace_snapshot_data_snapshot_time" {
16+
default = "snapshotTime"
17+
}
18+
19+
variable "trace_snapshot_data_trace_key" {
20+
default = "traceKey"
21+
}
22+
23+
variable "trace_snapshot_data_thread_id" {
24+
default = "threadId"
25+
}
26+
27+
28+
29+
provider "oci" {
30+
tenancy_ocid = var.tenancy_ocid
31+
user_ocid = var.user_ocid
32+
fingerprint = var.fingerprint
33+
private_key_path = var.private_key_path
34+
region = var.region
35+
}
36+
37+
data "oci_apm_traces_trace_snapshot_data" "test_trace_snapshot_data" {
38+
#Required
39+
apm_domain_id = var.apm_domain_id
40+
trace_key = var.trace_snapshot_data_trace_key
41+
42+
#Optional
43+
is_summarized = var.trace_snapshot_data_is_summarized
44+
snapshot_time = var.trace_snapshot_data_snapshot_time
45+
thread_id = var.trace_snapshot_data_thread_id
46+
}
47+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package client
5+
6+
import (
7+
oci_apm_traces "github.com/oracle/oci-go-sdk/v65/apmtraces"
8+
9+
oci_common "github.com/oracle/oci-go-sdk/v65/common"
10+
)
11+
12+
func init() {
13+
RegisterOracleClient("oci_apm_traces.QueryClient", &OracleClient{InitClientFn: initApmtracesQueryClient})
14+
RegisterOracleClient("oci_apm_traces.TraceClient", &OracleClient{InitClientFn: initApmtracesTraceClient})
15+
}
16+
17+
func initApmtracesQueryClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
18+
client, err := oci_apm_traces.NewQueryClientWithConfigurationProvider(configProvider)
19+
if err != nil {
20+
return nil, err
21+
}
22+
err = configureClient(&client.BaseClient)
23+
if err != nil {
24+
return nil, err
25+
}
26+
27+
if serviceClientOverrides.HostUrlOverride != "" {
28+
client.Host = serviceClientOverrides.HostUrlOverride
29+
}
30+
return &client, nil
31+
}
32+
33+
func (m *OracleClients) QueryClient() *oci_apm_traces.QueryClient {
34+
return m.GetClient("oci_apm_traces.QueryClient").(*oci_apm_traces.QueryClient)
35+
}
36+
37+
func initApmtracesTraceClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
38+
client, err := oci_apm_traces.NewTraceClientWithConfigurationProvider(configProvider)
39+
if err != nil {
40+
return nil, err
41+
}
42+
err = configureClient(&client.BaseClient)
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
if serviceClientOverrides.HostUrlOverride != "" {
48+
client.Host = serviceClientOverrides.HostUrlOverride
49+
}
50+
return &client, nil
51+
}
52+
53+
func (m *OracleClients) TraceClient() *oci_apm_traces.TraceClient {
54+
return m.GetClient("oci_apm_traces.TraceClient").(*oci_apm_traces.TraceClient)
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2017, 2021, 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-sdk/v2/helper/resource"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
"github.com/terraform-providers/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/terraform-providers/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
queryQuickPickDataSourceRepresentation = map[string]interface{}{
20+
"apm_domain_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_apm_apm_domain.test_apm_domain.id}`},
21+
}
22+
23+
QueryQuickPickResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_apm_apm_domain", "test_apm_domain", acctest.Required, acctest.Create, apmDomainRepresentation)
24+
)
25+
26+
// issue-routing-tag: apm_traces/default
27+
func TestApmTracesQueryQuickPickResource_basic(t *testing.T) {
28+
httpreplay.SetScenario("TestApmTracesQueryQuickPickResource_basic")
29+
defer httpreplay.SaveScenario()
30+
31+
config := acctest.ProviderTestConfig()
32+
33+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
34+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
35+
36+
datasourceName := "data.oci_apm_traces_query_quick_picks.test_query_quick_picks"
37+
38+
acctest.SaveConfigContent("", "", "", t)
39+
40+
acctest.ResourceTest(t, nil, []resource.TestStep{
41+
// verify datasource
42+
{
43+
Config: config +
44+
acctest.GenerateDataSourceFromRepresentationMap("oci_apm_traces_query_quick_picks", "test_query_quick_picks", acctest.Required, acctest.Create, queryQuickPickDataSourceRepresentation) +
45+
compartmentIdVariableStr + QueryQuickPickResourceConfig,
46+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
47+
resource.TestCheckResourceAttrSet(datasourceName, "apm_domain_id"),
48+
49+
resource.TestCheckResourceAttrSet(datasourceName, "quick_picks.#"),
50+
resource.TestCheckResourceAttrSet(datasourceName, "quick_picks.0.quick_pick_name"),
51+
resource.TestCheckResourceAttrSet(datasourceName, "quick_picks.0.quick_pick_query"),
52+
),
53+
},
54+
})
55+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2017, 2021, 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-sdk/v2/helper/resource"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
"github.com/terraform-providers/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/terraform-providers/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
traceAggregatedSnapshotDataSingularDataSourceRepresentation = map[string]interface{}{
20+
"apm_domain_id": acctest.Representation{RepType: acctest.Required, Create: `${var.apm_domain_id}`},
21+
"trace_key": acctest.Representation{RepType: acctest.Required, Create: `${var.trace_key}`},
22+
}
23+
24+
//TraceAggregatedSnapshotDataResourceConfig = 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 TestApmTracesTraceAggregatedSnapshotDataResource_basic(t *testing.T) {
29+
httpreplay.SetScenario("TestApmTracesTraceAggregatedSnapshotDataResource_basic")
30+
defer httpreplay.SaveScenario()
31+
32+
config := acctest.ProviderTestConfig()
33+
34+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
35+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
36+
37+
//This is a manual test. It requires apm_domain_id and trace_key as environment variables.
38+
apmDomainId := utils.GetEnvSettingWithBlankDefault("apm_domain_id")
39+
traceKey := utils.GetEnvSettingWithBlankDefault("trace_key")
40+
41+
if apmDomainId == "" || traceKey == "" {
42+
t.Skip("Set apm_domain_id, trace_key to run this test")
43+
}
44+
45+
apmDomainIdVariableStr := fmt.Sprintf("variable \"apm_domain_id\" { default = \"%s\" }\n", apmDomainId)
46+
traceKeyVariableStr := fmt.Sprintf("variable \"trace_key\" { default = \"%s\" }\n", traceKey)
47+
48+
singularDatasourceName := "data.oci_apm_traces_trace_aggregated_snapshot_data.test_trace_aggregated_snapshot_data"
49+
50+
acctest.SaveConfigContent("", "", "", t)
51+
52+
acctest.ResourceTest(t, nil, []resource.TestStep{
53+
// verify singular datasource
54+
{
55+
Config: config + apmDomainIdVariableStr + traceKeyVariableStr +
56+
acctest.GenerateDataSourceFromRepresentationMap("oci_apm_traces_trace_aggregated_snapshot_data", "test_trace_aggregated_snapshot_data", acctest.Required, acctest.Create, traceAggregatedSnapshotDataSingularDataSourceRepresentation) +
57+
compartmentIdVariableStr,
58+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
59+
resource.TestCheckResourceAttrSet(singularDatasourceName, "apm_domain_id"),
60+
resource.TestCheckResourceAttr(singularDatasourceName, "trace_key", traceKey),
61+
62+
resource.TestCheckResourceAttr(singularDatasourceName, "details.#", "2"),
63+
),
64+
},
65+
})
66+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2017, 2021, 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-sdk/v2/helper/resource"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
"github.com/terraform-providers/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/terraform-providers/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
traceSnapshotDataSingularDataSourceRepresentation = map[string]interface{}{
20+
"apm_domain_id": acctest.Representation{RepType: acctest.Required, Create: `${var.apm_domain_id}`},
21+
"trace_key": acctest.Representation{RepType: acctest.Required, Create: `${var.trace_key}`},
22+
"is_summarized": acctest.Representation{RepType: acctest.Optional, Create: `${var.isSummarized}`},
23+
"snapshot_time": acctest.Representation{RepType: acctest.Optional, Create: `${var.snapshotTime}`},
24+
"thread_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.thread.id}`},
25+
}
26+
)
27+
28+
// issue-routing-tag: apm_traces/default
29+
func TestApmTracesTraceSnapshotDataResource_basic(t *testing.T) {
30+
httpreplay.SetScenario("TestApmTracesTraceSnapshotDataResource_basic")
31+
defer httpreplay.SaveScenario()
32+
33+
config := acctest.ProviderTestConfig()
34+
35+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
36+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
37+
38+
//This is a manual test. It requires apm_domain_id and trace_key as environment variables.
39+
// Optional environment variables are thread_id, is_summarized and snapshot_time.
40+
apmDomainId := utils.GetEnvSettingWithBlankDefault("apm_domain_id")
41+
traceKey := utils.GetEnvSettingWithBlankDefault("trace_key")
42+
threadId := utils.GetEnvSettingWithBlankDefault("thread_id")
43+
isSummarized := utils.GetEnvSettingWithBlankDefault("is_summarized")
44+
snapshotTime := utils.GetEnvSettingWithBlankDefault("snapshot_time")
45+
46+
if apmDomainId == "" || traceKey == "" {
47+
t.Skip("Set apm_domain_id and trace_key to run this test")
48+
}
49+
50+
apmDomainIdVariableStr := fmt.Sprintf("variable \"apm_domain_id\" { default = \"%s\" }\n", apmDomainId)
51+
traceKeyVariableStr := fmt.Sprintf("variable \"trace_key\" { default = \"%s\" }\n", traceKey)
52+
threadIdVariableStr := fmt.Sprintf("variable \"thread_id\" { default = \"%s\" }\n", threadId)
53+
isSummarizedStr := fmt.Sprintf("variable \"is_summarized\" { default = \"%s\" }\n", isSummarized)
54+
snapshotTimeStr := fmt.Sprintf("variable \"snapshot_time\" { default = \"%s\" }\n", snapshotTime)
55+
56+
singularDatasourceName := "data.oci_apm_traces_trace_snapshot_data.test_trace_snapshot_data"
57+
58+
acctest.SaveConfigContent("", "", "", t)
59+
60+
acctest.ResourceTest(t, nil, []resource.TestStep{
61+
// verify singular datasource
62+
{
63+
Config: config + apmDomainIdVariableStr + traceKeyVariableStr + compartmentIdVariableStr + threadIdVariableStr + isSummarizedStr + snapshotTimeStr +
64+
acctest.GenerateDataSourceFromRepresentationMap("oci_apm_traces_trace_snapshot_data", "test_trace_snapshot_data", acctest.Required, acctest.Create, traceSnapshotDataSingularDataSourceRepresentation),
65+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
66+
resource.TestCheckResourceAttrSet(singularDatasourceName, "apm_domain_id"),
67+
resource.TestCheckResourceAttr(singularDatasourceName, "trace_key", traceKey),
68+
69+
resource.TestCheckResourceAttrSet(singularDatasourceName, "key"),
70+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_ended"),
71+
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_started"),
72+
resource.TestCheckResourceAttr(singularDatasourceName, "trace_snapshot_details.#", "2"),
73+
),
74+
},
75+
})
76+
}

0 commit comments

Comments
 (0)