@@ -8,24 +8,6 @@ import (
88 dyn "github.com/dynatrace-ace/dynatrace-go-api-client/api/v2/environment/dynatrace"
99)
1010
11- // AbstractDynatraceClient This interface is a wrapper for the dynatrace-go-client, this interface only implements functions regarding metrics.
12- // This wrapper also includes the ability to add metadata to your metric which uses the SettingsObjectAPI in the background.
13- type AbstractDynatraceClient interface {
14- NewClient (url * string , token string ) * dyn.APIClient
15-
16- // Metrics: Speak directly to MetricsAPI
17- SendMetric (ctx context.Context , metric MetricMetadata ) (* http.Response , error )
18- GetMetric (ctx context.Context , id string ) (dyn.MetricDescriptor , * http.Response , error )
19- GetAllMetrics (ctx context.Context ) (dyn.MetricDescriptorCollection , * http.Response , error )
20- DeleteMetric (ctx context.Context , id string ) (* http.Response , error )
21-
22- // Metrics Metadata: Speaks to SettingsObjectAPI
23- SendMetricMetadata (ctx context.Context , metric MetricMetadata ) ([]dyn.SettingsObjectResponse , * http.Response , error )
24- GetMetricMetadata (ctx context.Context , id string ) (dyn.ObjectsList , * http.Response , error )
25- DeleteMetricMetadata (ctx context.Context , objectID string ) (* http.Response , error )
26- UpdateMetricMetadata (ctx context.Context ) (dyn.SettingsObjectResponse , * http.Response , error )
27- }
28-
2911// DynatraceClient is a wrapper for the dynatrace-go-client, this interface only implements functions regarding metrics.
3012type DynatraceClient struct {
3113 Client * dyn.APIClient
@@ -77,61 +59,3 @@ func (d *DynatraceClient) SendMetric(ctx context.Context, metric MetricMetadata)
7759
7860 return res , err
7961}
80-
81- // GetAllMetrics returns all available metrics that Dynatrace has to over, this is not limited to anything.
82- func (d * DynatraceClient ) GetAllMetrics (ctx context.Context ) (dyn.MetricDescriptorCollection , * http.Response , error ) {
83- coll , res , err := d .Client .MetricsApi .AllMetrics (ctx ).Execute ()
84- return coll , res , err
85- }
86-
87- // GetMetric get a specific metric
88- // id: id of the metric you want (not the display name)
89- func (d * DynatraceClient ) GetMetric (ctx context.Context , id string ) (dyn.MetricDescriptor , * http.Response , error ) {
90- des , res , err := d .Client .MetricsApi .Metric (ctx , id ).Execute ()
91- return des , res , err
92- }
93-
94- // DeleteMetric deletes a metric
95- // id: id of the metric you want (not the display name)
96- func (d * DynatraceClient ) DeleteMetric (ctx context.Context , id string ) (* http.Response , error ) {
97- res , err := d .Client .MetricsApi .Delete (ctx , id ).Execute ()
98- return res , err
99- }
100-
101- // SendMetricMetadata sends the metadata of the metric
102- // this is a big request, this could cause overhead if send with every single datapoint
103- func (d * DynatraceClient ) SendMetricMetadata (ctx context.Context , metric MetricMetadata ) ([]dyn.SettingsObjectResponse , * http.Response , error ) {
104- settings , err := metric .GenerateSettingsObjects ()
105- if err != nil {
106- return []dyn.SettingsObjectResponse {}, & http.Response {}, err
107- }
108- collPost , resPost , errPost := d .Client .SettingsObjectsApi .PostSettingsObjects (ctx ).SettingsObjectCreate (settings ).Execute ()
109- return collPost , resPost , errPost
110- }
111-
112- // GetMetricMetadata gets the metadata of a specific metric
113- // id: id of the metric you want (not the display name)
114- func (d * DynatraceClient ) GetMetricMetadata (ctx context.Context , id string ) (dyn.ObjectsList , * http.Response , error ) {
115- coll , res , err := d .Client .SettingsObjectsApi .GetSettingsObjects (ctx ).SchemaIds ("builtin:metric.metadata" ).Scopes ("metric-" + id ).Execute ()
116- return coll , res , err
117- }
118-
119- // DeleteMetricMetadata deletes the metadata of a specific metric
120- // objectId: this id can be optained by making a get request (is not the normal id of an metric)
121- func (d * DynatraceClient ) DeleteMetricMetadata (ctx context.Context , objectID string ) (* http.Response , error ) {
122- resDel , errDel := d .Client .SettingsObjectsApi .DeleteSettingsObjectByObjectId (ctx , objectID ).Execute ()
123- return resDel , errDel
124- }
125-
126- // UpdateMetricMetadata updates the metadata of a specific metric
127- // objectId: this id can be optained by making a get request (is not the normal id of an metric)
128- // metric: the updated complete metricMetadata object
129- // updateToken: can again be obtained by making a get request for the metric you want to update
130- func (d * DynatraceClient ) UpdateMetricMetadata (ctx context.Context , objectID string , metric MetricMetadata , updateToken string ) (dyn.SettingsObjectResponse , * http.Response , error ) {
131- settings , err := metric .GenerateUpdateSettings (objectID , metric , updateToken )
132- if err != nil {
133- return dyn.SettingsObjectResponse {}, & http.Response {}, err
134- }
135- colUpd , resUpd , errUpd := d .Client .SettingsObjectsApi .PutSettingsObjectByObjectId (ctx , objectID ).SettingsObjectUpdate (settings ).Execute ()
136- return colUpd , resUpd , errUpd
137- }
0 commit comments