From 930be3f83e24cfcc81de8f91c1bb3d5ecd728c4c Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Thu, 6 Mar 2025 11:49:49 +0100 Subject: [PATCH 01/13] Support unmarshalling JSON-formatted CloudWatch Metric Streams. --- .chloggen/add-json-cw-metric-stream.yaml | 27 ++ .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + .github/ISSUE_TEMPLATE/feature_request.yaml | 1 + .github/ISSUE_TEMPLATE/other.yaml | 1 + .github/ISSUE_TEMPLATE/unmaintained.yaml | 1 + .../extension.go | 42 ++- .../go.mod | 10 +- .../go.sum | 14 +- internal/tidylist/tidylist.txt | 1 + .../cloudwatchmetricstream/Makefile | 1 + .../cloudwatchmetricstream/README.md | 8 + .../cwmetricstream_to_metric.go | 314 ++++++++++++++++++ .../cwmetricstream_to_metric_test.go | 94 ++++++ pkg/translator/cloudwatchmetricstream/go.mod | 35 ++ pkg/translator/cloudwatchmetricstream/go.sum | 105 ++++++ .../cloudwatchmetricstream/metadata.yaml | 7 + .../cloudwatchmetricstream/package_test.go | 14 + .../testdata/json/invalid_record.json | 14 + .../testdata/json/multiple_metrics.json | 67 ++++ .../json/multiple_metrics_expected.json | 107 ++++++ .../testdata/json/valid_record.json | 20 ++ .../testdata/json/valid_record_expected.json | 85 +++++ versions.yaml | 1 + 24 files changed, 944 insertions(+), 27 deletions(-) create mode 100644 .chloggen/add-json-cw-metric-stream.yaml create mode 100644 pkg/translator/cloudwatchmetricstream/Makefile create mode 100644 pkg/translator/cloudwatchmetricstream/README.md create mode 100644 pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go create mode 100644 pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go create mode 100644 pkg/translator/cloudwatchmetricstream/go.mod create mode 100644 pkg/translator/cloudwatchmetricstream/go.sum create mode 100644 pkg/translator/cloudwatchmetricstream/metadata.yaml create mode 100644 pkg/translator/cloudwatchmetricstream/package_test.go create mode 100644 pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json create mode 100644 pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json create mode 100644 pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json create mode 100644 pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json create mode 100644 pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json diff --git a/.chloggen/add-json-cw-metric-stream.yaml b/.chloggen/add-json-cw-metric-stream.yaml new file mode 100644 index 0000000000000..283f58d2b02d8 --- /dev/null +++ b/.chloggen/add-json-cw-metric-stream.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: awscloudwatchmetricstreamsencodingextension + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add unmarshaler for JSON cloudwatch metric stream + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [38407] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user, api] diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6951f1acf09e2..7e8d0edc9e535 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -166,6 +166,7 @@ pkg/stanza/fileconsumer/ @open-telemetry pkg/status/ @open-telemetry/collector-contrib-approvers @jpkrohling @mwear pkg/translator/azure/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @atoulme @cparkins pkg/translator/azurelogs/ @open-telemetry/collector-contrib-approvers @atoulme @cparkins @MikeGoldsmith +pkg/translator/cloudwatchmetricstream/ @open-telemetry/collector-contrib-approvers @axw pkg/translator/jaeger/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @frzifus pkg/translator/loki/ @open-telemetry/collector-contrib-approvers @gouthamve @mar4uk pkg/translator/opencensus/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 898b3ea793f4d..c53a78d98fd4d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -169,6 +169,7 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs + - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 72bf7a7ec2104..cd9aff386c2c2 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -163,6 +163,7 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs + - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/other.yaml b/.github/ISSUE_TEMPLATE/other.yaml index 8610a40480145..4d37e2f708716 100644 --- a/.github/ISSUE_TEMPLATE/other.yaml +++ b/.github/ISSUE_TEMPLATE/other.yaml @@ -163,6 +163,7 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs + - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/unmaintained.yaml b/.github/ISSUE_TEMPLATE/unmaintained.yaml index 6875957807719..3c0fddcb4f7c3 100644 --- a/.github/ISSUE_TEMPLATE/unmaintained.yaml +++ b/.github/ISSUE_TEMPLATE/unmaintained.yaml @@ -168,6 +168,7 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs + - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go index a2cbc09679182..e1a01b3bd712c 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go @@ -5,8 +5,14 @@ package awscloudwatchmetricstreamsencodingextension // import "github.com/open-t import ( "context" + "errors" "fmt" + "go.opentelemetry.io/collector/extension" + + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pmetric" @@ -16,21 +22,28 @@ import ( var _ encoding.MetricsUnmarshalerExtension = (*encodingExtension)(nil) type encodingExtension struct { - pmetric.Unmarshaler + unmarshaller pmetric.Unmarshaler } -func newExtension(cfg *Config) (*encodingExtension, error) { +func newExtension(cfg *Config, settings *extension.Settings) (*encodingExtension, error) { switch cfg.Format { - case formatJSON: - return &encodingExtension{Unmarshaler: formatJSONUnmarshaler{}}, nil - case formatOpenTelemetry10: - return &encodingExtension{Unmarshaler: formatOpenTelemetry10Unmarshaler{}}, nil + case formatJSON, formatOpenTelemetry10: default: // Format will have been validated by Config.Validate, // so we'll only get here if we haven't handled a valid // format. return nil, fmt.Errorf("unimplemented format %q", cfg.Format) } + unmarshaller, err := cloudwatchmetricstream.NewUnmarshaler( + cfg.Format, + metadata.Type.String(), + settings.BuildInfo, + settings.Logger, + ) + if err != nil { + return nil, err + } + return &encodingExtension{unmarshaller: unmarshaller}, nil } func (*encodingExtension) Start(_ context.Context, _ component.Host) error { @@ -41,16 +54,9 @@ func (*encodingExtension) Shutdown(_ context.Context) error { return nil } -type formatJSONUnmarshaler struct{} - -func (formatJSONUnmarshaler) UnmarshalMetrics([]byte) (pmetric.Metrics, error) { - // TODO implement - return pmetric.Metrics{}, fmt.Errorf("UnmarshalMetrics unimplemented for format %q", formatJSON) -} - -type formatOpenTelemetry10Unmarshaler struct{} - -func (formatOpenTelemetry10Unmarshaler) UnmarshalMetrics([]byte) (pmetric.Metrics, error) { - // TODO implement - return pmetric.Metrics{}, fmt.Errorf("UnmarshalMetrics unimplemented for format %q", formatOpenTelemetry10) +func (e *encodingExtension) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { + if e.unmarshaller == nil { + return pmetric.Metrics{}, errors.New("no unmarshaler defined") + } + return e.unmarshaller.UnmarshalMetrics(buf) } diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index 1223a8152b0a0..fb6399f392a43 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -4,6 +4,7 @@ go 1.23.0 require ( github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.121.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/collector/component v1.27.0 go.opentelemetry.io/collector/component/componenttest v0.121.0 @@ -33,6 +34,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.121.0 // indirect + go.opentelemetry.io/collector/semconv v0.121.0 // indirect go.opentelemetry.io/otel v1.34.0 // indirect go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/otel/sdk v1.34.0 // indirect @@ -40,9 +42,9 @@ require ( go.opentelemetry.io/otel/trace v1.34.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/net v0.33.0 // indirect - golang.org/x/sys v0.29.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect google.golang.org/grpc v1.70.0 // indirect google.golang.org/protobuf v1.36.5 // indirect @@ -50,3 +52,5 @@ require ( ) replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../ + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream => ../../../pkg/translator/cloudwatchmetricstream diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index 42e05dafa173d..f115761f627b2 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -70,6 +70,8 @@ go.opentelemetry.io/collector/pdata v1.27.0 h1:66yI7FYkUDia74h48Fd2/KG2Vk8DxZnGw go.opentelemetry.io/collector/pdata v1.27.0/go.mod h1:18e8/xDZsqyj00h/5HM5GLdJgBzzG9Ei8g9SpNoiMtI= go.opentelemetry.io/collector/pdata/pprofile v0.121.0 h1:DFBelDRsZYxEaSoxSRtseAazsHJfqfC/Yl64uPicl2g= go.opentelemetry.io/collector/pdata/pprofile v0.121.0/go.mod h1:j/fjrd7ybJp/PXkba92QLzx7hykUVmU8x/WJvI2JWSg= +go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= +go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= @@ -95,20 +97,20 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/internal/tidylist/tidylist.txt b/internal/tidylist/tidylist.txt index ea605f5eaa08c..a3f32075ea999 100644 --- a/internal/tidylist/tidylist.txt +++ b/internal/tidylist/tidylist.txt @@ -151,6 +151,7 @@ extension/bearertokenauthextension extension/cgroupruntimeextension extension/encoding/avrologencodingextension extension/encoding/awscloudwatchmetricstreamsencodingextension +pkg/translator/cloudwatchmetricstream extension/encoding/googlecloudlogentryencodingextension extension/encoding/jaegerencodingextension extension/encoding/jsonlogencodingextension diff --git a/pkg/translator/cloudwatchmetricstream/Makefile b/pkg/translator/cloudwatchmetricstream/Makefile new file mode 100644 index 0000000000000..bdd863a203be8 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/Makefile @@ -0,0 +1 @@ +include ../../../Makefile.Common diff --git a/pkg/translator/cloudwatchmetricstream/README.md b/pkg/translator/cloudwatchmetricstream/README.md new file mode 100644 index 0000000000000..cc361bc6bf283 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/README.md @@ -0,0 +1,8 @@ +# Cloudwatch metric stream translator + +The translator for [cloudwatch metric stream](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Metric-Streams.html) +extracts the OpenTelemetry metrics from a record containing cloudwatch metric streams. + +The record can contain several metrics, each split by a new line. + +Currently, there is support for records in JSON format. \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go b/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go new file mode 100644 index 0000000000000..25d693a8cba1a --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go @@ -0,0 +1,314 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package cloudwatchmetricstream // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" + +import ( + "bufio" + "bytes" + "errors" + "fmt" + "strings" + "time" + + jsoniter "github.com/json-iterator/go" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/pmetric" + conventions "go.opentelemetry.io/collector/semconv/v1.27.0" + "go.uber.org/zap" +) + +const ( + formatJSON = "json" + formatOpenTelemetry10 = "opentelemetry1.0" + + TypeStr = "cwmetrics" + + attributeAWSCloudWatchMetricStreamName = "aws.cloudwatch.metric_stream_name" + dimensionInstanceID = "InstanceId" + namespaceDelimiter = "/" +) + +var supportedFormats = []string{formatOpenTelemetry10, formatJSON} + +// The cloudwatchMetric is the format for the CloudWatch metric stream records. +// +// More details can be found at: +// https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-metric-streams-formats-json.html +type cloudwatchMetric struct { + // MetricStreamName is the name of the CloudWatch metric stream. + MetricStreamName string `json:"metric_stream_name"` + // AccountID is the AWS account ID associated with the metric. + AccountID string `json:"account_id"` + // Region is the AWS region for the metric. + Region string `json:"region"` + // Namespace is the CloudWatch namespace the metric is in. + Namespace string `json:"namespace"` + // MetricName is the name of the metric. + MetricName string `json:"metric_name"` + // Dimensions is a map of name/value pairs that help to + // differentiate a metric. + Dimensions map[string]string `json:"dimensions"` + // Timestamp is the milliseconds since epoch for + // the metric. + Timestamp int64 `json:"timestamp"` + // Value is the cloudwatchMetricValue, which has the min, max, + // sum, and count. + Value cloudwatchMetricValue `json:"value"` + // Unit is the unit for the metric. + // + // More details can be found at: + // https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html + Unit string `json:"unit"` +} + +// The cloudwatchMetricValue is the actual values of the CloudWatch metric. +type cloudwatchMetricValue struct { + isSet bool + + // Max is the highest value observed. + Max float64 `json:"max"` + // Min is the lowest value observed. + Min float64 `json:"min"` + // Sum is the sum of data points collected. + Sum float64 `json:"sum"` + // Count is the number of data points. + Count float64 `json:"count"` +} + +// CWMetricStreamUnmarshaler is the unmarshaller +// for a cloudwatch metric stream +type CWMetricStreamUnmarshaler struct { + format string + scope string + buildInfo component.BuildInfo + logger *zap.Logger +} + +var _ pmetric.Unmarshaler = (*CWMetricStreamUnmarshaler)(nil) + +// NewUnmarshaler creates a new CWMetricStreamUnmarshaler +func NewUnmarshaler( + format string, + scope string, + buildInfo component.BuildInfo, + logger *zap.Logger, +) (*CWMetricStreamUnmarshaler, error) { + switch format { + case "": + return nil, fmt.Errorf("format unspecified, expected one of %q", supportedFormats) + case formatJSON: + case formatOpenTelemetry10: + // TODO + return nil, fmt.Errorf("format %s still needs to be implemented", formatOpenTelemetry10) + default: + return nil, fmt.Errorf("unsupported format %q, expected one of %q", format, supportedFormats) + } + return &CWMetricStreamUnmarshaler{ + format: format, + scope: scope, + buildInfo: buildInfo, + logger: logger, + }, nil +} + +// UnmarshalMetrics according to the format +func (c *CWMetricStreamUnmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { + switch c.format { + case formatJSON: + return c.unmarshalJSONMetrics(buf) + case formatOpenTelemetry10: + // TODO + return pmetric.Metrics{}, fmt.Errorf("format %s still needs to be implemented", formatOpenTelemetry10) + default: + return pmetric.Metrics{}, fmt.Errorf("unsupported format %q, expected one of %q", c.format, supportedFormats) + } +} + +// resourceKey stores the metric attributes +// that make a cloudwatchMetric unique to +// a resource +type resourceKey struct { + metricStreamName string + namespace string + accountID string + region string +} + +// metricKey stores the metric attributes +// that make a metric unique within +// a resource +type metricKey struct { + name string + unit string +} + +func (c *CWMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric.Metrics, error) { + byResource := make(map[resourceKey]map[metricKey]pmetric.Metric) + + // Multiple metrics in each record separated by newline character + scanner := bufio.NewScanner(bytes.NewReader(record)) + for datumIndex := 0; scanner.Scan(); datumIndex++ { + var cwMetric cloudwatchMetric + if err := jsoniter.ConfigFastest.Unmarshal(scanner.Bytes(), &cwMetric); err != nil { + c.logger.Error( + "Unable to unmarshal input", + zap.Error(err), + zap.Int("datum_index", datumIndex), + ) + continue + } + if isValid, err := c.isMetricValid(cwMetric); !isValid { + c.logger.Error( + "Invalid metric", + zap.Int("datum_index", datumIndex), + zap.Error(err), + ) + continue + } + + c.addMetricToResource(byResource, cwMetric) + } + + if err := scanner.Err(); err != nil { + // Treat this as a non-fatal error, and handle the data below. + c.logger.Error("Error scanning for newline-delimited JSON", zap.Error(err)) + } + + if len(byResource) == 0 { + return pmetric.Metrics{}, errors.New("0 metrics were extracted from the record") + } + + return c.createMetrics(byResource), nil +} + +// isMetricValid validates that the cloudwatch metric has been unmarshalled correctly +func (c *CWMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { + if metric.MetricName == "" { + return false, errors.New("cloudwatch metric is missing metric name field") + } + if metric.Namespace == "" { + return false, errors.New("cloudwatch metric is missing namespace field") + } + if metric.Unit == "" { + return false, errors.New("cloudwatch metric is missing unit field") + } + if !metric.Value.isSet { + return false, errors.New("cloudwatch metric is missing value") + } + return true, nil +} + +// addMetricToResource adds a new cloudwatchMetric to the +// resource it belongs to according to resourceKey. It then +// sets the data point for the cloudwatchMetric. +func (c *CWMetricStreamUnmarshaler) addMetricToResource( + byResource map[resourceKey]map[metricKey]pmetric.Metric, + cwMetric cloudwatchMetric, +) { + rKey := resourceKey{ + metricStreamName: cwMetric.MetricStreamName, + namespace: cwMetric.Namespace, + accountID: cwMetric.AccountID, + region: cwMetric.Region, + } + metrics, ok := byResource[rKey] + if !ok { + metrics = make(map[metricKey]pmetric.Metric) + byResource[rKey] = metrics + } + + mKey := metricKey{ + name: cwMetric.MetricName, + unit: cwMetric.Unit, + } + metric, ok := metrics[mKey] + if !ok { + metric = pmetric.NewMetric() + metric.SetName(mKey.name) + metric.SetUnit(mKey.unit) + metric.SetEmptySummary() + metrics[mKey] = metric + } + + dp := metric.Summary().DataPoints().AppendEmpty() + dp.SetTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(cwMetric.Timestamp))) + setDataPointAttributes(cwMetric, dp) + dp.SetCount(uint64(cwMetric.Value.Count)) + dp.SetSum(cwMetric.Value.Sum) + minQ := dp.QuantileValues().AppendEmpty() + minQ.SetQuantile(0) + minQ.SetValue(cwMetric.Value.Min) + maxQ := dp.QuantileValues().AppendEmpty() + maxQ.SetQuantile(1) + maxQ.SetValue(cwMetric.Value.Max) +} + +// createMetrics creates pmetric.Metrics based on +// on the extracted metrics of each resource +func (c *CWMetricStreamUnmarshaler) createMetrics( + byResource map[resourceKey]map[metricKey]pmetric.Metric, +) pmetric.Metrics { + metrics := pmetric.NewMetrics() + for rKey, metricsMap := range byResource { + rm := metrics.ResourceMetrics().AppendEmpty() + setResourceAttributes(rKey, rm.Resource()) + scopeMetrics := rm.ScopeMetrics().AppendEmpty() + scopeMetrics.Scope().SetName(c.scope) + scopeMetrics.Scope().SetVersion(c.buildInfo.Version) + for _, metric := range metricsMap { + metric.MoveTo(scopeMetrics.Metrics().AppendEmpty()) + } + } + return metrics +} + +// setResourceAttributes sets attributes on a pcommon.Resource from a cloudwatchMetric. +func setResourceAttributes(rKey resourceKey, resource pcommon.Resource) { + attributes := resource.Attributes() + attributes.PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAWS) + attributes.PutStr(conventions.AttributeCloudAccountID, rKey.accountID) + attributes.PutStr(conventions.AttributeCloudRegion, rKey.region) + serviceNamespace, serviceName := toServiceAttributes(rKey.namespace) + if serviceNamespace != "" { + attributes.PutStr(conventions.AttributeServiceNamespace, serviceNamespace) + } + attributes.PutStr(conventions.AttributeServiceName, serviceName) + attributes.PutStr(attributeAWSCloudWatchMetricStreamName, rKey.metricStreamName) +} + +// toServiceAttributes splits the CloudWatch namespace into service namespace/name +// if prepended by AWS/. Otherwise, it returns the CloudWatch namespace as the +// service name with an empty service namespace +func toServiceAttributes(namespace string) (serviceNamespace, serviceName string) { + index := strings.Index(namespace, namespaceDelimiter) + if index != -1 && strings.EqualFold(namespace[:index], conventions.AttributeCloudProviderAWS) { + return namespace[:index], namespace[index+1:] + } + return "", namespace +} + +// setDataPointAttributes sets attributes on a metric data point from a cloudwatchMetric. +func setDataPointAttributes(metric cloudwatchMetric, dp pmetric.SummaryDataPoint) { + attrs := dp.Attributes() + for k, v := range metric.Dimensions { + switch k { + case dimensionInstanceID: + attrs.PutStr(conventions.AttributeServiceInstanceID, v) + default: + attrs.PutStr(k, v) + } + } +} + +// UnmarshalJSON unmarshalls the data to a cloudwatchMetricValue, +// and sets isSet to true upon a successful execution +func (v *cloudwatchMetricValue) UnmarshalJSON(data []byte) error { + type valueType cloudwatchMetricValue + if err := jsoniter.ConfigFastest.Unmarshal(data, (*valueType)(v)); err != nil { + return err + } + v.isSet = true + return nil +} diff --git a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go b/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go new file mode 100644 index 0000000000000..0191835c0b9e1 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go @@ -0,0 +1,94 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package cloudwatchmetricstream + +import ( + "bytes" + "errors" + "os" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/pmetric" + "go.uber.org/zap" +) + +func TestUnmarshalJSONMetrics(t *testing.T) { + t.Parallel() + + filesDirectory := "testdata/json" + tests := map[string]struct { + metricFilename string + metricExpectedFilename string + expectedErr error + }{ + "ValidRecordSingleMetric": { + // test a record with a single metric + metricFilename: "valid_record.json", + metricExpectedFilename: "valid_record_expected.json", + }, + "InvalidRecord": { + // test a record with one invalid metric + metricFilename: "invalid_record.json", + expectedErr: errors.New("0 metrics were extracted from the record"), + }, + "ValidRecordSomeInvalidMetrics": { + // test a record with multiple + // metrics: some invalid, some + // valid + metricFilename: "multiple_metrics.json", + metricExpectedFilename: "multiple_metrics_expected.json", + }, + } + + unmarshalerCW, err := NewUnmarshaler(formatJSON, "test", component.BuildInfo{}, zap.NewNop()) + require.NoError(t, err) + + unmarshallerJSONMetric := pmetric.JSONUnmarshaler{} + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + data, err := os.ReadFile(filesDirectory + "/" + test.metricFilename) + require.NoError(t, err) + + // a new line represents a new record, so we parse the file + // content to remove all new lines within each record, and + // leave only the ones that separate each of them + // Example input: + // [ + // { + // "name": "a" + // }, + // { + // "name": "b" + // } + // ] + // Example output: + // {name: "a"} + // {name: "b"} + record := bytes.ReplaceAll(data, []byte("]"), []byte("")) + record = bytes.ReplaceAll(record, []byte("["), []byte("")) + record = bytes.ReplaceAll(record, []byte("\n },"), []byte("}#\n")) + record = bytes.ReplaceAll(record, []byte("\n"), []byte("")) + record = bytes.ReplaceAll(record, []byte("#"), []byte("\n")) + + metrics, err := unmarshalerCW.unmarshalJSONMetrics(record) + if test.expectedErr != nil { + require.Equal(t, test.expectedErr, err) + return + } + + require.NoError(t, err) + + content, err := os.ReadFile(filesDirectory + "/" + test.metricExpectedFilename) + require.NoError(t, err) + + expected, err := unmarshallerJSONMetric.UnmarshalMetrics(content) + require.NoError(t, err) + + require.Equal(t, expected, metrics) + }) + } +} diff --git a/pkg/translator/cloudwatchmetricstream/go.mod b/pkg/translator/cloudwatchmetricstream/go.mod new file mode 100644 index 0000000000000..c77f8dc9a35dd --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/go.mod @@ -0,0 +1,35 @@ +module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream + +go 1.23.0 + +toolchain go1.23.6 + +require ( + github.com/json-iterator/go v1.1.12 + github.com/stretchr/testify v1.10.0 + go.opentelemetry.io/collector/component v1.27.0 + go.opentelemetry.io/collector/pdata v1.27.0 + go.opentelemetry.io/collector/semconv v0.121.0 + go.uber.org/goleak v1.3.0 + go.uber.org/zap v1.27.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/otel v1.34.0 // indirect + go.opentelemetry.io/otel/metric v1.34.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect + go.opentelemetry.io/otel/trace v1.34.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect + google.golang.org/grpc v1.70.0 // indirect + google.golang.org/protobuf v1.36.5 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/pkg/translator/cloudwatchmetricstream/go.sum b/pkg/translator/cloudwatchmetricstream/go.sum new file mode 100644 index 0000000000000..425df0e3c4ad2 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/go.sum @@ -0,0 +1,105 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/collector/component v1.27.0 h1:6wk0K23YT9lSprX8BH9x5w8ssAORE109ekH/ix2S614= +go.opentelemetry.io/collector/component v1.27.0/go.mod h1:fIyBHoa7vDyZL3Pcidgy45cx24tBe7iHWne097blGgo= +go.opentelemetry.io/collector/pdata v1.27.0 h1:66yI7FYkUDia74h48Fd2/KG2Vk8DxZnGw54wRXykCEU= +go.opentelemetry.io/collector/pdata v1.27.0/go.mod h1:18e8/xDZsqyj00h/5HM5GLdJgBzzG9Ei8g9SpNoiMtI= +go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= +go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= +google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/translator/cloudwatchmetricstream/metadata.yaml b/pkg/translator/cloudwatchmetricstream/metadata.yaml new file mode 100644 index 0000000000000..f5ece7bd03d9d --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/metadata.yaml @@ -0,0 +1,7 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +status: + class: "pkg" + codeowners: + active: [axw] diff --git a/pkg/translator/cloudwatchmetricstream/package_test.go b/pkg/translator/cloudwatchmetricstream/package_test.go new file mode 100644 index 0000000000000..f58805f12c029 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package cloudwatchmetricstream + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json b/pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json new file mode 100644 index 0000000000000..37d867eccefd6 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json @@ -0,0 +1,14 @@ +[ + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"MetricWithNoValue", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "unit":"Seconds" + } +] \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json b/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json new file mode 100644 index 0000000000000..446191b9fac32 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json @@ -0,0 +1,67 @@ +[ + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"DiskWriteOps", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "value":{ + "count":3.0, + "sum":20.0, + "max":18.0, + "min":0.0 + }, + "unit":"Seconds" + }, + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"WithNoValue", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "unit":"Seconds" + }, + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"DiskWriteOps", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1633329698000, + "value":{ + "count":5.0, + "sum":20.0, + "max":18.0, + "min":0.0 + }, + "unit":"Seconds" + }, + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"WithNoUnit", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1633329698000, + "value":{ + "count":5.0, + "sum":20.0, + "max":18.0, + "min":0.0 + } + } +] \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json b/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json new file mode 100644 index 0000000000000..ad14da640d86a --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json @@ -0,0 +1,107 @@ +{ + "resourceMetrics":[ + { + "resource":{ + "attributes":[ + { + "key":"cloud.provider", + "value":{ + "stringValue":"aws" + } + }, + { + "key":"cloud.account.id", + "value":{ + "stringValue":"1234567890" + } + }, + { + "key":"cloud.region", + "value":{ + "stringValue":"us-east-1" + } + }, + { + "key":"service.namespace", + "value":{ + "stringValue":"AWS" + } + }, + { + "key":"service.name", + "value":{ + "stringValue":"EC2" + } + }, + { + "key":"aws.cloudwatch.metric_stream_name", + "value":{ + "stringValue":"MyMetricStream" + } + } + ] + }, + "scopeMetrics":[ + { + "scope":{ + "name":"test" + }, + "metrics":[ + { + "name":"DiskWriteOps", + "unit":"Seconds", + "summary":{ + "dataPoints":[ + { + "attributes":[ + { + "key":"service.instance.id", + "value":{ + "stringValue":"i-123456789012" + } + } + ], + "timeUnixNano":"1611929698000000000", + "count":"3", + "sum":20, + "quantileValues":[ + { + + }, + { + "quantile":1, + "value":18 + } + ] + }, + { + "attributes":[ + { + "key":"service.instance.id", + "value":{ + "stringValue":"i-123456789012" + } + } + ], + "timeUnixNano":"1633329698000000000", + "count":"5", + "sum":20, + "quantileValues":[ + { + + }, + { + "quantile":1, + "value":18 + } + ] + } + ] + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json b/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json new file mode 100644 index 0000000000000..b34ff37ea794b --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json @@ -0,0 +1,20 @@ +[ + { + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"DiskWriteOps", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "value":{ + "count":3.0, + "sum":20.0, + "max":18.0, + "min":0.0 + }, + "unit":"Seconds" + } +] \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json b/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json new file mode 100644 index 0000000000000..9abb7eb0eb662 --- /dev/null +++ b/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json @@ -0,0 +1,85 @@ +{ + "resourceMetrics":[ + { + "resource":{ + "attributes":[ + { + "key":"cloud.provider", + "value":{ + "stringValue":"aws" + } + }, + { + "key":"cloud.account.id", + "value":{ + "stringValue":"1234567890" + } + }, + { + "key":"cloud.region", + "value":{ + "stringValue":"us-east-1" + } + }, + { + "key":"service.namespace", + "value":{ + "stringValue":"AWS" + } + }, + { + "key":"service.name", + "value":{ + "stringValue":"EC2" + } + }, + { + "key":"aws.cloudwatch.metric_stream_name", + "value":{ + "stringValue":"MyMetricStream" + } + } + ] + }, + "scopeMetrics":[ + { + "scope":{ + "name":"test" + }, + "metrics":[ + { + "name":"DiskWriteOps", + "unit":"Seconds", + "summary":{ + "dataPoints":[ + { + "attributes":[ + { + "key":"service.instance.id", + "value":{ + "stringValue":"i-123456789012" + } + } + ], + "timeUnixNano":"1611929698000000000", + "count":"3", + "sum":20, + "quantileValues":[ + { + + }, + { + "quantile":1, + "value":18 + } + ] + } + ] + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/versions.yaml b/versions.yaml index 799ac2de57aec..019a22656473a 100644 --- a/versions.yaml +++ b/versions.yaml @@ -165,6 +165,7 @@ module-sets: - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs + - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus From c64349a596827aa0d865ed0609b7246eafefae45 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Thu, 6 Mar 2025 14:06:03 +0100 Subject: [PATCH 02/13] format, and fix unit tests --- .../extension.go | 10 ++++------ .../extension_test.go | 7 ++++--- .../factory.go | 4 ++-- internal/tidylist/tidylist.txt | 2 +- pkg/translator/cloudwatchmetricstream/metadata.yaml | 3 --- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go index e1a01b3bd712c..c809c073e51de 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go @@ -8,15 +8,13 @@ import ( "errors" "fmt" - "go.opentelemetry.io/collector/extension" - - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" - "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" "go.opentelemetry.io/collector/pdata/pmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding" + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" ) var _ encoding.MetricsUnmarshalerExtension = (*encodingExtension)(nil) @@ -25,7 +23,7 @@ type encodingExtension struct { unmarshaller pmetric.Unmarshaler } -func newExtension(cfg *Config, settings *extension.Settings) (*encodingExtension, error) { +func newExtension(cfg *Config, settings extension.Settings) (*encodingExtension, error) { switch cfg.Format { case formatJSON, formatOpenTelemetry10: default: diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go index b411d8b2b281f..15c102ba4b9ee 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go @@ -8,10 +8,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/extension/extensiontest" ) func TestNew_JSON(t *testing.T) { - e, err := newExtension(&Config{Format: formatJSON}) + e, err := newExtension(&Config{Format: formatJSON}, extensiontest.NewNopSettings(extensiontest.NopType)) require.NoError(t, err) require.NotNil(t, e) @@ -20,7 +21,7 @@ func TestNew_JSON(t *testing.T) { } func TestNew_OpenTelemetry10(t *testing.T) { - e, err := newExtension(&Config{Format: formatOpenTelemetry10}) + e, err := newExtension(&Config{Format: formatOpenTelemetry10}, extensiontest.NewNopSettings(extensiontest.NopType)) require.NoError(t, err) require.NotNil(t, e) @@ -29,7 +30,7 @@ func TestNew_OpenTelemetry10(t *testing.T) { } func TestNew_Unimplemented(t *testing.T) { - e, err := newExtension(&Config{Format: "invalid"}) + e, err := newExtension(&Config{Format: "invalid"}, extensiontest.NewNopSettings(extensiontest.NopType)) require.Error(t, err) require.Nil(t, e) assert.EqualError(t, err, `unimplemented format "invalid"`) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/factory.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/factory.go index b0d723a83a4dd..5164e6f5ec134 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/factory.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/factory.go @@ -21,8 +21,8 @@ func NewFactory() extension.Factory { ) } -func createExtension(_ context.Context, _ extension.Settings, cfg component.Config) (extension.Extension, error) { - return newExtension(cfg.(*Config)) +func createExtension(_ context.Context, settings extension.Settings, cfg component.Config) (extension.Extension, error) { + return newExtension(cfg.(*Config), settings) } func createDefaultConfig() component.Config { diff --git a/internal/tidylist/tidylist.txt b/internal/tidylist/tidylist.txt index a3f32075ea999..f5654ba1f38f8 100644 --- a/internal/tidylist/tidylist.txt +++ b/internal/tidylist/tidylist.txt @@ -150,8 +150,8 @@ extension/basicauthextension extension/bearertokenauthextension extension/cgroupruntimeextension extension/encoding/avrologencodingextension -extension/encoding/awscloudwatchmetricstreamsencodingextension pkg/translator/cloudwatchmetricstream +extension/encoding/awscloudwatchmetricstreamsencodingextension extension/encoding/googlecloudlogentryencodingextension extension/encoding/jaegerencodingextension extension/encoding/jsonlogencodingextension diff --git a/pkg/translator/cloudwatchmetricstream/metadata.yaml b/pkg/translator/cloudwatchmetricstream/metadata.yaml index f5ece7bd03d9d..f9dda74ee7026 100644 --- a/pkg/translator/cloudwatchmetricstream/metadata.yaml +++ b/pkg/translator/cloudwatchmetricstream/metadata.yaml @@ -1,6 +1,3 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - status: class: "pkg" codeowners: From cc4314830c779948967e8d1890b48a8b122d96b2 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Thu, 6 Mar 2025 14:35:47 +0100 Subject: [PATCH 03/13] move translator to encoding extension --- .github/CODEOWNERS | 1 - .github/ISSUE_TEMPLATE/bug_report.yaml | 1 - .github/ISSUE_TEMPLATE/feature_request.yaml | 1 - .github/ISSUE_TEMPLATE/other.yaml | 1 - .github/ISSUE_TEMPLATE/unmaintained.yaml | 1 - .../cwmetricstream_to_metric.go | 46 ++++---- .../cwmetricstream_to_metric_test.go | 4 +- .../extension.go | 3 +- .../extension_test.go | 2 +- .../go.mod | 9 +- .../testdata/json/invalid_record.json | 0 .../testdata/json/multiple_metrics.json | 0 .../json/multiple_metrics_expected.json | 0 .../testdata/json/valid_record.json | 0 .../testdata/json/valid_record_expected.json | 0 internal/tidylist/tidylist.txt | 1 - .../cloudwatchmetricstream/Makefile | 1 - .../cloudwatchmetricstream/README.md | 8 -- pkg/translator/cloudwatchmetricstream/go.mod | 35 ------ pkg/translator/cloudwatchmetricstream/go.sum | 105 ------------------ .../cloudwatchmetricstream/metadata.yaml | 4 - .../cloudwatchmetricstream/package_test.go | 14 --- versions.yaml | 1 - 23 files changed, 27 insertions(+), 211 deletions(-) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/cwmetricstream_to_metric.go (88%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/cwmetricstream_to_metric_test.go (95%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/testdata/json/invalid_record.json (100%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/testdata/json/multiple_metrics.json (100%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/testdata/json/multiple_metrics_expected.json (100%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/testdata/json/valid_record.json (100%) rename {pkg/translator/cloudwatchmetricstream => extension/encoding/awscloudwatchmetricstreamsencodingextension}/testdata/json/valid_record_expected.json (100%) delete mode 100644 pkg/translator/cloudwatchmetricstream/Makefile delete mode 100644 pkg/translator/cloudwatchmetricstream/README.md delete mode 100644 pkg/translator/cloudwatchmetricstream/go.mod delete mode 100644 pkg/translator/cloudwatchmetricstream/go.sum delete mode 100644 pkg/translator/cloudwatchmetricstream/metadata.yaml delete mode 100644 pkg/translator/cloudwatchmetricstream/package_test.go diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7e8d0edc9e535..6951f1acf09e2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -166,7 +166,6 @@ pkg/stanza/fileconsumer/ @open-telemetry pkg/status/ @open-telemetry/collector-contrib-approvers @jpkrohling @mwear pkg/translator/azure/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @atoulme @cparkins pkg/translator/azurelogs/ @open-telemetry/collector-contrib-approvers @atoulme @cparkins @MikeGoldsmith -pkg/translator/cloudwatchmetricstream/ @open-telemetry/collector-contrib-approvers @axw pkg/translator/jaeger/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @frzifus pkg/translator/loki/ @open-telemetry/collector-contrib-approvers @gouthamve @mar4uk pkg/translator/opencensus/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index c53a78d98fd4d..898b3ea793f4d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -169,7 +169,6 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index cd9aff386c2c2..72bf7a7ec2104 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -163,7 +163,6 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/other.yaml b/.github/ISSUE_TEMPLATE/other.yaml index 4d37e2f708716..8610a40480145 100644 --- a/.github/ISSUE_TEMPLATE/other.yaml +++ b/.github/ISSUE_TEMPLATE/other.yaml @@ -163,7 +163,6 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/.github/ISSUE_TEMPLATE/unmaintained.yaml b/.github/ISSUE_TEMPLATE/unmaintained.yaml index 3c0fddcb4f7c3..6875957807719 100644 --- a/.github/ISSUE_TEMPLATE/unmaintained.yaml +++ b/.github/ISSUE_TEMPLATE/unmaintained.yaml @@ -168,7 +168,6 @@ body: - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - - pkg/translator/cloudwatchmetricstream - pkg/translator/jaeger - pkg/translator/loki - pkg/translator/opencensus diff --git a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go similarity index 88% rename from pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go index 25d693a8cba1a..bb022691115e5 100644 --- a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package cloudwatchmetricstream // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" +package awscloudwatchmetricstreamsencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" import ( "bufio" @@ -20,18 +20,11 @@ import ( ) const ( - formatJSON = "json" - formatOpenTelemetry10 = "opentelemetry1.0" - - TypeStr = "cwmetrics" - attributeAWSCloudWatchMetricStreamName = "aws.cloudwatch.metric_stream_name" dimensionInstanceID = "InstanceId" namespaceDelimiter = "/" ) -var supportedFormats = []string{formatOpenTelemetry10, formatJSON} - // The cloudwatchMetric is the format for the CloudWatch metric stream records. // // More details can be found at: @@ -77,35 +70,32 @@ type cloudwatchMetricValue struct { Count float64 `json:"count"` } -// CWMetricStreamUnmarshaler is the unmarshaller +// cwMetricStreamUnmarshaler is the unmarshaller // for a cloudwatch metric stream -type CWMetricStreamUnmarshaler struct { +type cwMetricStreamUnmarshaler struct { format string scope string buildInfo component.BuildInfo logger *zap.Logger } -var _ pmetric.Unmarshaler = (*CWMetricStreamUnmarshaler)(nil) +var _ pmetric.Unmarshaler = (*cwMetricStreamUnmarshaler)(nil) -// NewUnmarshaler creates a new CWMetricStreamUnmarshaler -func NewUnmarshaler( +// newUnmarshaler creates a new cwMetricStreamUnmarshaler +func newUnmarshaler( format string, scope string, buildInfo component.BuildInfo, logger *zap.Logger, -) (*CWMetricStreamUnmarshaler, error) { +) (*cwMetricStreamUnmarshaler, error) { switch format { case "": return nil, fmt.Errorf("format unspecified, expected one of %q", supportedFormats) - case formatJSON: - case formatOpenTelemetry10: - // TODO - return nil, fmt.Errorf("format %s still needs to be implemented", formatOpenTelemetry10) + case formatJSON, formatOpenTelemetry10: default: return nil, fmt.Errorf("unsupported format %q, expected one of %q", format, supportedFormats) } - return &CWMetricStreamUnmarshaler{ + return &cwMetricStreamUnmarshaler{ format: format, scope: scope, buildInfo: buildInfo, @@ -114,18 +104,22 @@ func NewUnmarshaler( } // UnmarshalMetrics according to the format -func (c *CWMetricStreamUnmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { +func (c *cwMetricStreamUnmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { switch c.format { case formatJSON: return c.unmarshalJSONMetrics(buf) case formatOpenTelemetry10: - // TODO - return pmetric.Metrics{}, fmt.Errorf("format %s still needs to be implemented", formatOpenTelemetry10) + return c.unmarshalOTLPMetrics(buf) default: return pmetric.Metrics{}, fmt.Errorf("unsupported format %q, expected one of %q", c.format, supportedFormats) } } +func (c *cwMetricStreamUnmarshaler) unmarshalOTLPMetrics(record []byte) (pmetric.Metrics, error) { + // TODO + return pmetric.Metrics{}, errors.New(`UnmarshalMetrics unimplemented for format "opentelemetry1.0"`) +} + // resourceKey stores the metric attributes // that make a cloudwatchMetric unique to // a resource @@ -144,7 +138,7 @@ type metricKey struct { unit string } -func (c *CWMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric.Metrics, error) { +func (c *cwMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric.Metrics, error) { byResource := make(map[resourceKey]map[metricKey]pmetric.Metric) // Multiple metrics in each record separated by newline character @@ -184,7 +178,7 @@ func (c *CWMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric } // isMetricValid validates that the cloudwatch metric has been unmarshalled correctly -func (c *CWMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { +func (c *cwMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { if metric.MetricName == "" { return false, errors.New("cloudwatch metric is missing metric name field") } @@ -203,7 +197,7 @@ func (c *CWMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool // addMetricToResource adds a new cloudwatchMetric to the // resource it belongs to according to resourceKey. It then // sets the data point for the cloudwatchMetric. -func (c *CWMetricStreamUnmarshaler) addMetricToResource( +func (c *cwMetricStreamUnmarshaler) addMetricToResource( byResource map[resourceKey]map[metricKey]pmetric.Metric, cwMetric cloudwatchMetric, ) { @@ -247,7 +241,7 @@ func (c *CWMetricStreamUnmarshaler) addMetricToResource( // createMetrics creates pmetric.Metrics based on // on the extracted metrics of each resource -func (c *CWMetricStreamUnmarshaler) createMetrics( +func (c *cwMetricStreamUnmarshaler) createMetrics( byResource map[resourceKey]map[metricKey]pmetric.Metric, ) pmetric.Metrics { metrics := pmetric.NewMetrics() diff --git a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go similarity index 95% rename from pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go index 0191835c0b9e1..b1a392952aa82 100644 --- a/pkg/translator/cloudwatchmetricstream/cwmetricstream_to_metric_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package cloudwatchmetricstream +package awscloudwatchmetricstreamsencodingextension import ( "bytes" @@ -43,7 +43,7 @@ func TestUnmarshalJSONMetrics(t *testing.T) { }, } - unmarshalerCW, err := NewUnmarshaler(formatJSON, "test", component.BuildInfo{}, zap.NewNop()) + unmarshalerCW, err := newUnmarshaler(formatJSON, "test", component.BuildInfo{}, zap.NewNop()) require.NoError(t, err) unmarshallerJSONMetric := pmetric.JSONUnmarshaler{} diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go index c809c073e51de..87418d93238d6 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go @@ -14,7 +14,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream" ) var _ encoding.MetricsUnmarshalerExtension = (*encodingExtension)(nil) @@ -32,7 +31,7 @@ func newExtension(cfg *Config, settings extension.Settings) (*encodingExtension, // format. return nil, fmt.Errorf("unimplemented format %q", cfg.Format) } - unmarshaller, err := cloudwatchmetricstream.NewUnmarshaler( + unmarshaller, err := newUnmarshaler( cfg.Format, metadata.Type.String(), settings.BuildInfo, diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go index 15c102ba4b9ee..89fb016cc1b47 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go @@ -17,7 +17,7 @@ func TestNew_JSON(t *testing.T) { require.NotNil(t, e) _, err = e.UnmarshalMetrics([]byte{}) - assert.EqualError(t, err, `UnmarshalMetrics unimplemented for format "json"`) + assert.EqualError(t, err, `0 metrics were extracted from the record`) } func TestNew_OpenTelemetry10(t *testing.T) { diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index fb6399f392a43..4ce100ba9f63d 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -3,8 +3,8 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/extension/encod go 1.23.0 require ( + github.com/json-iterator/go v1.1.12 github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.121.0 - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/collector/component v1.27.0 go.opentelemetry.io/collector/component/componenttest v0.121.0 @@ -13,7 +13,9 @@ require ( go.opentelemetry.io/collector/extension v1.27.0 go.opentelemetry.io/collector/extension/extensiontest v0.121.0 go.opentelemetry.io/collector/pdata v1.27.0 + go.opentelemetry.io/collector/semconv v0.121.0 go.uber.org/goleak v1.3.0 + go.uber.org/zap v1.27.0 ) require ( @@ -23,7 +25,6 @@ require ( github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect github.com/knadh/koanf/providers/confmap v0.1.0 // indirect github.com/knadh/koanf/v2 v2.1.2 // indirect @@ -34,14 +35,12 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.121.0 // indirect - go.opentelemetry.io/collector/semconv v0.121.0 // indirect go.opentelemetry.io/otel v1.34.0 // indirect go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/otel/sdk v1.34.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect go.opentelemetry.io/otel/trace v1.34.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 // indirect golang.org/x/net v0.35.0 // indirect golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.22.0 // indirect @@ -52,5 +51,3 @@ require ( ) replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../ - -replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream => ../../../pkg/translator/cloudwatchmetricstream diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json similarity index 100% rename from pkg/translator/cloudwatchmetricstream/testdata/json/invalid_record.json rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json similarity index 100% rename from pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics.json rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json similarity index 100% rename from pkg/translator/cloudwatchmetricstream/testdata/json/multiple_metrics_expected.json rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json similarity index 100% rename from pkg/translator/cloudwatchmetricstream/testdata/json/valid_record.json rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json diff --git a/pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json similarity index 100% rename from pkg/translator/cloudwatchmetricstream/testdata/json/valid_record_expected.json rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json diff --git a/internal/tidylist/tidylist.txt b/internal/tidylist/tidylist.txt index f5654ba1f38f8..ea605f5eaa08c 100644 --- a/internal/tidylist/tidylist.txt +++ b/internal/tidylist/tidylist.txt @@ -150,7 +150,6 @@ extension/basicauthextension extension/bearertokenauthextension extension/cgroupruntimeextension extension/encoding/avrologencodingextension -pkg/translator/cloudwatchmetricstream extension/encoding/awscloudwatchmetricstreamsencodingextension extension/encoding/googlecloudlogentryencodingextension extension/encoding/jaegerencodingextension diff --git a/pkg/translator/cloudwatchmetricstream/Makefile b/pkg/translator/cloudwatchmetricstream/Makefile deleted file mode 100644 index bdd863a203be8..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../../../Makefile.Common diff --git a/pkg/translator/cloudwatchmetricstream/README.md b/pkg/translator/cloudwatchmetricstream/README.md deleted file mode 100644 index cc361bc6bf283..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Cloudwatch metric stream translator - -The translator for [cloudwatch metric stream](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Metric-Streams.html) -extracts the OpenTelemetry metrics from a record containing cloudwatch metric streams. - -The record can contain several metrics, each split by a new line. - -Currently, there is support for records in JSON format. \ No newline at end of file diff --git a/pkg/translator/cloudwatchmetricstream/go.mod b/pkg/translator/cloudwatchmetricstream/go.mod deleted file mode 100644 index c77f8dc9a35dd..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/go.mod +++ /dev/null @@ -1,35 +0,0 @@ -module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream - -go 1.23.0 - -toolchain go1.23.6 - -require ( - github.com/json-iterator/go v1.1.12 - github.com/stretchr/testify v1.10.0 - go.opentelemetry.io/collector/component v1.27.0 - go.opentelemetry.io/collector/pdata v1.27.0 - go.opentelemetry.io/collector/semconv v0.121.0 - go.uber.org/goleak v1.3.0 - go.uber.org/zap v1.27.0 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gogo/protobuf v1.3.2 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel v1.34.0 // indirect - go.opentelemetry.io/otel/metric v1.34.0 // indirect - go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect - go.opentelemetry.io/otel/trace v1.34.0 // indirect - go.uber.org/multierr v1.11.0 // indirect - golang.org/x/net v0.35.0 // indirect - golang.org/x/sys v0.30.0 // indirect - golang.org/x/text v0.22.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect - google.golang.org/grpc v1.70.0 // indirect - google.golang.org/protobuf v1.36.5 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/pkg/translator/cloudwatchmetricstream/go.sum b/pkg/translator/cloudwatchmetricstream/go.sum deleted file mode 100644 index 425df0e3c4ad2..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/go.sum +++ /dev/null @@ -1,105 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= -go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/collector/component v1.27.0 h1:6wk0K23YT9lSprX8BH9x5w8ssAORE109ekH/ix2S614= -go.opentelemetry.io/collector/component v1.27.0/go.mod h1:fIyBHoa7vDyZL3Pcidgy45cx24tBe7iHWne097blGgo= -go.opentelemetry.io/collector/pdata v1.27.0 h1:66yI7FYkUDia74h48Fd2/KG2Vk8DxZnGw54wRXykCEU= -go.opentelemetry.io/collector/pdata v1.27.0/go.mod h1:18e8/xDZsqyj00h/5HM5GLdJgBzzG9Ei8g9SpNoiMtI= -go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= -go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= -go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= -go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= -go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= -go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= -go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= -go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= -go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= -go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= -go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= -go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= -golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= -google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= -google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= -google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= -google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/translator/cloudwatchmetricstream/metadata.yaml b/pkg/translator/cloudwatchmetricstream/metadata.yaml deleted file mode 100644 index f9dda74ee7026..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/metadata.yaml +++ /dev/null @@ -1,4 +0,0 @@ -status: - class: "pkg" - codeowners: - active: [axw] diff --git a/pkg/translator/cloudwatchmetricstream/package_test.go b/pkg/translator/cloudwatchmetricstream/package_test.go deleted file mode 100644 index f58805f12c029..0000000000000 --- a/pkg/translator/cloudwatchmetricstream/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package cloudwatchmetricstream - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/versions.yaml b/versions.yaml index 019a22656473a..799ac2de57aec 100644 --- a/versions.yaml +++ b/versions.yaml @@ -165,7 +165,6 @@ module-sets: - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs - - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/cloudwatchmetricstream - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus From f4d9791c84eb7d8514daab578e89ecce658ece0d Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Thu, 6 Mar 2025 15:00:17 +0100 Subject: [PATCH 04/13] rename files --- .../extension.go | 29 +++----- ...tream_to_metric.go => json_unmarshaler.go} | 70 ++++--------------- ...etric_test.go => json_unmarshaler_test.go} | 6 +- .../opentelemetry_unmarshaler.go | 18 +++++ .../opentelemetry_unmarshaler_test.go | 10 +++ .../json/multiple_metrics_expected.json | 2 +- .../testdata/json/valid_record_expected.json | 2 +- 7 files changed, 54 insertions(+), 83 deletions(-) rename extension/encoding/awscloudwatchmetricstreamsencodingextension/{cwmetricstream_to_metric.go => json_unmarshaler.go} (82%) rename extension/encoding/awscloudwatchmetricstreamsencodingextension/{cwmetricstream_to_metric_test.go => json_unmarshaler_test.go} (93%) create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler_test.go diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go index 87418d93238d6..1041f3e32937c 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension.go @@ -5,7 +5,6 @@ package awscloudwatchmetricstreamsencodingextension // import "github.com/open-t import ( "context" - "errors" "fmt" "go.opentelemetry.io/collector/component" @@ -13,34 +12,29 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" ) var _ encoding.MetricsUnmarshalerExtension = (*encodingExtension)(nil) type encodingExtension struct { - unmarshaller pmetric.Unmarshaler + pmetric.Unmarshaler } func newExtension(cfg *Config, settings extension.Settings) (*encodingExtension, error) { switch cfg.Format { - case formatJSON, formatOpenTelemetry10: + case formatJSON: + return &encodingExtension{&formatJSONUnmarshaler{ + buildInfo: settings.BuildInfo, + logger: settings.Logger, + }}, nil + case formatOpenTelemetry10: + return &encodingExtension{Unmarshaler: &formatOpenTelemetry10Unmarshaler{}}, nil default: // Format will have been validated by Config.Validate, // so we'll only get here if we haven't handled a valid // format. return nil, fmt.Errorf("unimplemented format %q", cfg.Format) } - unmarshaller, err := newUnmarshaler( - cfg.Format, - metadata.Type.String(), - settings.BuildInfo, - settings.Logger, - ) - if err != nil { - return nil, err - } - return &encodingExtension{unmarshaller: unmarshaller}, nil } func (*encodingExtension) Start(_ context.Context, _ component.Host) error { @@ -50,10 +44,3 @@ func (*encodingExtension) Start(_ context.Context, _ component.Host) error { func (*encodingExtension) Shutdown(_ context.Context) error { return nil } - -func (e *encodingExtension) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { - if e.unmarshaller == nil { - return pmetric.Metrics{}, errors.New("no unmarshaler defined") - } - return e.unmarshaller.UnmarshalMetrics(buf) -} diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go similarity index 82% rename from extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go index bb022691115e5..a7b98cfa50fe4 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go @@ -7,10 +7,11 @@ import ( "bufio" "bytes" "errors" - "fmt" "strings" "time" + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" + jsoniter "github.com/json-iterator/go" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" @@ -25,6 +26,13 @@ const ( namespaceDelimiter = "/" ) +type formatJSONUnmarshaler struct { + buildInfo component.BuildInfo + logger *zap.Logger +} + +var _ pmetric.Unmarshaler = (*formatJSONUnmarshaler)(nil) + // The cloudwatchMetric is the format for the CloudWatch metric stream records. // // More details can be found at: @@ -70,56 +78,6 @@ type cloudwatchMetricValue struct { Count float64 `json:"count"` } -// cwMetricStreamUnmarshaler is the unmarshaller -// for a cloudwatch metric stream -type cwMetricStreamUnmarshaler struct { - format string - scope string - buildInfo component.BuildInfo - logger *zap.Logger -} - -var _ pmetric.Unmarshaler = (*cwMetricStreamUnmarshaler)(nil) - -// newUnmarshaler creates a new cwMetricStreamUnmarshaler -func newUnmarshaler( - format string, - scope string, - buildInfo component.BuildInfo, - logger *zap.Logger, -) (*cwMetricStreamUnmarshaler, error) { - switch format { - case "": - return nil, fmt.Errorf("format unspecified, expected one of %q", supportedFormats) - case formatJSON, formatOpenTelemetry10: - default: - return nil, fmt.Errorf("unsupported format %q, expected one of %q", format, supportedFormats) - } - return &cwMetricStreamUnmarshaler{ - format: format, - scope: scope, - buildInfo: buildInfo, - logger: logger, - }, nil -} - -// UnmarshalMetrics according to the format -func (c *cwMetricStreamUnmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { - switch c.format { - case formatJSON: - return c.unmarshalJSONMetrics(buf) - case formatOpenTelemetry10: - return c.unmarshalOTLPMetrics(buf) - default: - return pmetric.Metrics{}, fmt.Errorf("unsupported format %q, expected one of %q", c.format, supportedFormats) - } -} - -func (c *cwMetricStreamUnmarshaler) unmarshalOTLPMetrics(record []byte) (pmetric.Metrics, error) { - // TODO - return pmetric.Metrics{}, errors.New(`UnmarshalMetrics unimplemented for format "opentelemetry1.0"`) -} - // resourceKey stores the metric attributes // that make a cloudwatchMetric unique to // a resource @@ -138,7 +96,7 @@ type metricKey struct { unit string } -func (c *cwMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric.Metrics, error) { +func (c *formatJSONUnmarshaler) UnmarshalMetrics(record []byte) (pmetric.Metrics, error) { byResource := make(map[resourceKey]map[metricKey]pmetric.Metric) // Multiple metrics in each record separated by newline character @@ -178,7 +136,7 @@ func (c *cwMetricStreamUnmarshaler) unmarshalJSONMetrics(record []byte) (pmetric } // isMetricValid validates that the cloudwatch metric has been unmarshalled correctly -func (c *cwMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { +func (c *formatJSONUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { if metric.MetricName == "" { return false, errors.New("cloudwatch metric is missing metric name field") } @@ -197,7 +155,7 @@ func (c *cwMetricStreamUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool // addMetricToResource adds a new cloudwatchMetric to the // resource it belongs to according to resourceKey. It then // sets the data point for the cloudwatchMetric. -func (c *cwMetricStreamUnmarshaler) addMetricToResource( +func (c *formatJSONUnmarshaler) addMetricToResource( byResource map[resourceKey]map[metricKey]pmetric.Metric, cwMetric cloudwatchMetric, ) { @@ -241,7 +199,7 @@ func (c *cwMetricStreamUnmarshaler) addMetricToResource( // createMetrics creates pmetric.Metrics based on // on the extracted metrics of each resource -func (c *cwMetricStreamUnmarshaler) createMetrics( +func (c *formatJSONUnmarshaler) createMetrics( byResource map[resourceKey]map[metricKey]pmetric.Metric, ) pmetric.Metrics { metrics := pmetric.NewMetrics() @@ -249,7 +207,7 @@ func (c *cwMetricStreamUnmarshaler) createMetrics( rm := metrics.ResourceMetrics().AppendEmpty() setResourceAttributes(rKey, rm.Resource()) scopeMetrics := rm.ScopeMetrics().AppendEmpty() - scopeMetrics.Scope().SetName(c.scope) + scopeMetrics.Scope().SetName(metadata.ScopeName) scopeMetrics.Scope().SetVersion(c.buildInfo.Version) for _, metric := range metricsMap { metric.MoveTo(scopeMetrics.Metrics().AppendEmpty()) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go similarity index 93% rename from extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go rename to extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go index b1a392952aa82..7c4d1c6034905 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/cwmetricstream_to_metric_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go @@ -43,9 +43,7 @@ func TestUnmarshalJSONMetrics(t *testing.T) { }, } - unmarshalerCW, err := newUnmarshaler(formatJSON, "test", component.BuildInfo{}, zap.NewNop()) - require.NoError(t, err) - + unmarshalerCW := &formatJSONUnmarshaler{component.BuildInfo{}, zap.NewNop()} unmarshallerJSONMetric := pmetric.JSONUnmarshaler{} for name, test := range tests { @@ -74,7 +72,7 @@ func TestUnmarshalJSONMetrics(t *testing.T) { record = bytes.ReplaceAll(record, []byte("\n"), []byte("")) record = bytes.ReplaceAll(record, []byte("#"), []byte("\n")) - metrics, err := unmarshalerCW.unmarshalJSONMetrics(record) + metrics, err := unmarshalerCW.UnmarshalMetrics(record) if test.expectedErr != nil { require.Equal(t, test.expectedErr, err) return diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go new file mode 100644 index 0000000000000..54658d14a9364 --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go @@ -0,0 +1,18 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package awscloudwatchmetricstreamsencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" + +import ( + "fmt" + + "go.opentelemetry.io/collector/pdata/pmetric" +) + +type formatOpenTelemetry10Unmarshaler struct{} + +var _ pmetric.Unmarshaler = (*formatOpenTelemetry10Unmarshaler)(nil) + +func (f formatOpenTelemetry10Unmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { + return pmetric.Metrics{}, fmt.Errorf("UnmarshalMetrics unimplemented for format %q", formatOpenTelemetry10) +} diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler_test.go new file mode 100644 index 0000000000000..fcff7eea10e17 --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler_test.go @@ -0,0 +1,10 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package awscloudwatchmetricstreamsencodingextension + +import "testing" + +func TestUnmarshalOpenTelemetryMetrics(t *testing.T) { + t.Skip("still to be implemented") +} diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json index ad14da640d86a..667ca330b5dac 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json @@ -44,7 +44,7 @@ "scopeMetrics":[ { "scope":{ - "name":"test" + "name":"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" }, "metrics":[ { diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json index 9abb7eb0eb662..f4ff31e595902 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json @@ -44,7 +44,7 @@ "scopeMetrics":[ { "scope":{ - "name":"test" + "name":"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" }, "metrics":[ { From e0112171a71221d3a2b8bd45f3c3bebcf86f2335 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Thu, 6 Mar 2025 17:26:16 +0100 Subject: [PATCH 05/13] fix lint errors --- .../json_unmarshaler.go | 4 ++-- .../opentelemetry_unmarshaler.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go index a7b98cfa50fe4..1848886acf431 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go @@ -10,14 +10,14 @@ import ( "strings" "time" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" - jsoniter "github.com/json-iterator/go" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" conventions "go.opentelemetry.io/collector/semconv/v1.27.0" "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension/internal/metadata" ) const ( diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go index 54658d14a9364..dc8f37943ba82 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/opentelemetry_unmarshaler.go @@ -13,6 +13,6 @@ type formatOpenTelemetry10Unmarshaler struct{} var _ pmetric.Unmarshaler = (*formatOpenTelemetry10Unmarshaler)(nil) -func (f formatOpenTelemetry10Unmarshaler) UnmarshalMetrics(buf []byte) (pmetric.Metrics, error) { +func (f formatOpenTelemetry10Unmarshaler) UnmarshalMetrics(_ []byte) (pmetric.Metrics, error) { return pmetric.Metrics{}, fmt.Errorf("UnmarshalMetrics unimplemented for format %q", formatOpenTelemetry10) } From 66c43a6aaa2a8948a15e458176abe9d990f24d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constan=C3=A7a=20Manteigas?= <113898685+constanca-m@users.noreply.github.com> Date: Fri, 7 Mar 2025 07:56:44 +0100 Subject: [PATCH 06/13] Update .chloggen/add-json-cw-metric-stream.yaml Co-authored-by: Andrew Wilkins --- .chloggen/add-json-cw-metric-stream.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/add-json-cw-metric-stream.yaml b/.chloggen/add-json-cw-metric-stream.yaml index 283f58d2b02d8..1a22ad585132d 100644 --- a/.chloggen/add-json-cw-metric-stream.yaml +++ b/.chloggen/add-json-cw-metric-stream.yaml @@ -24,4 +24,4 @@ subtext: # Include 'user' if the change is relevant to end users. # Include 'api' if there is a change to a library API. # Default: '[user]' -change_logs: [user, api] +change_logs: [user] From 46bad7debd6c1b90e541cf15c1a5a02415994899 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Fri, 7 Mar 2025 08:49:27 +0100 Subject: [PATCH 07/13] fix unit test --- .../go.mod | 4 + .../go.sum | 8 + .../json_unmarshaler.go | 68 ++++---- .../json_unmarshaler_test.go | 163 +++++++++++++----- .../testdata/json/invalid_metric.json | 12 ++ .../testdata/json/invalid_record.json | 14 -- .../testdata/json/multiple_metrics.json | 67 ------- .../json/multiple_metrics_expected.json | 107 ------------ .../testdata/json/valid_metric.json | 18 ++ .../testdata/json/valid_record.json | 20 --- .../testdata/json/valid_record_expected.json | 85 --------- ...alid_record_multiple_metrics_expected.yaml | 51 ++++++ .../valid_record_single_metric_expected.yaml | 40 +++++ 13 files changed, 290 insertions(+), 367 deletions(-) create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_metric.json delete mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json delete mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json delete mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_metric.json delete mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json delete mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_multiple_metrics_expected.yaml create mode 100644 extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_single_metric_expected.yaml diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index 4ce100ba9f63d..0e457098a2384 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -5,6 +5,8 @@ go 1.23.0 require ( github.com/json-iterator/go v1.1.12 github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.121.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/collector/component v1.27.0 go.opentelemetry.io/collector/component/componenttest v0.121.0 @@ -19,6 +21,7 @@ require ( ) require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -32,6 +35,7 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.121.0 // indirect diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index f115761f627b2..60b556f9b234f 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -1,3 +1,5 @@ +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -41,6 +43,12 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0 h1:VvMR0isNCB2lVX3R8VMwuePa+UDUj/4jBzCj8ik7r3M= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0/go.mod h1:MoCMz/TtwE0yYmOL3uJ+VoOxZpt7+obfdLrKNG40deI= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0 h1:efEcUMbyFWBx56TQDz2IMsuI0kQ5g8Im0DjQc9w9HBU= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0/go.mod h1:9ghLP9djsDo5xzmzkADqeJjZb3l92XIRhpAz/ToX2QM= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0 h1:D7mQQKd4rncv3PSsbDGayNENqmVwN1dFvPo3wHFzhI4= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0/go.mod h1:swPiDfFHEiy9x2TwNO3uexCkwppLWfPRVoJdpJvKIQE= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go index 1848886acf431..132ba12a3ec4b 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler.go @@ -26,6 +26,14 @@ const ( namespaceDelimiter = "/" ) +var ( + errNoMetricName = errors.New("cloudwatch metric is missing metric name field") + errNoMetricNamespace = errors.New("cloudwatch metric is missing namespace field") + errNoMetricUnit = errors.New("cloudwatch metric is missing unit field") + errNoMetricValue = errors.New("cloudwatch metric is missing value") + errEmptyRecord = errors.New("0 metrics were extracted from the record") +) + type formatJSONUnmarshaler struct { buildInfo component.BuildInfo logger *zap.Logger @@ -78,6 +86,34 @@ type cloudwatchMetricValue struct { Count float64 `json:"count"` } +// validateMetric validates that the cloudwatch metric has been unmarshalled correctly +func validateMetric(metric cloudwatchMetric) error { + if metric.MetricName == "" { + return errNoMetricName + } + if metric.Namespace == "" { + return errNoMetricNamespace + } + if metric.Unit == "" { + return errNoMetricUnit + } + if !metric.Value.isSet { + return errNoMetricValue + } + return nil +} + +// UnmarshalJSON unmarshalls the data to a cloudwatchMetricValue, +// and sets isSet to true upon a successful execution +func (v *cloudwatchMetricValue) UnmarshalJSON(data []byte) error { + type valueType cloudwatchMetricValue + if err := jsoniter.ConfigFastest.Unmarshal(data, (*valueType)(v)); err != nil { + return err + } + v.isSet = true + return nil +} + // resourceKey stores the metric attributes // that make a cloudwatchMetric unique to // a resource @@ -111,7 +147,7 @@ func (c *formatJSONUnmarshaler) UnmarshalMetrics(record []byte) (pmetric.Metrics ) continue } - if isValid, err := c.isMetricValid(cwMetric); !isValid { + if err := validateMetric(cwMetric); err != nil { c.logger.Error( "Invalid metric", zap.Int("datum_index", datumIndex), @@ -129,29 +165,12 @@ func (c *formatJSONUnmarshaler) UnmarshalMetrics(record []byte) (pmetric.Metrics } if len(byResource) == 0 { - return pmetric.Metrics{}, errors.New("0 metrics were extracted from the record") + return pmetric.Metrics{}, errEmptyRecord } return c.createMetrics(byResource), nil } -// isMetricValid validates that the cloudwatch metric has been unmarshalled correctly -func (c *formatJSONUnmarshaler) isMetricValid(metric cloudwatchMetric) (bool, error) { - if metric.MetricName == "" { - return false, errors.New("cloudwatch metric is missing metric name field") - } - if metric.Namespace == "" { - return false, errors.New("cloudwatch metric is missing namespace field") - } - if metric.Unit == "" { - return false, errors.New("cloudwatch metric is missing unit field") - } - if !metric.Value.isSet { - return false, errors.New("cloudwatch metric is missing value") - } - return true, nil -} - // addMetricToResource adds a new cloudwatchMetric to the // resource it belongs to according to resourceKey. It then // sets the data point for the cloudwatchMetric. @@ -253,14 +272,3 @@ func setDataPointAttributes(metric cloudwatchMetric, dp pmetric.SummaryDataPoint } } } - -// UnmarshalJSON unmarshalls the data to a cloudwatchMetricValue, -// and sets isSet to true upon a successful execution -func (v *cloudwatchMetricValue) UnmarshalJSON(data []byte) error { - type valueType cloudwatchMetricValue - if err := jsoniter.ConfigFastest.Unmarshal(data, (*valueType)(v)); err != nil { - return err - } - v.isSet = true - return nil -} diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go index 7c4d1c6034905..ed15aedb07c8b 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go @@ -5,72 +5,152 @@ package awscloudwatchmetricstreamsencodingextension import ( "bytes" - "errors" + "encoding/json" "os" + "path/filepath" "testing" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" ) +func TestValidateMetric(t *testing.T) { + t.Parallel() + + tests := map[string]struct { + metric cloudwatchMetric + expectedErr error + }{ + "ValidMetric": { + metric: cloudwatchMetric{ + Namespace: "test/namespace", + Unit: "Seconds", + Value: cloudwatchMetricValue{ + isSet: true, + }, + MetricName: "test", + }, + }, + "MissingMetricName": { + metric: cloudwatchMetric{ + Namespace: "test/namespace", + Unit: "Seconds", + Value: cloudwatchMetricValue{ + isSet: true, + }, + }, + expectedErr: errNoMetricName, + }, + "MissingMetricNamespace": { + metric: cloudwatchMetric{ + Unit: "Seconds", + Value: cloudwatchMetricValue{ + isSet: true, + }, + MetricName: "test", + }, + expectedErr: errNoMetricNamespace, + }, + "MissingMetricUnit": { + metric: cloudwatchMetric{ + Namespace: "test/namespace", + Value: cloudwatchMetricValue{ + isSet: true, + }, + MetricName: "test", + }, + expectedErr: errNoMetricUnit, + }, + "MissingMetricValue": { + metric: cloudwatchMetric{ + Namespace: "test/namespace", + Unit: "Seconds", + Value: cloudwatchMetricValue{ + isSet: false, + }, + MetricName: "test", + }, + expectedErr: errNoMetricValue, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + err := validateMetric(test.metric) + require.Equal(t, test.expectedErr, err) + }) + } +} + +// joinMetricsFromFile reads the metrics inside the files, +// and joins them in the format a record expects it to be: +// each metric is expected to be in 1 line, and every new +// line marks a new metric +func joinMetricsFromFile(t *testing.T, dir string, files []string) []byte { + if len(files) == 0 { + t.Fatalf("joinMetricsFromFile requires at least one file") + } + var buffer bytes.Buffer + for _, file := range files { + // get the metric from the files + data, err := os.ReadFile(filepath.Join(dir, file)) + require.NoError(t, err) + + // remove all insignificant spaces, + // including new lines + var compacted bytes.Buffer + err = json.Compact(&compacted, data) + require.NoError(t, err) + + // append the metric and add new line + // to mark the end of this metric + buffer.Write(compacted.Bytes()) + buffer.WriteByte('\n') + } + return buffer.Bytes() +} + func TestUnmarshalJSONMetrics(t *testing.T) { t.Parallel() filesDirectory := "testdata/json" tests := map[string]struct { - metricFilename string + files []string metricExpectedFilename string expectedErr error }{ - "ValidRecordSingleMetric": { + "valid_record_single_metric": { // test a record with a single metric - metricFilename: "valid_record.json", - metricExpectedFilename: "valid_record_expected.json", + files: []string{"valid_metric.json"}, + metricExpectedFilename: "valid_record_single_metric_expected.yaml", }, - "InvalidRecord": { + "invalid_record": { // test a record with one invalid metric - metricFilename: "invalid_record.json", - expectedErr: errors.New("0 metrics were extracted from the record"), + files: []string{"invalid_metric.json"}, + expectedErr: errEmptyRecord, }, - "ValidRecordSomeInvalidMetrics": { + "valid_record_multiple_metrics": { // test a record with multiple // metrics: some invalid, some // valid - metricFilename: "multiple_metrics.json", - metricExpectedFilename: "multiple_metrics_expected.json", + files: []string{ + "valid_metric.json", + "invalid_metric.json", + "valid_metric.json", + "invalid_metric.json", + }, + metricExpectedFilename: "valid_record_multiple_metrics_expected.yaml", }, } unmarshalerCW := &formatJSONUnmarshaler{component.BuildInfo{}, zap.NewNop()} - unmarshallerJSONMetric := pmetric.JSONUnmarshaler{} - for name, test := range tests { t.Run(name, func(t *testing.T) { - data, err := os.ReadFile(filesDirectory + "/" + test.metricFilename) - require.NoError(t, err) - - // a new line represents a new record, so we parse the file - // content to remove all new lines within each record, and - // leave only the ones that separate each of them - // Example input: - // [ - // { - // "name": "a" - // }, - // { - // "name": "b" - // } - // ] - // Example output: - // {name: "a"} - // {name: "b"} - record := bytes.ReplaceAll(data, []byte("]"), []byte("")) - record = bytes.ReplaceAll(record, []byte("["), []byte("")) - record = bytes.ReplaceAll(record, []byte("\n },"), []byte("}#\n")) - record = bytes.ReplaceAll(record, []byte("\n"), []byte("")) - record = bytes.ReplaceAll(record, []byte("#"), []byte("\n")) + record := joinMetricsFromFile(t, filesDirectory, test.files) metrics, err := unmarshalerCW.UnmarshalMetrics(record) if test.expectedErr != nil { @@ -78,15 +158,10 @@ func TestUnmarshalJSONMetrics(t *testing.T) { return } + expectedMetrics, err := golden.ReadMetrics(filepath.Join(filesDirectory, test.metricExpectedFilename)) require.NoError(t, err) - content, err := os.ReadFile(filesDirectory + "/" + test.metricExpectedFilename) - require.NoError(t, err) - - expected, err := unmarshallerJSONMetric.UnmarshalMetrics(content) - require.NoError(t, err) - - require.Equal(t, expected, metrics) + require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, metrics)) }) } } diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_metric.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_metric.json new file mode 100644 index 0000000000000..4ea870b5d2734 --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_metric.json @@ -0,0 +1,12 @@ +{ + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"MetricWithNoValue", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "unit":"Seconds" +} \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json deleted file mode 100644 index 37d867eccefd6..0000000000000 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/invalid_record.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"MetricWithNoValue", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1611929698000, - "unit":"Seconds" - } -] \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json deleted file mode 100644 index 446191b9fac32..0000000000000 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics.json +++ /dev/null @@ -1,67 +0,0 @@ -[ - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"DiskWriteOps", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1611929698000, - "value":{ - "count":3.0, - "sum":20.0, - "max":18.0, - "min":0.0 - }, - "unit":"Seconds" - }, - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"WithNoValue", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1611929698000, - "unit":"Seconds" - }, - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"DiskWriteOps", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1633329698000, - "value":{ - "count":5.0, - "sum":20.0, - "max":18.0, - "min":0.0 - }, - "unit":"Seconds" - }, - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"WithNoUnit", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1633329698000, - "value":{ - "count":5.0, - "sum":20.0, - "max":18.0, - "min":0.0 - } - } -] \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json deleted file mode 100644 index 667ca330b5dac..0000000000000 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/multiple_metrics_expected.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "resourceMetrics":[ - { - "resource":{ - "attributes":[ - { - "key":"cloud.provider", - "value":{ - "stringValue":"aws" - } - }, - { - "key":"cloud.account.id", - "value":{ - "stringValue":"1234567890" - } - }, - { - "key":"cloud.region", - "value":{ - "stringValue":"us-east-1" - } - }, - { - "key":"service.namespace", - "value":{ - "stringValue":"AWS" - } - }, - { - "key":"service.name", - "value":{ - "stringValue":"EC2" - } - }, - { - "key":"aws.cloudwatch.metric_stream_name", - "value":{ - "stringValue":"MyMetricStream" - } - } - ] - }, - "scopeMetrics":[ - { - "scope":{ - "name":"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" - }, - "metrics":[ - { - "name":"DiskWriteOps", - "unit":"Seconds", - "summary":{ - "dataPoints":[ - { - "attributes":[ - { - "key":"service.instance.id", - "value":{ - "stringValue":"i-123456789012" - } - } - ], - "timeUnixNano":"1611929698000000000", - "count":"3", - "sum":20, - "quantileValues":[ - { - - }, - { - "quantile":1, - "value":18 - } - ] - }, - { - "attributes":[ - { - "key":"service.instance.id", - "value":{ - "stringValue":"i-123456789012" - } - } - ], - "timeUnixNano":"1633329698000000000", - "count":"5", - "sum":20, - "quantileValues":[ - { - - }, - { - "quantile":1, - "value":18 - } - ] - } - ] - } - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_metric.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_metric.json new file mode 100644 index 0000000000000..c6df0d38cc349 --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_metric.json @@ -0,0 +1,18 @@ +{ + "metric_stream_name":"MyMetricStream", + "account_id":"1234567890", + "region":"us-east-1", + "namespace":"AWS/EC2", + "metric_name":"DiskWriteOps", + "dimensions":{ + "InstanceId":"i-123456789012" + }, + "timestamp":1611929698000, + "value":{ + "count":3.0, + "sum":20.0, + "max":18.0, + "min":0.0 + }, + "unit":"Seconds" +} \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json deleted file mode 100644 index b34ff37ea794b..0000000000000 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "metric_stream_name":"MyMetricStream", - "account_id":"1234567890", - "region":"us-east-1", - "namespace":"AWS/EC2", - "metric_name":"DiskWriteOps", - "dimensions":{ - "InstanceId":"i-123456789012" - }, - "timestamp":1611929698000, - "value":{ - "count":3.0, - "sum":20.0, - "max":18.0, - "min":0.0 - }, - "unit":"Seconds" - } -] \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json deleted file mode 100644 index f4ff31e595902..0000000000000 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_expected.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "resourceMetrics":[ - { - "resource":{ - "attributes":[ - { - "key":"cloud.provider", - "value":{ - "stringValue":"aws" - } - }, - { - "key":"cloud.account.id", - "value":{ - "stringValue":"1234567890" - } - }, - { - "key":"cloud.region", - "value":{ - "stringValue":"us-east-1" - } - }, - { - "key":"service.namespace", - "value":{ - "stringValue":"AWS" - } - }, - { - "key":"service.name", - "value":{ - "stringValue":"EC2" - } - }, - { - "key":"aws.cloudwatch.metric_stream_name", - "value":{ - "stringValue":"MyMetricStream" - } - } - ] - }, - "scopeMetrics":[ - { - "scope":{ - "name":"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension" - }, - "metrics":[ - { - "name":"DiskWriteOps", - "unit":"Seconds", - "summary":{ - "dataPoints":[ - { - "attributes":[ - { - "key":"service.instance.id", - "value":{ - "stringValue":"i-123456789012" - } - } - ], - "timeUnixNano":"1611929698000000000", - "count":"3", - "sum":20, - "quantileValues":[ - { - - }, - { - "quantile":1, - "value":18 - } - ] - } - ] - } - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_multiple_metrics_expected.yaml b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_multiple_metrics_expected.yaml new file mode 100644 index 0000000000000..ec9aa5914abea --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_multiple_metrics_expected.yaml @@ -0,0 +1,51 @@ +resourceMetrics: + - resource: + attributes: + - key: aws.cloudwatch.metric_stream_name + value: + stringValue: MyMetricStream + - key: cloud.account.id + value: + stringValue: "1234567890" + - key: cloud.provider + value: + stringValue: aws + - key: cloud.region + value: + stringValue: us-east-1 + - key: service.name + value: + stringValue: EC2 + - key: service.namespace + value: + stringValue: AWS + scopeMetrics: + - metrics: + - name: DiskWriteOps + summary: + dataPoints: + - attributes: + - key: service.instance.id + value: + stringValue: i-123456789012 + count: "3" + quantileValues: + - {} + - quantile: 1 + value: 18 + sum: 20 + timeUnixNano: 1611929698000000000 + - attributes: + - key: service.instance.id + value: + stringValue: i-123456789012 + count: "3" + quantileValues: + - {} + - quantile: 1 + value: 18 + sum: 20 + timeUnixNano: 1611929698000000000 + unit: Seconds + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_single_metric_expected.yaml b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_single_metric_expected.yaml new file mode 100644 index 0000000000000..1863d1580f1df --- /dev/null +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/testdata/json/valid_record_single_metric_expected.yaml @@ -0,0 +1,40 @@ +resourceMetrics: + - resource: + attributes: + - key: aws.cloudwatch.metric_stream_name + value: + stringValue: MyMetricStream + - key: cloud.account.id + value: + stringValue: "1234567890" + - key: cloud.provider + value: + stringValue: aws + - key: cloud.region + value: + stringValue: us-east-1 + - key: service.name + value: + stringValue: EC2 + - key: service.namespace + value: + stringValue: AWS + scopeMetrics: + - metrics: + - name: DiskWriteOps + summary: + dataPoints: + - attributes: + - key: service.instance.id + value: + stringValue: i-123456789012 + count: "3" + quantileValues: + - {} + - quantile: 1 + value: 18 + sum: 20 + timeUnixNano: 1611929698000000000 + unit: Seconds + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/awscloudwatchmetricstreamsencodingextension From dca87d08b376a3d5b6b776c1cb4745ad3db6ea2e Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Fri, 7 Mar 2025 08:51:13 +0100 Subject: [PATCH 08/13] use err variable --- .../extension_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go index 89fb016cc1b47..a237d56781f74 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/extension_test.go @@ -17,7 +17,7 @@ func TestNew_JSON(t *testing.T) { require.NotNil(t, e) _, err = e.UnmarshalMetrics([]byte{}) - assert.EqualError(t, err, `0 metrics were extracted from the record`) + assert.EqualError(t, err, errEmptyRecord.Error()) } func TestNew_OpenTelemetry10(t *testing.T) { From adf484f2434afce91221aea4792cfa19488e9442 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Fri, 7 Mar 2025 08:53:45 +0100 Subject: [PATCH 09/13] uniform test names casing --- .../json_unmarshaler_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go index ed15aedb07c8b..b9c99253def08 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/json_unmarshaler_test.go @@ -25,7 +25,7 @@ func TestValidateMetric(t *testing.T) { metric cloudwatchMetric expectedErr error }{ - "ValidMetric": { + "valid_metric": { metric: cloudwatchMetric{ Namespace: "test/namespace", Unit: "Seconds", @@ -35,7 +35,7 @@ func TestValidateMetric(t *testing.T) { MetricName: "test", }, }, - "MissingMetricName": { + "no_metric_name": { metric: cloudwatchMetric{ Namespace: "test/namespace", Unit: "Seconds", @@ -45,7 +45,7 @@ func TestValidateMetric(t *testing.T) { }, expectedErr: errNoMetricName, }, - "MissingMetricNamespace": { + "no_metric_namespace": { metric: cloudwatchMetric{ Unit: "Seconds", Value: cloudwatchMetricValue{ @@ -55,7 +55,7 @@ func TestValidateMetric(t *testing.T) { }, expectedErr: errNoMetricNamespace, }, - "MissingMetricUnit": { + "no_metric_unit": { metric: cloudwatchMetric{ Namespace: "test/namespace", Value: cloudwatchMetricValue{ @@ -65,7 +65,7 @@ func TestValidateMetric(t *testing.T) { }, expectedErr: errNoMetricUnit, }, - "MissingMetricValue": { + "no_metric_value": { metric: cloudwatchMetric{ Namespace: "test/namespace", Unit: "Seconds", From cd6cb293d64d95287e24514a033db0e25569ac6e Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Mon, 10 Mar 2025 12:18:43 +0100 Subject: [PATCH 10/13] fix ci issues --- .../awscloudwatchmetricstreamsencodingextension/go.mod | 3 ++- .../awscloudwatchmetricstreamsencodingextension/go.sum | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index 2ad7a5671b842..7cdf3a32dd1a1 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -15,6 +15,7 @@ require ( go.opentelemetry.io/collector/extension v1.27.1-0.20250307164521-7c787571daa5 go.opentelemetry.io/collector/extension/extensiontest v0.121.1-0.20250307145831-dc9250a6c150 go.opentelemetry.io/collector/pdata v1.27.1-0.20250307164521-7c787571daa5 + go.opentelemetry.io/collector/semconv v0.121.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) @@ -27,6 +28,7 @@ require ( github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/uuid v1.6.0 // indirect + github.com/hashicorp/go-version v1.7.0 // indirect github.com/knadh/koanf/maps v0.1.1 // indirect github.com/knadh/koanf/providers/confmap v0.1.0 // indirect github.com/knadh/koanf/v2 v2.1.2 // indirect @@ -45,7 +47,6 @@ require ( go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect go.opentelemetry.io/otel/trace v1.34.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 // indirect golang.org/x/net v0.34.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/text v0.21.0 // indirect diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index 9d4f33d9f734a..d47697f58cae3 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -82,6 +82,8 @@ go.opentelemetry.io/collector/pdata v1.27.1-0.20250307164521-7c787571daa5 h1:oYW go.opentelemetry.io/collector/pdata v1.27.1-0.20250307164521-7c787571daa5/go.mod h1:nFXOEpZx43ykMZJd87AHWIJKqDP+UMMKydIy59m5SEs= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307145831-dc9250a6c150 h1:/lRlw149AcLEbVKfSB7cvp3ekGG3PEduEGcheOKZczQ= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307145831-dc9250a6c150/go.mod h1:hmtWKCi7aeWs2BreLuB+ajHFSVZgDd3d9jra4ilwrBE= +go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= +go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= @@ -115,12 +117,12 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= From 7ce5d56555e926225c9b26c9a1f8a28b3888484b Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Mon, 10 Mar 2025 12:20:08 +0100 Subject: [PATCH 11/13] fix ci issues --- .../encoding/awscloudwatchmetricstreamsencodingextension/go.mod | 1 + .../encoding/awscloudwatchmetricstreamsencodingextension/go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index 4ec000f920814..da9327b202723 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -15,6 +15,7 @@ require ( go.opentelemetry.io/collector/extension v1.27.1-0.20250307194215-7d3e03e500b0 go.opentelemetry.io/collector/extension/extensiontest v0.121.1-0.20250307194215-7d3e03e500b0 go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0 + go.opentelemetry.io/collector/semconv v0.121.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index a18a30d4dc80a..f13d473ae3905 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -82,6 +82,8 @@ go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0 h1:85g go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0/go.mod h1:nFXOEpZx43ykMZJd87AHWIJKqDP+UMMKydIy59m5SEs= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307194215-7d3e03e500b0 h1:6STf0CH2h922SOWNtWHx0b4M2EWRq4iuEXhXJ/iROYs= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307194215-7d3e03e500b0/go.mod h1:hmtWKCi7aeWs2BreLuB+ajHFSVZgDd3d9jra4ilwrBE= +go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= +go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= From e9c6497b982f0f70137737855753bcfe5453ac2e Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Mon, 10 Mar 2025 12:28:42 +0100 Subject: [PATCH 12/13] make checks --- .../awscloudwatchmetricstreamsencodingextension/go.mod | 6 ++++++ .../awscloudwatchmetricstreamsencodingextension/go.sum | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index da9327b202723..b88c6bbf041af 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -57,3 +57,9 @@ require ( ) replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../ + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../../pkg/pdatautil + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../../pkg/pdatatest + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../../pkg/golden diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index f13d473ae3905..29cf361f4d914 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -45,12 +45,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0 h1:VvMR0isNCB2lVX3R8VMwuePa+UDUj/4jBzCj8ik7r3M= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.121.0/go.mod h1:MoCMz/TtwE0yYmOL3uJ+VoOxZpt7+obfdLrKNG40deI= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0 h1:efEcUMbyFWBx56TQDz2IMsuI0kQ5g8Im0DjQc9w9HBU= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.121.0/go.mod h1:9ghLP9djsDo5xzmzkADqeJjZb3l92XIRhpAz/ToX2QM= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0 h1:D7mQQKd4rncv3PSsbDGayNENqmVwN1dFvPo3wHFzhI4= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.121.0/go.mod h1:swPiDfFHEiy9x2TwNO3uexCkwppLWfPRVoJdpJvKIQE= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= From 837b4a0a5937e7877c1fbcdc03603414161b5e02 Mon Sep 17 00:00:00 2001 From: Constanca Manteigas Date: Mon, 10 Mar 2025 13:02:22 +0100 Subject: [PATCH 13/13] fix check-collector-module-version --- .../awscloudwatchmetricstreamsencodingextension/go.mod | 2 +- .../awscloudwatchmetricstreamsencodingextension/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod index b88c6bbf041af..19d6b6d92c7d7 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.mod @@ -15,7 +15,7 @@ require ( go.opentelemetry.io/collector/extension v1.27.1-0.20250307194215-7d3e03e500b0 go.opentelemetry.io/collector/extension/extensiontest v0.121.1-0.20250307194215-7d3e03e500b0 go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0 - go.opentelemetry.io/collector/semconv v0.121.0 + go.opentelemetry.io/collector/semconv v0.121.1-0.20250307194215-7d3e03e500b0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 ) diff --git a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum index 29cf361f4d914..9b2c0c4625e8d 100644 --- a/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum +++ b/extension/encoding/awscloudwatchmetricstreamsencodingextension/go.sum @@ -76,8 +76,8 @@ go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0 h1:85g go.opentelemetry.io/collector/pdata v1.27.1-0.20250307194215-7d3e03e500b0/go.mod h1:nFXOEpZx43ykMZJd87AHWIJKqDP+UMMKydIy59m5SEs= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307194215-7d3e03e500b0 h1:6STf0CH2h922SOWNtWHx0b4M2EWRq4iuEXhXJ/iROYs= go.opentelemetry.io/collector/pdata/pprofile v0.121.1-0.20250307194215-7d3e03e500b0/go.mod h1:hmtWKCi7aeWs2BreLuB+ajHFSVZgDd3d9jra4ilwrBE= -go.opentelemetry.io/collector/semconv v0.121.0 h1:dtdgh5TsKWGZXIBMsyCMVrY1VgmyWlXHgWx/VH9tL1U= -go.opentelemetry.io/collector/semconv v0.121.0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= +go.opentelemetry.io/collector/semconv v0.121.1-0.20250307194215-7d3e03e500b0 h1:K+a24AicCzO3gq8bxcwiTL4YIp7Nqgf/lXlw79FcOeQ= +go.opentelemetry.io/collector/semconv v0.121.1-0.20250307194215-7d3e03e500b0/go.mod h1:te6VQ4zZJO5Lp8dM2XIhDxDiL45mwX0YAQQWRQ0Qr9U= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=