Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.24.0
require (
github.com/dynatrace-ace/dynatrace-go-api-client/api/v2/environment/dynatrace v0.0.0-20210816162345-de2eacc8ac9a
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/golang-lru v0.5.1
github.com/openmcp-project/controller-utils v0.4.2
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
76 changes: 0 additions & 76 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@ import (
dyn "github.com/dynatrace-ace/dynatrace-go-api-client/api/v2/environment/dynatrace"
)

// AbstractDynatraceClient This interface is a wrapper for the dynatrace-go-client, this interface only implements functions regarding metrics.
// This wrapper also includes the ability to add metadata to your metric which uses the SettingsObjectAPI in the background.
type AbstractDynatraceClient interface {
NewClient(url *string, token string) *dyn.APIClient

// Metrics: Speak directly to MetricsAPI
SendMetric(ctx context.Context, metric MetricMetadata) (*http.Response, error)
GetMetric(ctx context.Context, id string) (dyn.MetricDescriptor, *http.Response, error)
GetAllMetrics(ctx context.Context) (dyn.MetricDescriptorCollection, *http.Response, error)
DeleteMetric(ctx context.Context, id string) (*http.Response, error)

// Metrics Metadata: Speaks to SettingsObjectAPI
SendMetricMetadata(ctx context.Context, metric MetricMetadata) ([]dyn.SettingsObjectResponse, *http.Response, error)
GetMetricMetadata(ctx context.Context, id string) (dyn.ObjectsList, *http.Response, error)
DeleteMetricMetadata(ctx context.Context, objectID string) (*http.Response, error)
UpdateMetricMetadata(ctx context.Context) (dyn.SettingsObjectResponse, *http.Response, error)
}

// DynatraceClient is a wrapper for the dynatrace-go-client, this interface only implements functions regarding metrics.
type DynatraceClient struct {
Client *dyn.APIClient
Expand Down Expand Up @@ -77,61 +59,3 @@ func (d *DynatraceClient) SendMetric(ctx context.Context, metric MetricMetadata)

return res, err
}

// GetAllMetrics returns all available metrics that Dynatrace has to over, this is not limited to anything.
func (d *DynatraceClient) GetAllMetrics(ctx context.Context) (dyn.MetricDescriptorCollection, *http.Response, error) {
coll, res, err := d.Client.MetricsApi.AllMetrics(ctx).Execute()
return coll, res, err
}

// GetMetric get a specific metric
// id: id of the metric you want (not the display name)
func (d *DynatraceClient) GetMetric(ctx context.Context, id string) (dyn.MetricDescriptor, *http.Response, error) {
des, res, err := d.Client.MetricsApi.Metric(ctx, id).Execute()
return des, res, err
}

// DeleteMetric deletes a metric
// id: id of the metric you want (not the display name)
func (d *DynatraceClient) DeleteMetric(ctx context.Context, id string) (*http.Response, error) {
res, err := d.Client.MetricsApi.Delete(ctx, id).Execute()
return res, err
}

// SendMetricMetadata sends the metadata of the metric
// this is a big request, this could cause overhead if send with every single datapoint
func (d *DynatraceClient) SendMetricMetadata(ctx context.Context, metric MetricMetadata) ([]dyn.SettingsObjectResponse, *http.Response, error) {
settings, err := metric.GenerateSettingsObjects()
if err != nil {
return []dyn.SettingsObjectResponse{}, &http.Response{}, err
}
collPost, resPost, errPost := d.Client.SettingsObjectsApi.PostSettingsObjects(ctx).SettingsObjectCreate(settings).Execute()
return collPost, resPost, errPost
}

// GetMetricMetadata gets the metadata of a specific metric
// id: id of the metric you want (not the display name)
func (d *DynatraceClient) GetMetricMetadata(ctx context.Context, id string) (dyn.ObjectsList, *http.Response, error) {
coll, res, err := d.Client.SettingsObjectsApi.GetSettingsObjects(ctx).SchemaIds("builtin:metric.metadata").Scopes("metric-" + id).Execute()
return coll, res, err
}

// DeleteMetricMetadata deletes the metadata of a specific metric
// objectId: this id can be optained by making a get request (is not the normal id of an metric)
func (d *DynatraceClient) DeleteMetricMetadata(ctx context.Context, objectID string) (*http.Response, error) {
resDel, errDel := d.Client.SettingsObjectsApi.DeleteSettingsObjectByObjectId(ctx, objectID).Execute()
return resDel, errDel
}

// UpdateMetricMetadata updates the metadata of a specific metric
// objectId: this id can be optained by making a get request (is not the normal id of an metric)
// metric: the updated complete metricMetadata object
// updateToken: can again be obtained by making a get request for the metric you want to update
func (d *DynatraceClient) UpdateMetricMetadata(ctx context.Context, objectID string, metric MetricMetadata, updateToken string) (dyn.SettingsObjectResponse, *http.Response, error) {
settings, err := metric.GenerateUpdateSettings(objectID, metric, updateToken)
if err != nil {
return dyn.SettingsObjectResponse{}, &http.Response{}, err
}
colUpd, resUpd, errUpd := d.Client.SettingsObjectsApi.PutSettingsObjectByObjectId(ctx, objectID).SettingsObjectUpdate(settings).Execute()
return colUpd, resUpd, errUpd
}
Loading