From 5fff1040a2844d4d435359b8108202317762593d Mon Sep 17 00:00:00 2001 From: Gabriel Aszalos Date: Mon, 19 Jun 2023 13:13:11 +0300 Subject: [PATCH] {processor,exporter}/datadog: bump opentelemetry-mapping-go (#23445) This change bumps the opentelemetry-mapping-go dependency to v0.5.0 which contains the metric remapping code. As a result, it is removed from the exporter. --- cmd/configschema/go.mod | 8 +- cmd/configschema/go.sum | 18 +- cmd/otelcontribcol/go.mod | 8 +- cmd/otelcontribcol/go.sum | 18 +- exporter/datadogexporter/go.mod | 8 +- exporter/datadogexporter/go.sum | 18 +- .../internal/metrics/system.go | 192 ----- .../internal/metrics/system_deprecated.go | 184 ----- .../metrics/system_deprecated_test.go | 697 ------------------ .../internal/metrics/system_test.go | 653 ---------------- exporter/datadogexporter/metrics_exporter.go | 7 +- .../datadogexporter/metrics_exporter_test.go | 96 ++- go.mod | 8 +- go.sum | 18 +- processor/datadogprocessor/go.mod | 6 +- processor/datadogprocessor/go.sum | 14 +- 16 files changed, 109 insertions(+), 1844 deletions(-) delete mode 100644 exporter/datadogexporter/internal/metrics/system.go delete mode 100644 exporter/datadogexporter/internal/metrics/system_deprecated.go delete mode 100644 exporter/datadogexporter/internal/metrics/system_deprecated_test.go delete mode 100644 exporter/datadogexporter/internal/metrics/system_test.go diff --git a/cmd/configschema/go.mod b/cmd/configschema/go.mod index d493581100e5..eab9167c11e4 100644 --- a/cmd/configschema/go.mod +++ b/cmd/configschema/go.mod @@ -21,8 +21,8 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.8.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 // indirect github.com/gocql/gocql v1.3.1 // indirect github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.79.0 // indirect @@ -259,8 +259,8 @@ require ( github.com/DataDog/datadog-go/v5 v5.1.1 // indirect github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork // indirect github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 // indirect github.com/DataDog/sketches-go v1.4.2 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 // indirect diff --git a/cmd/configschema/go.sum b/cmd/configschema/go.sum index 3a77980b1048..e8546f55e017 100644 --- a/cmd/configschema/go.sum +++ b/cmd/configschema/go.sum @@ -740,15 +740,15 @@ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork h1:yBq5PrAtrM4yVeSzQ+bn050+ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork/go.mod h1:yA5JwkZsHTLuqq3zaRgUQf35DfDkpOZqgtBqHKpwrBs= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc h1:gtlKB6B50/UEuFm1LeMn0R5a+tubx69OecPqxfXJDmU= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc/go.mod h1:oyPC4jWHHjVVNjslDAKp8EqfQBaSmODjHt4HCX+C+9Q= -github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.3.0 h1:4x1lf6HLZdSAhCdOfD7E1178E5ZSw3YbvUhrYNNCCt4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 h1:P3+qEU8Bs3hbKFKhTKBf5OabRQR9RxLl426WR44/ZLY= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0/go.mod h1:ucRvNvmSkJ0QVB6mRwDNvm6TrClnqP2xGE8fqJCA2UA= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 h1:YEgXa2scN5XEzDh/74N7Vu0oq3BzN54FessFky1eS7k= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0/go.mod h1:Du8pI+PeewNbv7AmPHEGY2undFXaR0TM5fblU2/MKU4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 h1:GAxNu0crKwFCgUVDTgxZlnb8FLXIKcPGlpZkEls7z64= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0/go.mod h1:CSnyTkVETMcA9sgY+lbGxSJbIr0ZInGeQY4Ao1sC80A= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 h1:TYJanFBdTOTHScwDk+LBCxUU8CfqTaVhyHC0BSpmoYY= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0/go.mod h1:d1F26FBaHVrDyGxBulO8ixVYbFjtLgvgcadbXwFOpJY= +github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.5.0 h1:bsK3Z6ZnjxgzQffKCQ/zv9y/gmq3f+zezdGlGH3FjyQ= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 h1:a+jLcDKyqjUU1PNncHZREMyXYkenE/IdZQvINaduJT0= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0/go.mod h1:Mixtnwg4RbENPVrodbdyxQSyVVOqBE8+qVW7GQuIKuk= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 h1:Ca1mGZA8DRjpPnJkKsuVdRbg4m3j1KMBAEkmPujqBZg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0/go.mod h1:MtJv7xlFiTL8qQlHV6yXYDUY+pAmnYyXOKaHjRgQbVw= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 h1:HkcDmHBtfNp1U23Ae8GTh/t5RabvFTyP3NIU3iyW+tg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0/go.mod h1:H2553prGE5bRNEQXjo5svUvjL7TXCtuLE5MakF6jDU0= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 h1:gKm5sSMHEeKkNUPgDAAqcCbzKCPXNf4g79C783DzTiY= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0/go.mod h1:0ieak3dqhwyEF+KB1dIMikw0cn9ZHiinmQrSebaivRw= github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjvVA/o= github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= diff --git a/cmd/otelcontribcol/go.mod b/cmd/otelcontribcol/go.mod index ab8df411f30b..83fc4527870b 100644 --- a/cmd/otelcontribcol/go.mod +++ b/cmd/otelcontribcol/go.mod @@ -261,10 +261,10 @@ require ( github.com/DataDog/datadog-go/v5 v5.1.1 // indirect github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork // indirect github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 // indirect github.com/DataDog/sketches-go v1.4.2 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 // indirect diff --git a/cmd/otelcontribcol/go.sum b/cmd/otelcontribcol/go.sum index 6a368fb3c72c..b5635ae4e503 100644 --- a/cmd/otelcontribcol/go.sum +++ b/cmd/otelcontribcol/go.sum @@ -739,15 +739,15 @@ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork h1:yBq5PrAtrM4yVeSzQ+bn050+ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork/go.mod h1:yA5JwkZsHTLuqq3zaRgUQf35DfDkpOZqgtBqHKpwrBs= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc h1:gtlKB6B50/UEuFm1LeMn0R5a+tubx69OecPqxfXJDmU= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc/go.mod h1:oyPC4jWHHjVVNjslDAKp8EqfQBaSmODjHt4HCX+C+9Q= -github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.3.0 h1:4x1lf6HLZdSAhCdOfD7E1178E5ZSw3YbvUhrYNNCCt4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 h1:P3+qEU8Bs3hbKFKhTKBf5OabRQR9RxLl426WR44/ZLY= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0/go.mod h1:ucRvNvmSkJ0QVB6mRwDNvm6TrClnqP2xGE8fqJCA2UA= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 h1:YEgXa2scN5XEzDh/74N7Vu0oq3BzN54FessFky1eS7k= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0/go.mod h1:Du8pI+PeewNbv7AmPHEGY2undFXaR0TM5fblU2/MKU4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 h1:GAxNu0crKwFCgUVDTgxZlnb8FLXIKcPGlpZkEls7z64= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0/go.mod h1:CSnyTkVETMcA9sgY+lbGxSJbIr0ZInGeQY4Ao1sC80A= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 h1:TYJanFBdTOTHScwDk+LBCxUU8CfqTaVhyHC0BSpmoYY= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0/go.mod h1:d1F26FBaHVrDyGxBulO8ixVYbFjtLgvgcadbXwFOpJY= +github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.5.0 h1:bsK3Z6ZnjxgzQffKCQ/zv9y/gmq3f+zezdGlGH3FjyQ= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 h1:a+jLcDKyqjUU1PNncHZREMyXYkenE/IdZQvINaduJT0= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0/go.mod h1:Mixtnwg4RbENPVrodbdyxQSyVVOqBE8+qVW7GQuIKuk= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 h1:Ca1mGZA8DRjpPnJkKsuVdRbg4m3j1KMBAEkmPujqBZg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0/go.mod h1:MtJv7xlFiTL8qQlHV6yXYDUY+pAmnYyXOKaHjRgQbVw= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 h1:HkcDmHBtfNp1U23Ae8GTh/t5RabvFTyP3NIU3iyW+tg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0/go.mod h1:H2553prGE5bRNEQXjo5svUvjL7TXCtuLE5MakF6jDU0= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 h1:gKm5sSMHEeKkNUPgDAAqcCbzKCPXNf4g79C783DzTiY= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0/go.mod h1:0ieak3dqhwyEF+KB1dIMikw0cn9ZHiinmQrSebaivRw= github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjvVA/o= github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= diff --git a/exporter/datadogexporter/go.mod b/exporter/datadogexporter/go.mod index bbd169211322..0990c43df263 100644 --- a/exporter/datadogexporter/go.mod +++ b/exporter/datadogexporter/go.mod @@ -7,10 +7,10 @@ require ( github.com/DataDog/datadog-agent/pkg/trace v0.47.0-devel github.com/DataDog/datadog-api-client-go/v2 v2.13.0 github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 - github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 + github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 github.com/DataDog/sketches-go v1.4.2 github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.15.0 github.com/aws/aws-sdk-go v1.44.282 diff --git a/exporter/datadogexporter/go.sum b/exporter/datadogexporter/go.sum index d9fee7bebaed..8a49273b2dcd 100644 --- a/exporter/datadogexporter/go.sum +++ b/exporter/datadogexporter/go.sum @@ -72,15 +72,15 @@ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork h1:yBq5PrAtrM4yVeSzQ+bn050+ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork/go.mod h1:yA5JwkZsHTLuqq3zaRgUQf35DfDkpOZqgtBqHKpwrBs= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc h1:gtlKB6B50/UEuFm1LeMn0R5a+tubx69OecPqxfXJDmU= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc/go.mod h1:oyPC4jWHHjVVNjslDAKp8EqfQBaSmODjHt4HCX+C+9Q= -github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.3.0 h1:4x1lf6HLZdSAhCdOfD7E1178E5ZSw3YbvUhrYNNCCt4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 h1:P3+qEU8Bs3hbKFKhTKBf5OabRQR9RxLl426WR44/ZLY= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0/go.mod h1:ucRvNvmSkJ0QVB6mRwDNvm6TrClnqP2xGE8fqJCA2UA= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 h1:YEgXa2scN5XEzDh/74N7Vu0oq3BzN54FessFky1eS7k= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0/go.mod h1:Du8pI+PeewNbv7AmPHEGY2undFXaR0TM5fblU2/MKU4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 h1:GAxNu0crKwFCgUVDTgxZlnb8FLXIKcPGlpZkEls7z64= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0/go.mod h1:CSnyTkVETMcA9sgY+lbGxSJbIr0ZInGeQY4Ao1sC80A= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 h1:TYJanFBdTOTHScwDk+LBCxUU8CfqTaVhyHC0BSpmoYY= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0/go.mod h1:d1F26FBaHVrDyGxBulO8ixVYbFjtLgvgcadbXwFOpJY= +github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.5.0 h1:bsK3Z6ZnjxgzQffKCQ/zv9y/gmq3f+zezdGlGH3FjyQ= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 h1:a+jLcDKyqjUU1PNncHZREMyXYkenE/IdZQvINaduJT0= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0/go.mod h1:Mixtnwg4RbENPVrodbdyxQSyVVOqBE8+qVW7GQuIKuk= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 h1:Ca1mGZA8DRjpPnJkKsuVdRbg4m3j1KMBAEkmPujqBZg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0/go.mod h1:MtJv7xlFiTL8qQlHV6yXYDUY+pAmnYyXOKaHjRgQbVw= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 h1:HkcDmHBtfNp1U23Ae8GTh/t5RabvFTyP3NIU3iyW+tg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0/go.mod h1:H2553prGE5bRNEQXjo5svUvjL7TXCtuLE5MakF6jDU0= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 h1:gKm5sSMHEeKkNUPgDAAqcCbzKCPXNf4g79C783DzTiY= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0/go.mod h1:0ieak3dqhwyEF+KB1dIMikw0cn9ZHiinmQrSebaivRw= github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjvVA/o= github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= diff --git a/exporter/datadogexporter/internal/metrics/system.go b/exporter/datadogexporter/internal/metrics/system.go deleted file mode 100644 index f36c0f776898..000000000000 --- a/exporter/datadogexporter/internal/metrics/system.go +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" - -import ( - "strings" - - "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" -) - -const ( - // divMebibytes specifies the number of bytes in a mebibyte. - divMebibytes = 1024 * 1024 - // divPercentage specifies the division necessary for converting fractions to percentages. - divPercentage = 0.01 - // otelNamespacePrefix specifies the namespace used for OpenTelemetry host metrics. - otelNamespacePrefix = "otel." -) - -// copySystemMetric copies the metric from src by giving it a new name. If div differs from 1, it scales all -// data points. -// -// Warning: this is not a deep copy. Only some fields are fully copied, others remain shared. This is intentional. -// Do not alter the returned metric (or the source one) after copying. -func copySystemMetric(src datadogV2.MetricSeries, name string, div float64) datadogV2.MetricSeries { - return copySystemMetricWithUnit(src, name, div, "") -} - -// copySystemMetricWithUnit is equivalent to copySystemMetric, but allows changing the unit. -func copySystemMetricWithUnit(src datadogV2.MetricSeries, name string, div float64, unit string) datadogV2.MetricSeries { - cp := src - cp.Metric = name - // No need to set cp.Interval if cp.Type is gauge. - cp.Type = datadogV2.METRICINTAKETYPE_GAUGE.Ptr() - if div == 0 || div == 1 || len(src.Points) == 0 { - // division by 0 or 1 should not have an impact - return cp - } - if unit != "" { - cp.Unit = &unit - } - cp.Points = make([]datadogV2.MetricPoint, len(src.Points)) - for i, dp := range src.Points { - cp.Points[i].Timestamp = dp.Timestamp - if dp.Value != nil { - newdp := *dp.Value / div - cp.Points[i].Value = &newdp - } - } - return cp -} - -// extractSystemMetrics takes an OpenTelemetry metric m and extracts Datadog system metrics from it, -// if m is a valid system metric. The boolean argument reports whether any system metrics were extractd. -func extractSystemMetrics(m datadogV2.MetricSeries) []datadogV2.MetricSeries { - var series []datadogV2.MetricSeries - switch m.Metric { - case "system.cpu.load_average.1m": - series = append(series, copySystemMetric(m, "system.load.1", 1)) - case "system.cpu.load_average.5m": - series = append(series, copySystemMetric(m, "system.load.5", 1)) - case "system.cpu.load_average.15m": - series = append(series, copySystemMetric(m, "system.load.15", 1)) - case "system.cpu.utilization": - for _, tag := range m.Tags { - switch tag { - case "state:idle": - series = append(series, copySystemMetric(m, "system.cpu.idle", divPercentage)) - case "state:user": - series = append(series, copySystemMetric(m, "system.cpu.user", divPercentage)) - case "state:system": - series = append(series, copySystemMetric(m, "system.cpu.system", divPercentage)) - case "state:wait": - series = append(series, copySystemMetric(m, "system.cpu.iowait", divPercentage)) - case "state:steal": - series = append(series, copySystemMetric(m, "system.cpu.stolen", divPercentage)) - } - } - case "system.memory.usage": - series = append(series, copySystemMetric(m, "system.mem.total", divMebibytes)) - for _, tag := range m.Tags { - switch tag { - case "state:free", "state:cached", "state:buffered": - series = append(series, copySystemMetric(m, "system.mem.usable", divMebibytes)) - } - } - case "system.network.io": - for _, tag := range m.Tags { - switch tag { - case "direction:receive": - series = append(series, copySystemMetric(m, "system.net.bytes_rcvd", 1)) - case "direction:transmit": - series = append(series, copySystemMetric(m, "system.net.bytes_sent", 1)) - } - } - case "system.paging.usage": - for _, tag := range m.Tags { - switch tag { - case "state:free": - series = append(series, copySystemMetric(m, "system.swap.free", divMebibytes)) - case "state:used": - series = append(series, copySystemMetric(m, "system.swap.used", divMebibytes)) - } - } - case "system.filesystem.utilization": - series = append(series, copySystemMetric(m, "system.disk.in_use", 1)) - } - return series -} - -// PrepareSystemMetrics prepends system hosts metrics with the otel.* prefix to identify -// them as part of the Datadog OpenTelemetry Integration. It also extracts Datadog compatible -// system metrics and returns the full set of metrics to be used. -func PrepareSystemMetrics(ms []datadogV2.MetricSeries) []datadogV2.MetricSeries { - series := ms - for i, m := range ms { - if !strings.HasPrefix(m.Metric, "system.") && - !strings.HasPrefix(m.Metric, "process.") { - // not a system metric - continue - } - series = append(series, extractSystemMetrics(m)...) - // all existing system metrics need to be prepended - newname := otelNamespacePrefix + m.Metric - series[i].Metric = newname - } - return series -} - -// PrepareContainerMetrics converts OTEL container.* metrics to Datadog container -// metrics. -func PrepareContainerMetrics(ms []datadogV2.MetricSeries) []datadogV2.MetricSeries { - series := ms - for _, m := range ms { - if !strings.HasPrefix(m.Metric, "container.") { - // not what we're looking for - continue - } - switch m.Metric { - case "container.cpu.usage.total": - series = append(series, copySystemMetricWithUnit(m, "container.cpu.usage", 1, "nanocore")) - case "container.cpu.usage.usermode": - series = append(series, copySystemMetricWithUnit(m, "container.cpu.user", 1, "nanocore")) - case "container.cpu.usage.system": - series = append(series, copySystemMetricWithUnit(m, "container.cpu.system", 1, "nanocore")) - case "container.cpu.throttling_data.throttled_time": - series = append(series, copySystemMetric(m, "container.cpu.throttled", 1)) - case "container.cpu.throttling_data.throttled_periods": - series = append(series, copySystemMetric(m, "container.cpu.throttled.periods", 1)) - case "container.memory.usage.total": - series = append(series, copySystemMetric(m, "container.memory.usage", 1)) - case "container.memory.active_anon": - series = append(series, copySystemMetric(m, "container.memory.kernel", 1)) - case "container.memory.hierarchical_memory_limit": - series = append(series, copySystemMetric(m, "container.memory.limit", 1)) - case "container.memory.usage.limit": - series = append(series, copySystemMetric(m, "container.memory.soft_limit", 1)) - case "container.memory.total_cache": - series = append(series, copySystemMetric(m, "container.memory.cache", 1)) - case "container.memory.total_swap": - series = append(series, copySystemMetric(m, "container.memory.swap", 1)) - case "container.blockio.io_service_bytes_recursive": - for _, tag := range m.Tags { - switch tag { - case "operation:write": - series = append(series, copySystemMetric(m, "container.io.write", 1)) - case "operation:read": - series = append(series, copySystemMetric(m, "container.io.read", 1)) - } - } - case "container.blockio.io_serviced_recursive": - for _, tag := range m.Tags { - switch tag { - case "operation:write": - series = append(series, copySystemMetric(m, "container.io.write.operations", 1)) - case "operation:read": - series = append(series, copySystemMetric(m, "container.io.read.operations", 1)) - } - } - case "container.network.io.usage.tx_bytes": - series = append(series, copySystemMetric(m, "container.net.sent", 1)) - case "container.network.io.usage.tx_packets": - series = append(series, copySystemMetric(m, "container.net.sent.packets", 1)) - case "container.network.io.usage.rx_bytes": - series = append(series, copySystemMetric(m, "container.net.rcvd", 1)) - case "container.network.io.usage.rx_packets": - series = append(series, copySystemMetric(m, "container.net.rcvd.packets", 1)) - } - } - return series -} diff --git a/exporter/datadogexporter/internal/metrics/system_deprecated.go b/exporter/datadogexporter/internal/metrics/system_deprecated.go deleted file mode 100644 index 4bc3bd9dfc51..000000000000 --- a/exporter/datadogexporter/internal/metrics/system_deprecated.go +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" - -import ( - "strings" - - zorkian "gopkg.in/zorkian/go-datadog-api.v2" -) - -// copyZorkianSystemMetric copies the metric from src by giving it a new name. If div differs from 1, it scales all -// data points. -// -// Warning: this is not a deep copy. Only some fields are fully copied, others remain shared. This is intentional. -// Do not alter the returned metric (or the source one) after copying. -func copyZorkianSystemMetric(src zorkian.Metric, name string, div float64) zorkian.Metric { - return copyZorkianSystemMetricWithUnit(src, name, div, "") -} - -func copyZorkianSystemMetricWithUnit(src zorkian.Metric, name string, div float64, unit string) zorkian.Metric { - cp := src - cp.Metric = &name - i := 1 - cp.Interval = &i - t := "gauge" - cp.Type = &t - if div == 0 || div == 1 || len(src.Points) == 0 { - // division by 0 or 1 should not have an impact - return cp - } - if unit != "" { - cp.Unit = &unit - } - cp.Points = make([]zorkian.DataPoint, len(src.Points)) - for i, dp := range src.Points { - cp.Points[i][0] = dp[0] - if dp[1] != nil { - newdp := *dp[1] / div - cp.Points[i][1] = &newdp - } - } - return cp -} - -// extractZorkianSystemMetric takes an OpenTelemetry metric m and extracts Datadog system metrics from it, -// if m is a valid system metric. The boolean argument reports whether any system metrics were extractd. -func extractZorkianSystemMetric(m zorkian.Metric) []zorkian.Metric { - var series []zorkian.Metric - switch *m.Metric { - case "system.cpu.load_average.1m": - series = append(series, copyZorkianSystemMetric(m, "system.load.1", 1)) - case "system.cpu.load_average.5m": - series = append(series, copyZorkianSystemMetric(m, "system.load.5", 1)) - case "system.cpu.load_average.15m": - series = append(series, copyZorkianSystemMetric(m, "system.load.15", 1)) - case "system.cpu.utilization": - for _, tag := range m.Tags { - switch tag { - case "state:idle": - series = append(series, copyZorkianSystemMetric(m, "system.cpu.idle", divPercentage)) - case "state:user": - series = append(series, copyZorkianSystemMetric(m, "system.cpu.user", divPercentage)) - case "state:system": - series = append(series, copyZorkianSystemMetric(m, "system.cpu.system", divPercentage)) - case "state:wait": - series = append(series, copyZorkianSystemMetric(m, "system.cpu.iowait", divPercentage)) - case "state:steal": - series = append(series, copyZorkianSystemMetric(m, "system.cpu.stolen", divPercentage)) - } - } - case "system.memory.usage": - series = append(series, copyZorkianSystemMetric(m, "system.mem.total", divMebibytes)) - for _, tag := range m.Tags { - switch tag { - case "state:free", "state:cached", "state:buffered": - series = append(series, copyZorkianSystemMetric(m, "system.mem.usable", divMebibytes)) - } - } - case "system.network.io": - for _, tag := range m.Tags { - switch tag { - case "direction:receive": - series = append(series, copyZorkianSystemMetric(m, "system.net.bytes_rcvd", 1)) - case "direction:transmit": - series = append(series, copyZorkianSystemMetric(m, "system.net.bytes_sent", 1)) - } - } - case "system.paging.usage": - for _, tag := range m.Tags { - switch tag { - case "state:free": - series = append(series, copyZorkianSystemMetric(m, "system.swap.free", divMebibytes)) - case "state:used": - series = append(series, copyZorkianSystemMetric(m, "system.swap.used", divMebibytes)) - } - } - case "system.filesystem.utilization": - series = append(series, copyZorkianSystemMetric(m, "system.disk.in_use", 1)) - } - return series -} - -// PrepareZorkianSystemMetrics prepends system hosts metrics with the otel.* prefix to identify -// them as part of the Datadog OpenTelemetry Integration. It also extracts Datadog compatible -// system metrics and returns the full set of metrics to be used. -func PrepareZorkianSystemMetrics(ms []zorkian.Metric) []zorkian.Metric { - series := ms - for i, m := range ms { - if !strings.HasPrefix(*m.Metric, "system.") && - !strings.HasPrefix(*m.Metric, "process.") { - // not a system metric - continue - } - series = append(series, extractZorkianSystemMetric(m)...) - // all existing system metrics need to be prepended - newname := otelNamespacePrefix + *m.Metric - series[i].Metric = &newname - } - return series -} - -// PrepareZorkianContainerMetrics converts OTEL container.* metrics to Datadog container -// metrics. -func PrepareZorkianContainerMetrics(ms []zorkian.Metric) []zorkian.Metric { - series := ms - for _, m := range ms { - if !strings.HasPrefix(*m.Metric, "container.") { - // not what we're looking for - continue - } - switch *m.Metric { - case "container.cpu.usage.total": - series = append(series, copyZorkianSystemMetricWithUnit(m, "container.cpu.usage", 1, "nanocore")) - case "container.cpu.usage.usermode": - series = append(series, copyZorkianSystemMetricWithUnit(m, "container.cpu.user", 1, "nanocore")) - case "container.cpu.usage.system": - series = append(series, copyZorkianSystemMetricWithUnit(m, "container.cpu.system", 1, "nanocore")) - case "container.cpu.throttling_data.throttled_time": - series = append(series, copyZorkianSystemMetric(m, "container.cpu.throttled", 1)) - case "container.cpu.throttling_data.throttled_periods": - series = append(series, copyZorkianSystemMetric(m, "container.cpu.throttled.periods", 1)) - case "container.memory.usage.total": - series = append(series, copyZorkianSystemMetric(m, "container.memory.usage", 1)) - case "container.memory.active_anon": - series = append(series, copyZorkianSystemMetric(m, "container.memory.kernel", 1)) - case "container.memory.hierarchical_memory_limit": - series = append(series, copyZorkianSystemMetric(m, "container.memory.limit", 1)) - case "container.memory.usage.limit": - series = append(series, copyZorkianSystemMetric(m, "container.memory.soft_limit", 1)) - case "container.memory.total_cache": - series = append(series, copyZorkianSystemMetric(m, "container.memory.cache", 1)) - case "container.memory.total_swap": - series = append(series, copyZorkianSystemMetric(m, "container.memory.swap", 1)) - case "container.blockio.io_service_bytes_recursive": - for _, tag := range m.Tags { - switch tag { - case "operation:write": - series = append(series, copyZorkianSystemMetric(m, "container.io.write", 1)) - case "operation:read": - series = append(series, copyZorkianSystemMetric(m, "container.io.read", 1)) - } - } - case "container.blockio.io_serviced_recursive": - for _, tag := range m.Tags { - switch tag { - case "operation:write": - series = append(series, copyZorkianSystemMetric(m, "container.io.write.operations", 1)) - case "operation:read": - series = append(series, copyZorkianSystemMetric(m, "container.io.read.operations", 1)) - } - } - case "container.network.io.usage.tx_bytes": - series = append(series, copyZorkianSystemMetric(m, "container.net.sent", 1)) - case "container.network.io.usage.tx_packets": - series = append(series, copyZorkianSystemMetric(m, "container.net.sent.packets", 1)) - case "container.network.io.usage.rx_bytes": - series = append(series, copyZorkianSystemMetric(m, "container.net.rcvd", 1)) - case "container.network.io.usage.rx_packets": - series = append(series, copyZorkianSystemMetric(m, "container.net.rcvd.packets", 1)) - } - } - return series -} diff --git a/exporter/datadogexporter/internal/metrics/system_deprecated_test.go b/exporter/datadogexporter/internal/metrics/system_deprecated_test.go deleted file mode 100644 index d19ef9dc0dcf..000000000000 --- a/exporter/datadogexporter/internal/metrics/system_deprecated_test.go +++ /dev/null @@ -1,697 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" - -import ( - "fmt" - "math" - "testing" - - "github.com/stretchr/testify/require" - zorkian "gopkg.in/zorkian/go-datadog-api.v2" -) - -func TestCopyZorkianMetric(t *testing.T) { - sptr := func(s string) *string { return &s } - dptr := func(d int) *int { return &d } - dp := func(a, b float64) zorkian.DataPoint { return zorkian.DataPoint{&a, &b} } - - t.Run("renaming", func(t *testing.T) { - require.EqualValues(t, copyZorkianSystemMetric(zorkian.Metric{ - Metric: sptr("oldname"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("oldtype"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(3), - }, "newname", 1), zorkian.Metric{ - Metric: sptr("newname"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("gauge"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(1), - }) - - require.EqualValues(t, copyZorkianSystemMetric(zorkian.Metric{ - Metric: sptr("oldname"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("oldtype"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(3), - }, "", 1), zorkian.Metric{ - Metric: sptr(""), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("gauge"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(1), - }) - - require.EqualValues(t, copyZorkianSystemMetric(zorkian.Metric{ - Metric: nil, - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("oldtype"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(3), - }, "", 1), zorkian.Metric{ - Metric: sptr(""), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("gauge"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(1), - }) - }) - - t.Run("interval", func(t *testing.T) { - require.EqualValues(t, copyZorkianSystemMetric(zorkian.Metric{ - Metric: nil, - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("oldtype"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(3), - }, "", 1), zorkian.Metric{ - Metric: sptr(""), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Type: sptr("gauge"), - Host: sptr("oldhost"), - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - Interval: dptr(1), - }) - }) - - t.Run("division", func(t *testing.T) { - for _, tt := range []struct { - in, out []zorkian.DataPoint - div float64 - }{ - { - in: []zorkian.DataPoint{dp(0, 0), dp(1, 20)}, - div: 0, - out: []zorkian.DataPoint{dp(0, 0), dp(1, 20)}, - }, - { - in: []zorkian.DataPoint{dp(0, 0), dp(1, 20)}, - div: 1, - out: []zorkian.DataPoint{dp(0, 0), dp(1, 20)}, - }, - { - in: []zorkian.DataPoint{dp(1.1, 0), {}}, - div: 2, - out: []zorkian.DataPoint{dp(1.1, 0), {}}, - }, - { - in: []zorkian.DataPoint{dp(0, 0), dp(1, 20)}, - div: 10, - out: []zorkian.DataPoint{dp(0, 0), dp(1, 2)}, - }, - { - in: []zorkian.DataPoint{dp(1.1, 0), dp(55.5, math.MaxFloat64)}, - div: 1024 * 1024.5, - out: []zorkian.DataPoint{dp(1.1, 0), dp(55.5, 1.713577063947272e+302)}, - }, - { - in: []zorkian.DataPoint{dp(1.1, 0), dp(55.5, 20)}, - div: math.MaxFloat64, - out: []zorkian.DataPoint{dp(1.1, 0), dp(55.5, 1.1125369292536009e-307)}, - }, - } { - t.Run(fmt.Sprintf("%.0f", tt.div), func(t *testing.T) { - require.EqualValues(t, - copyZorkianSystemMetric(zorkian.Metric{Points: tt.in}, "", tt.div), - zorkian.Metric{Metric: sptr(""), Type: sptr("gauge"), Points: tt.out, Interval: dptr(1)}, - ) - }) - } - }) -} - -func TestExtractZorkianSystemMetrics(t *testing.T) { - sptr := func(s string) *string { return &s } - dptr := func(d int) *int { return &d } - dp := func(a, b float64) zorkian.DataPoint { return zorkian.DataPoint{&a, &b} } - - for _, tt := range []struct { - in zorkian.Metric - out []zorkian.Metric - }{ - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.load_average.1m"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.load.1"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.load_average.5m"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.load.5"), - Points: []zorkian.DataPoint{dp(1, 2), dp(3, 4)}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.load_average.15m"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.load.15"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:idle"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.cpu.idle"), - Points: []zorkian.DataPoint{dp(2, 200), dp(3, 400)}, - Interval: dptr(1), - Tags: []string{"state:idle"}, - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:user"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.cpu.user"), - Points: []zorkian.DataPoint{dp(2, 200), dp(3, 400)}, - Interval: dptr(1), - Tags: []string{"state:user"}, - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:system"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.cpu.system"), - Points: []zorkian.DataPoint{dp(2, 200), dp(3, 400)}, - Interval: dptr(1), - Tags: []string{"state:system"}, - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:wait"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.cpu.iowait"), - Points: []zorkian.DataPoint{dp(2, 200), dp(3, 400)}, - Interval: dptr(1), - Tags: []string{"state:wait"}, - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.cpu.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:steal"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.cpu.stolen"), - Points: []zorkian.DataPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:steal"}, - Type: sptr("gauge"), - Interval: dptr(1), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.memory.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:other"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:other"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.memory.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:free"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Interval: dptr(1), - Type: sptr("gauge"), - }, { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.memory.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:cached"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:cached"}, - Interval: dptr(1), - Type: sptr("gauge"), - }, { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:cached"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.memory.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:buffered"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:buffered"}, - Interval: dptr(1), - Type: sptr("gauge"), - }, { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:buffered"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.network.io"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:receive"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.net.bytes_rcvd"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:receive"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.network.io"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:transmit"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.net.bytes_sent"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:transmit"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.paging.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:free"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.swap.free"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.paging.usage"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:used"}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.swap.used"), - Points: []zorkian.DataPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:used"}, - Interval: dptr(1), - Type: sptr("gauge"), - }}, - }, - { - in: zorkian.Metric{ - Metric: sptr("system.filesystem.utilization"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - }, - out: []zorkian.Metric{{ - Metric: sptr("system.disk.in_use"), - Points: []zorkian.DataPoint{dp(2, 2), dp(3, 4)}, - Type: sptr("gauge"), - Interval: dptr(1), - }}, - }, - } { - t.Run("", func(t *testing.T) { - out := extractZorkianSystemMetric(tt.in) - require.EqualValues(t, tt.out, out, fmt.Sprintf("%s[%#v]", *tt.in.Metric, tt.in.Tags)) - }) - } -} - -func TestPrepareZorkianSystemMetrics(t *testing.T) { - m := func(name string, tags []string, points ...float64) zorkian.Metric { - met := zorkian.Metric{ - Metric: &name, - Tags: tags, - } - if len(points)%2 != 0 { - t.Fatal("Number of data point arguments passed to function must be even.") - } - met.Points = make([]zorkian.DataPoint, 0, len(points)/2) - for i := 0; i < len(points); i += 2 { - met.Points = append(met.Points, zorkian.DataPoint{&points[i], &points[i+1]}) - } - return met - } - fptr := func(d float64) *float64 { return &d } - dptr := func(d int) *int { return &d } - sptr := func(s string) *string { return &s } - require.EqualValues(t, PrepareZorkianSystemMetrics([]zorkian.Metric{ - m("system.metric.1", nil, 0.1, 0.2), - m("system.metric.2", nil, 0.3, 0.4), - m("process.metric.1", nil, 0.5, 0.6), - m("process.metric.2", nil, 0.7, 0.8), - m("system.cpu.load_average.1m", nil, 1, 2), - m("system.cpu.load_average.5m", nil, 3, 4), - m("system.cpu.load_average.15m", nil, 5, 6), - m("system.cpu.utilization", []string{"state:idle"}, 0.15, 0.17), - m("system.cpu.utilization", []string{"state:user"}, 0.18, 0.19), - m("system.cpu.utilization", []string{"state:system"}, 0.20, 0.21), - m("system.cpu.utilization", []string{"state:wait"}, 0.22, 0.23), - m("system.cpu.utilization", []string{"state:steal"}, 0.24, 0.25), - m("system.cpu.utilization", []string{"state:other"}, 0.26, 0.27), - m("system.memory.usage", nil, 1, 0.30), - m("system.memory.usage", []string{"state:other"}, 1, 1.35), - m("system.memory.usage", []string{"state:free"}, 1, 1.30), - m("system.memory.usage", []string{"state:cached"}, 1, 1.35), - m("system.memory.usage", []string{"state:buffered"}, 1, 1.37, 2, 2.22), - m("system.network.io", []string{"direction:receive"}, 1, 2.37, 2, 3.22), - m("system.network.io", []string{"direction:transmit"}, 1, 4.37, 2, 5.22), - m("system.paging.usage", []string{"state:free"}, 1, 4.37, 2, 5.22), - m("system.paging.usage", []string{"state:used"}, 1, 4.3, 2, 8.22), - m("system.filesystem.utilization", nil, 1, 4.3, 2, 5.5, 3, 12.1), - }), []zorkian.Metric{ - { - Metric: sptr("otel.system.metric.1"), - Points: []zorkian.DataPoint{{fptr(0.1), fptr(0.2)}}, - }, - { - Metric: sptr("otel.system.metric.2"), - Points: []zorkian.DataPoint{{fptr(0.3), fptr(0.4)}}, - }, - { - Metric: sptr("otel.process.metric.1"), - Points: []zorkian.DataPoint{{fptr(0.5), fptr(0.6)}}, - }, - { - Metric: sptr("otel.process.metric.2"), - Points: []zorkian.DataPoint{{fptr(0.7), fptr(0.8)}}, - }, - { - Metric: sptr("otel.system.cpu.load_average.1m"), - Points: []zorkian.DataPoint{{fptr(1), fptr(2)}}, - }, - { - Metric: sptr("otel.system.cpu.load_average.5m"), - Points: []zorkian.DataPoint{{fptr(3), fptr(4)}}, - }, - { - Metric: sptr("otel.system.cpu.load_average.15m"), - Points: []zorkian.DataPoint{{fptr(5), fptr(6)}}, - }, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.15), fptr(0.17)}}, - Tags: []string{"state:idle"}, - }, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.18), fptr(0.19)}}, - Tags: []string{"state:user"}, - }, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.2), fptr(0.21)}}, - Tags: []string{"state:system"}, - }, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.22), fptr(0.23)}}, - Tags: []string{"state:wait"}}, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.24), fptr(0.25)}}, - Tags: []string{"state:steal"}, - }, - { - Metric: sptr("otel.system.cpu.utilization"), - Points: []zorkian.DataPoint{{fptr(0.26), fptr(0.27)}}, - Tags: []string{"state:other"}}, - { - Metric: sptr("otel.system.memory.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(0.3)}}, - }, - { - Metric: sptr("otel.system.memory.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.35)}}, - Tags: []string{"state:other"}, - }, - { - Metric: sptr("otel.system.memory.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.3)}}, - Tags: []string{"state:free"}, - }, - { - Metric: sptr("otel.system.memory.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.35)}}, - Tags: []string{"state:cached"}, - }, - { - Metric: sptr("otel.system.memory.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.37)}, {fptr(2), fptr(2.22)}}, - Tags: []string{"state:buffered"}, - }, - { - Metric: sptr("otel.system.network.io"), - Points: []zorkian.DataPoint{{fptr(1), fptr(2.37)}, {fptr(2), fptr(3.22)}}, - Tags: []string{"direction:receive"}, - }, - { - Metric: sptr("otel.system.network.io"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.37)}, {fptr(2), fptr(5.22)}}, - Tags: []string{"direction:transmit"}, - }, - { - Metric: sptr("otel.system.paging.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.37)}, {fptr(2), fptr(5.22)}}, - Tags: []string{"state:free"}, - }, - { - Metric: sptr("otel.system.paging.usage"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.3)}, {fptr(2), fptr(8.22)}}, - Tags: []string{"state:used"}, - }, - { - Metric: sptr("otel.system.filesystem.utilization"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.3)}, {fptr(2), fptr(5.5)}, {fptr(3), fptr(12.1)}}, - }, - { - Metric: sptr("system.load.1"), - Points: []zorkian.DataPoint{{fptr(1), fptr(2)}}, - Type: sptr("gauge"), - Interval: dptr(1), - }, - { - Metric: sptr("system.load.5"), - Points: []zorkian.DataPoint{{fptr(3), fptr(4)}}, - Type: sptr("gauge"), - Interval: dptr(1), - }, - { - Metric: sptr("system.load.15"), - Points: []zorkian.DataPoint{{fptr(5), fptr(6)}}, - Type: sptr("gauge"), - Interval: dptr(1), - }, - { - Metric: sptr("system.cpu.idle"), - Points: []zorkian.DataPoint{{fptr(0.15), fptr(17)}}, - Type: sptr("gauge"), - Tags: []string{"state:idle"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.cpu.user"), - Points: []zorkian.DataPoint{{fptr(0.18), fptr(19)}}, - Type: sptr("gauge"), - Tags: []string{"state:user"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.cpu.system"), - Points: []zorkian.DataPoint{{fptr(0.2), fptr(21)}}, - Type: sptr("gauge"), - Tags: []string{"state:system"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.cpu.iowait"), - Points: []zorkian.DataPoint{{fptr(0.22), fptr(23)}}, - Type: sptr("gauge"), - Tags: []string{"state:wait"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.cpu.stolen"), - Points: []zorkian.DataPoint{{fptr(0.24), fptr(25)}}, - Type: sptr("gauge"), - Tags: []string{"state:steal"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{{fptr(1), fptr(2.86102294921875e-07)}}, - Type: sptr("gauge"), - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.2874603271484376e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:other"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.239776611328125e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:free"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.239776611328125e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:free"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.2874603271484376e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:cached"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.2874603271484376e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:cached"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.total"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.3065338134765626e-06)}, {fptr(2), fptr(2.117156982421875e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:buffered"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.mem.usable"), - Points: []zorkian.DataPoint{{fptr(1), fptr(1.3065338134765626e-06)}, {fptr(2), fptr(2.117156982421875e-06)}}, - Type: sptr("gauge"), - Tags: []string{"state:buffered"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.net.bytes_rcvd"), - Points: []zorkian.DataPoint{{fptr(1), fptr(2.37)}, {fptr(2), fptr(3.22)}}, - Type: sptr("gauge"), - Tags: []string{"direction:receive"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.net.bytes_sent"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.37)}, {fptr(2), fptr(5.22)}}, - Type: sptr("gauge"), - Tags: []string{"direction:transmit"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.swap.free"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.37 / 1024 / 1024)}, {fptr(2), fptr(5.22 / 1024 / 1024)}}, - Type: sptr("gauge"), - Tags: []string{"state:free"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.swap.used"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.3 / 1024 / 1024)}, {fptr(2), fptr(8.22 / 1024 / 1024)}}, - Type: sptr("gauge"), - Tags: []string{"state:used"}, - Interval: dptr(1), - }, - { - Metric: sptr("system.disk.in_use"), - Points: []zorkian.DataPoint{{fptr(1), fptr(4.3)}, {fptr(2), fptr(5.5)}, {fptr(3), fptr(12.1)}}, - Type: sptr("gauge"), - Interval: dptr(1), - }, - }) -} diff --git a/exporter/datadogexporter/internal/metrics/system_test.go b/exporter/datadogexporter/internal/metrics/system_test.go deleted file mode 100644 index f0829ca09d04..000000000000 --- a/exporter/datadogexporter/internal/metrics/system_test.go +++ /dev/null @@ -1,653 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metrics" - -import ( - "fmt" - "math" - "testing" - - "github.com/DataDog/datadog-api-client-go/v2/api/datadog" - "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" - "github.com/stretchr/testify/require" -) - -func TestCopyMetric(t *testing.T) { - sptr := func(s string) *string { return &s } - dp := func(a int64, b float64) datadogV2.MetricPoint { - return datadogV2.MetricPoint{ - Timestamp: datadog.PtrInt64(a), - Value: datadog.PtrFloat64(b), - } - } - - var unspecified = datadogV2.METRICINTAKETYPE_UNSPECIFIED - var gauge = datadogV2.METRICINTAKETYPE_GAUGE - - t.Run("renaming", func(t *testing.T) { - require.EqualValues(t, copySystemMetric(datadogV2.MetricSeries{ - Metric: "oldname", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &unspecified, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }, "newname", 1), datadogV2.MetricSeries{ - Metric: "newname", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &gauge, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }) - - require.EqualValues(t, copySystemMetric(datadogV2.MetricSeries{ - Metric: "oldname", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &unspecified, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }, "", 1), datadogV2.MetricSeries{ - Metric: "", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &gauge, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }) - - require.EqualValues(t, copySystemMetric(datadogV2.MetricSeries{ - Metric: "", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &unspecified, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }, "", 1), datadogV2.MetricSeries{ - Metric: "", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &gauge, - Resources: []datadogV2.MetricResource{{Name: sptr("oldhost"), Type: sptr("host")}}, - Tags: []string{"x", "y", "z"}, - Unit: sptr("oldunit"), - }) - }) - - t.Run("division", func(t *testing.T) { - for _, tt := range []struct { - in, out []datadogV2.MetricPoint - div float64 - }{ - { - in: []datadogV2.MetricPoint{dp(0, 0), dp(1, 20)}, - div: 0, - out: []datadogV2.MetricPoint{dp(0, 0), dp(1, 20)}, - }, - { - in: []datadogV2.MetricPoint{dp(0, 0), dp(1, 20)}, - div: 1, - out: []datadogV2.MetricPoint{dp(0, 0), dp(1, 20)}, - }, - { - in: []datadogV2.MetricPoint{dp(1, 0), {}}, - div: 2, - out: []datadogV2.MetricPoint{dp(1, 0), {}}, - }, - { - in: []datadogV2.MetricPoint{dp(0, 0), dp(1, 20)}, - div: 10, - out: []datadogV2.MetricPoint{dp(0, 0), dp(1, 2)}, - }, - { - in: []datadogV2.MetricPoint{dp(1, 0), dp(55, math.MaxFloat64)}, - div: 1024 * 1024.5, - out: []datadogV2.MetricPoint{dp(1, 0), dp(55, 1.713577063947272e+302)}, - }, - { - in: []datadogV2.MetricPoint{dp(1, 0), dp(55, 20)}, - div: math.MaxFloat64, - out: []datadogV2.MetricPoint{dp(1, 0), dp(55, 1.1125369292536009e-307)}, - }, - } { - t.Run(fmt.Sprintf("%.0f", tt.div), func(t *testing.T) { - require.EqualValues(t, - copySystemMetric(datadogV2.MetricSeries{Points: tt.in}, "", tt.div), - datadogV2.MetricSeries{Metric: "", Type: &gauge, Points: tt.out}, - ) - }) - } - }) -} - -func TestExtractSystemMetrics(t *testing.T) { - dp := func(a int64, b float64) datadogV2.MetricPoint { - return datadogV2.MetricPoint{ - Timestamp: datadog.PtrInt64(a), - Value: datadog.PtrFloat64(b), - } - } - - var gauge = datadogV2.METRICINTAKETYPE_GAUGE - - for _, tt := range []struct { - in datadogV2.MetricSeries - out []datadogV2.MetricSeries - }{ - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.load_average.1m", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.load.1", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.load_average.5m", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.load.5", - Points: []datadogV2.MetricPoint{dp(1, 2), dp(3, 4)}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.load_average.15m", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.load.15", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:idle"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.cpu.idle", - Points: []datadogV2.MetricPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:idle"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:user"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.cpu.user", - Points: []datadogV2.MetricPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:user"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:system"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.cpu.system", - Points: []datadogV2.MetricPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:system"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:wait"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.cpu.iowait", - Points: []datadogV2.MetricPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:wait"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:steal"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.cpu.stolen", - Points: []datadogV2.MetricPoint{dp(2, 200), dp(3, 400)}, - Tags: []string{"state:steal"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.memory.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:other"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:other"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.memory.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:free"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Type: &gauge, - }, { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.memory.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:cached"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:cached"}, - Type: &gauge, - }, { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:cached"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.memory.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:buffered"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:buffered"}, - Type: &gauge, - }, { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:buffered"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.network.io", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:receive"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.net.bytes_rcvd", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:receive"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.network.io", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:transmit"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.net.bytes_sent", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"direction:transmit"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.paging.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:free"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.swap.free", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:free"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.paging.usage", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Tags: []string{"state:used"}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.swap.used", - Points: []datadogV2.MetricPoint{dp(2, 1.9073486328125e-06), dp(3, 3.814697265625e-06)}, - Tags: []string{"state:used"}, - Type: &gauge, - }}, - }, - { - in: datadogV2.MetricSeries{ - Metric: "system.filesystem.utilization", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - }, - out: []datadogV2.MetricSeries{{ - Metric: "system.disk.in_use", - Points: []datadogV2.MetricPoint{dp(2, 2), dp(3, 4)}, - Type: &gauge, - }}, - }, - } { - t.Run("", func(t *testing.T) { - out := extractSystemMetrics(tt.in) - require.EqualValues(t, tt.out, out, fmt.Sprintf("%s[%#v]", tt.in.Metric, tt.in.Tags)) - }) - } -} - -func TestPrepareSystemMetrics(t *testing.T) { - var gauge = datadogV2.METRICINTAKETYPE_GAUGE - - m := func(name string, tags []string, points ...float64) datadogV2.MetricSeries { - met := datadogV2.MetricSeries{ - Metric: name, - Tags: tags, - } - if len(points)%2 != 0 { - t.Fatal("Number of data point arguments passed to function must be even.") - } - met.Points = make([]datadogV2.MetricPoint, 0, len(points)/2) - for i := 0; i < len(points); i += 2 { - ts := int64(points[i]) - val := points[i+1] - met.Points = append(met.Points, datadogV2.MetricPoint{Timestamp: datadog.PtrInt64(ts), Value: datadog.PtrFloat64(val)}) - } - return met - } - - dp := func(a int64, b float64) datadogV2.MetricPoint { - return datadogV2.MetricPoint{ - Timestamp: datadog.PtrInt64(a), - Value: datadog.PtrFloat64(b), - } - } - - require.EqualValues(t, PrepareSystemMetrics([]datadogV2.MetricSeries{ - m("system.metric.1", nil, 0.1, 0.2), - m("system.metric.2", nil, 0.3, 0.4), - m("process.metric.1", nil, 0.5, 0.6), - m("process.metric.2", nil, 0.7, 0.8), - m("system.cpu.load_average.1m", nil, 1, 2), - m("system.cpu.load_average.5m", nil, 3, 4), - m("system.cpu.load_average.15m", nil, 5, 6), - m("system.cpu.utilization", []string{"state:idle"}, 0.15, 0.17), - m("system.cpu.utilization", []string{"state:user"}, 0.18, 0.19), - m("system.cpu.utilization", []string{"state:system"}, 0.20, 0.21), - m("system.cpu.utilization", []string{"state:wait"}, 0.22, 0.23), - m("system.cpu.utilization", []string{"state:steal"}, 0.24, 0.25), - m("system.cpu.utilization", []string{"state:other"}, 0.26, 0.27), - m("system.memory.usage", nil, 1, 0.30), - m("system.memory.usage", []string{"state:other"}, 1, 1.35), - m("system.memory.usage", []string{"state:free"}, 1, 1.30), - m("system.memory.usage", []string{"state:cached"}, 1, 1.35), - m("system.memory.usage", []string{"state:buffered"}, 1, 1.37, 2, 2.22), - m("system.network.io", []string{"direction:receive"}, 1, 2.37, 2, 3.22), - m("system.network.io", []string{"direction:transmit"}, 1, 4.37, 2, 5.22), - m("system.paging.usage", []string{"state:free"}, 1, 4.37, 2, 5.22), - m("system.paging.usage", []string{"state:used"}, 1, 4.3, 2, 8.22), - m("system.filesystem.utilization", nil, 1, 4.3, 2, 5.5, 3, 12.1), - }), []datadogV2.MetricSeries{ - { - Metric: "otel.system.metric.1", - Points: []datadogV2.MetricPoint{dp(0, 0.2)}, - }, - { - Metric: "otel.system.metric.2", - Points: []datadogV2.MetricPoint{dp(0, 0.4)}, - }, - { - Metric: "otel.process.metric.1", - Points: []datadogV2.MetricPoint{dp(0, 0.6)}, - }, - { - Metric: "otel.process.metric.2", - Points: []datadogV2.MetricPoint{dp(0, 0.8)}, - }, - { - Metric: "otel.system.cpu.load_average.1m", - Points: []datadogV2.MetricPoint{dp(1, 2)}, - }, - { - Metric: "otel.system.cpu.load_average.5m", - Points: []datadogV2.MetricPoint{dp(3, 4)}, - }, - { - Metric: "otel.system.cpu.load_average.15m", - Points: []datadogV2.MetricPoint{dp(5, 6)}, - }, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.17)}, - Tags: []string{"state:idle"}, - }, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.19)}, - Tags: []string{"state:user"}, - }, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.21)}, - Tags: []string{"state:system"}, - }, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.23)}, - Tags: []string{"state:wait"}}, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.25)}, - Tags: []string{"state:steal"}, - }, - { - Metric: "otel.system.cpu.utilization", - Points: []datadogV2.MetricPoint{dp(0, 0.27)}, - Tags: []string{"state:other"}, - }, - { - Metric: "otel.system.memory.usage", - Points: []datadogV2.MetricPoint{dp(1, 0.3)}, - }, - { - Metric: "otel.system.memory.usage", - Points: []datadogV2.MetricPoint{dp(1, 1.35)}, - Tags: []string{"state:other"}, - }, - { - Metric: "otel.system.memory.usage", - Points: []datadogV2.MetricPoint{dp(1, 1.3)}, - Tags: []string{"state:free"}, - }, - { - Metric: "otel.system.memory.usage", - Points: []datadogV2.MetricPoint{dp(1, 1.35)}, - Tags: []string{"state:cached"}, - }, - { - Metric: "otel.system.memory.usage", - Points: []datadogV2.MetricPoint{dp(1, 1.37), dp(2, 2.22)}, - Tags: []string{"state:buffered"}, - }, - { - Metric: "otel.system.network.io", - Points: []datadogV2.MetricPoint{dp(1, 2.37), dp(2, 3.22)}, - Tags: []string{"direction:receive"}, - }, - { - Metric: "otel.system.network.io", - Points: []datadogV2.MetricPoint{dp(1, 4.37), dp(2, 5.22)}, - Tags: []string{"direction:transmit"}, - }, - { - Metric: "otel.system.paging.usage", - Points: []datadogV2.MetricPoint{dp(1, 4.37), dp(2, 5.22)}, - Tags: []string{"state:free"}, - }, - { - Metric: "otel.system.paging.usage", - Points: []datadogV2.MetricPoint{dp(1, 4.3), dp(2, 8.22)}, - Tags: []string{"state:used"}, - }, - { - Metric: "otel.system.filesystem.utilization", - Points: []datadogV2.MetricPoint{dp(1, 4.3), dp(2, 5.5), dp(3, 12.1)}, - }, - { - Metric: "system.load.1", - Points: []datadogV2.MetricPoint{dp(1, 2)}, - Type: &gauge, - }, - { - Metric: "system.load.5", - Points: []datadogV2.MetricPoint{dp(3, 4)}, - Type: &gauge, - }, - { - Metric: "system.load.15", - Points: []datadogV2.MetricPoint{dp(5, 6)}, - Type: &gauge, - }, - { - Metric: "system.cpu.idle", - Points: []datadogV2.MetricPoint{dp(0, 17)}, - Type: &gauge, - Tags: []string{"state:idle"}, - }, - { - Metric: "system.cpu.user", - Points: []datadogV2.MetricPoint{dp(0, 19)}, - Type: &gauge, - Tags: []string{"state:user"}, - }, - { - Metric: "system.cpu.system", - Points: []datadogV2.MetricPoint{dp(0, 21)}, - Type: &gauge, - Tags: []string{"state:system"}, - }, - { - Metric: "system.cpu.iowait", - Points: []datadogV2.MetricPoint{dp(0, 23)}, - Type: &gauge, - Tags: []string{"state:wait"}, - }, - { - Metric: "system.cpu.stolen", - Points: []datadogV2.MetricPoint{dp(0, 25)}, - Type: &gauge, - Tags: []string{"state:steal"}, - }, - { - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(1, 2.86102294921875e-07)}, - Type: &gauge, - }, - { - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(1, 1.2874603271484376e-06)}, - Type: &gauge, - Tags: []string{"state:other"}, - }, - { - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(1, 1.239776611328125e-06)}, - Type: &gauge, - Tags: []string{"state:free"}, - }, - { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(1, 1.239776611328125e-06)}, - Type: &gauge, - Tags: []string{"state:free"}, - }, - { - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(1, 1.2874603271484376e-06)}, - Type: &gauge, - Tags: []string{"state:cached"}, - }, - { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(1, 1.2874603271484376e-06)}, - Type: &gauge, - Tags: []string{"state:cached"}, - }, - { - Metric: "system.mem.total", - Points: []datadogV2.MetricPoint{dp(1, 1.3065338134765626e-06), dp(2, 2.117156982421875e-06)}, - Type: &gauge, - Tags: []string{"state:buffered"}, - }, - { - Metric: "system.mem.usable", - Points: []datadogV2.MetricPoint{dp(1, 1.3065338134765626e-06), dp(2, 2.117156982421875e-06)}, - Type: &gauge, - Tags: []string{"state:buffered"}, - }, - { - Metric: "system.net.bytes_rcvd", - Points: []datadogV2.MetricPoint{dp(1, 2.37), dp(2, 3.22)}, - Type: &gauge, - Tags: []string{"direction:receive"}, - }, - { - Metric: "system.net.bytes_sent", - Points: []datadogV2.MetricPoint{dp(1, 4.37), dp(2, 5.22)}, - Type: &gauge, - Tags: []string{"direction:transmit"}, - }, - { - Metric: "system.swap.free", - Points: []datadogV2.MetricPoint{dp(1, 4.37/1024/1024), dp(2, 5.22/1024/1024)}, - Type: &gauge, - Tags: []string{"state:free"}, - }, - { - Metric: "system.swap.used", - Points: []datadogV2.MetricPoint{dp(1, 4.3/1024/1024), dp(2, 8.22/1024/1024)}, - Type: &gauge, - Tags: []string{"state:used"}, - }, - { - Metric: "system.disk.in_use", - Points: []datadogV2.MetricPoint{dp(1, 4.3), dp(2, 5.5), dp(3, 12.1)}, - Type: &gauge, - }, - }) -} diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index cf7c89264b0d..706e9b5d202b 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -52,6 +52,7 @@ func translatorFromConfig(logger *zap.Logger, cfg *Config, sourceProvider source options := []otlpmetrics.TranslatorOption{ otlpmetrics.WithDeltaTTL(cfg.Metrics.DeltaTTL), otlpmetrics.WithFallbackSourceProvider(sourceProvider), + otlpmetrics.WithRemapping(), } if cfg.Metrics.HistConfig.SendAggregations { @@ -204,9 +205,6 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr if isMetricExportV2Enabled() { var ms []datadogV2.MetricSeries ms, sl, sp = consumer.(*metrics.Consumer).All(exp.getPushTime(), exp.params.BuildInfo, tags, metadata) - ms = metrics.PrepareSystemMetrics(ms) - ms = metrics.PrepareContainerMetrics(ms) - err = nil if len(ms) > 0 { exp.params.Logger.Debug("exporting native Datadog payload", zap.Any("metric", ms)) @@ -220,9 +218,6 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr } else { var ms []zorkian.Metric ms, sl, sp = consumer.(*metrics.ZorkianConsumer).All(exp.getPushTime(), exp.params.BuildInfo, tags) - ms = metrics.PrepareZorkianSystemMetrics(ms) - ms = metrics.PrepareZorkianContainerMetrics(ms) - err = nil if len(ms) > 0 { exp.params.Logger.Debug("exporting Zorkian Datadog payload", zap.Any("metric", ms)) diff --git a/exporter/datadogexporter/metrics_exporter_test.go b/exporter/datadogexporter/metrics_exporter_test.go index 3feadd3ed42a..8d32908a0bbe 100644 --- a/exporter/datadogexporter/metrics_exporter_test.go +++ b/exporter/datadogexporter/metrics_exporter_test.go @@ -152,18 +152,18 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) { "tags": []interface{}{"lower_bound:0", "upper_bound:inf", "env:dev"}, }, map[string]interface{}{ - "metric": "otel.datadog_exporter.metrics.running", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, + "metric": "otel.system.disk.in_use", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"version:latest", "command:otelcol"}, + "tags": []interface{}{"env:dev"}, }, map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, + "metric": "otel.datadog_exporter.metrics.running", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"env:dev"}, + "tags": []interface{}{"version:latest", "command:otelcol"}, }, }, }, @@ -193,18 +193,18 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) { "tags": []interface{}{"env:dev"}, }, map[string]interface{}{ - "metric": "otel.datadog_exporter.metrics.running", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, + "metric": "otel.system.disk.in_use", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"version:latest", "command:otelcol"}, + "tags": []interface{}{"env:dev"}, }, map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, + "metric": "otel.datadog_exporter.metrics.running", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"env:dev"}, + "tags": []interface{}{"version:latest", "command:otelcol"}, }, }, }, @@ -266,18 +266,18 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) { "tags": []interface{}{"lower_bound:0", "upper_bound:inf", "env:dev", "key1:value1", "key2:value2"}, }, map[string]interface{}{ - "metric": "otel.datadog_exporter.metrics.running", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, + "metric": "otel.system.disk.in_use", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"version:latest", "command:otelcol", "key1:value1", "key2:value2"}, + "tags": []interface{}{"env:dev", "key1:value1", "key2:value2"}, }, map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(333)}}, + "metric": "otel.datadog_exporter.metrics.running", + "points": []interface{}{map[string]interface{}{"timestamp": float64(0), "value": float64(1)}}, "type": float64(datadogV2.METRICINTAKETYPE_GAUGE), "resources": []interface{}{map[string]interface{}{"name": "test-host", "type": "host"}}, - "tags": []interface{}{"env:dev", "key1:value1", "key2:value2"}, + "tags": []interface{}{"version:latest", "command:otelcol", "key1:value1", "key2:value2"}, }, }, }, @@ -473,6 +473,13 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"lower_bound:0", "upper_bound:inf", "env:dev"}, }, + map[string]interface{}{ + "metric": "otel.system.disk.in_use", + "points": []interface{}{[]interface{}{float64(0), float64(333)}}, + "type": "gauge", + "host": "test-host", + "tags": []interface{}{"env:dev"}, + }, map[string]interface{}{ "metric": "otel.datadog_exporter.metrics.running", "points": []interface{}{[]interface{}{float64(0), float64(1)}}, @@ -480,14 +487,6 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"version:latest", "command:otelcol"}, }, - map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{[]interface{}{float64(0), float64(333)}}, - "type": "gauge", - "host": "test-host", - "interval": float64(1), - "tags": []interface{}{"env:dev"}, - }, }, }, }, @@ -515,6 +514,13 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"env:dev"}, }, + map[string]interface{}{ + "metric": "otel.system.disk.in_use", + "points": []interface{}{[]interface{}{float64(0), float64(333)}}, + "type": "gauge", + "host": "test-host", + "tags": []interface{}{"env:dev"}, + }, map[string]interface{}{ "metric": "otel.datadog_exporter.metrics.running", "points": []interface{}{[]interface{}{float64(0), float64(1)}}, @@ -522,14 +528,6 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"version:latest", "command:otelcol"}, }, - map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{[]interface{}{float64(0), float64(333)}}, - "type": "gauge", - "host": "test-host", - "interval": float64(1), - "tags": []interface{}{"env:dev"}, - }, }, }, expectedSketchPayload: &gogen.SketchPayload{ @@ -589,6 +587,13 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"lower_bound:0", "upper_bound:inf", "env:dev", "key1:value1", "key2:value2"}, }, + map[string]interface{}{ + "metric": "otel.system.disk.in_use", + "points": []interface{}{[]interface{}{float64(0), float64(333)}}, + "type": "gauge", + "host": "test-host", + "tags": []interface{}{"env:dev", "key1:value1", "key2:value2"}, + }, map[string]interface{}{ "metric": "otel.datadog_exporter.metrics.running", "points": []interface{}{[]interface{}{float64(0), float64(1)}}, @@ -596,14 +601,6 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"version:latest", "command:otelcol", "key1:value1", "key2:value2"}, }, - map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{[]interface{}{float64(0), float64(333)}}, - "type": "gauge", - "host": "test-host", - "interval": float64(1), - "tags": []interface{}{"env:dev", "key1:value1", "key2:value2"}, - }, }, }, expectedSketchPayload: nil, @@ -633,6 +630,13 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"env:dev"}, }, + map[string]interface{}{ + "metric": "otel.system.disk.in_use", + "points": []interface{}{[]interface{}{float64(0), float64(333)}}, + "type": "gauge", + "host": "test-host", + "tags": []interface{}{"env:dev"}, + }, map[string]interface{}{ "metric": "otel.datadog_exporter.metrics.running", "points": []interface{}{[]interface{}{float64(0), float64(1)}}, @@ -640,14 +644,6 @@ func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) { "host": "test-host", "tags": []interface{}{"version:latest", "command:otelcol"}, }, - map[string]interface{}{ - "metric": "system.disk.in_use", - "points": []interface{}{[]interface{}{float64(0), float64(333)}}, - "type": "gauge", - "host": "test-host", - "interval": float64(1), - "tags": []interface{}{"env:dev"}, - }, }, }, expectedSketchPayload: &gogen.SketchPayload{ diff --git a/go.mod b/go.mod index 708f1ff2a0e8..b00b1e6e8fcb 100644 --- a/go.mod +++ b/go.mod @@ -240,10 +240,10 @@ require ( github.com/DataDog/datadog-go/v5 v5.1.1 // indirect github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork // indirect github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 // indirect github.com/DataDog/sketches-go v1.4.2 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 // indirect diff --git a/go.sum b/go.sum index ee19134a6af3..8598ad00ef49 100644 --- a/go.sum +++ b/go.sum @@ -743,15 +743,15 @@ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork h1:yBq5PrAtrM4yVeSzQ+bn050+ github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork/go.mod h1:yA5JwkZsHTLuqq3zaRgUQf35DfDkpOZqgtBqHKpwrBs= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc h1:gtlKB6B50/UEuFm1LeMn0R5a+tubx69OecPqxfXJDmU= github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc/go.mod h1:oyPC4jWHHjVVNjslDAKp8EqfQBaSmODjHt4HCX+C+9Q= -github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.3.0 h1:4x1lf6HLZdSAhCdOfD7E1178E5ZSw3YbvUhrYNNCCt4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0 h1:P3+qEU8Bs3hbKFKhTKBf5OabRQR9RxLl426WR44/ZLY= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.3.0/go.mod h1:ucRvNvmSkJ0QVB6mRwDNvm6TrClnqP2xGE8fqJCA2UA= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0 h1:YEgXa2scN5XEzDh/74N7Vu0oq3BzN54FessFky1eS7k= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.3.0/go.mod h1:Du8pI+PeewNbv7AmPHEGY2undFXaR0TM5fblU2/MKU4= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0 h1:GAxNu0crKwFCgUVDTgxZlnb8FLXIKcPGlpZkEls7z64= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.3.0/go.mod h1:CSnyTkVETMcA9sgY+lbGxSJbIr0ZInGeQY4Ao1sC80A= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0 h1:TYJanFBdTOTHScwDk+LBCxUU8CfqTaVhyHC0BSpmoYY= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.3.0/go.mod h1:d1F26FBaHVrDyGxBulO8ixVYbFjtLgvgcadbXwFOpJY= +github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.5.0 h1:bsK3Z6ZnjxgzQffKCQ/zv9y/gmq3f+zezdGlGH3FjyQ= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 h1:a+jLcDKyqjUU1PNncHZREMyXYkenE/IdZQvINaduJT0= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0/go.mod h1:Mixtnwg4RbENPVrodbdyxQSyVVOqBE8+qVW7GQuIKuk= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0 h1:Ca1mGZA8DRjpPnJkKsuVdRbg4m3j1KMBAEkmPujqBZg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.5.0/go.mod h1:MtJv7xlFiTL8qQlHV6yXYDUY+pAmnYyXOKaHjRgQbVw= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 h1:HkcDmHBtfNp1U23Ae8GTh/t5RabvFTyP3NIU3iyW+tg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0/go.mod h1:H2553prGE5bRNEQXjo5svUvjL7TXCtuLE5MakF6jDU0= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 h1:gKm5sSMHEeKkNUPgDAAqcCbzKCPXNf4g79C783DzTiY= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0/go.mod h1:0ieak3dqhwyEF+KB1dIMikw0cn9ZHiinmQrSebaivRw= github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjvVA/o= github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= diff --git a/processor/datadogprocessor/go.mod b/processor/datadogprocessor/go.mod index cf4fce80d1cf..c52c9ebe28db 100644 --- a/processor/datadogprocessor/go.mod +++ b/processor/datadogprocessor/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/DataDog/datadog-agent/pkg/trace v0.47.0-devel - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.2.1 + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 github.com/DataDog/sketches-go v1.4.2 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.79.1-0.20230609201858-ed8547a8e5d6 @@ -26,8 +26,8 @@ require ( github.com/DataDog/datadog-agent/pkg/util/scrubber v0.46.0-rc.2 // indirect github.com/DataDog/datadog-go/v5 v5.1.1 // indirect github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.2.3 // indirect - github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.2.3 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 // indirect + github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 // indirect github.com/Microsoft/go-winio v0.6.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect diff --git a/processor/datadogprocessor/go.sum b/processor/datadogprocessor/go.sum index 98f422fea45b..a1c2ca18df41 100644 --- a/processor/datadogprocessor/go.sum +++ b/processor/datadogprocessor/go.sum @@ -19,13 +19,13 @@ github.com/DataDog/datadog-go/v5 v5.1.1 h1:JLZ6s2K1pG2h9GkvEvMdEGqMDyVLEAccdX5Tl github.com/DataDog/datadog-go/v5 v5.1.1/go.mod h1:KhiYb2Badlv9/rofz+OznKoEF5XKTonWyhx5K83AP8E= github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork h1:yBq5PrAtrM4yVeSzQ+bn050+Ysp++RKF1QmtkL4VqvU= github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork/go.mod h1:yA5JwkZsHTLuqq3zaRgUQf35DfDkpOZqgtBqHKpwrBs= -github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.2.3 h1:IznT4hQ24X3gOir+AVotp8h/ogYoXAmvU5jggBqOO8o= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.2.3 h1:QM2aly2st5pdRuDhc8w026YXNIm9IjjyaXhJ4BTdTZQ= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.2.3/go.mod h1:q5aHWhZtr114VrPgmlJL+JnemK7O66YxDCRy9zAHAxU= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.2.1 h1:jlQDTTLPBMiHn/tEpWH9lMkOOT16UVJNfzQqE4XQe44= -github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.2.1/go.mod h1:c9En9elnWkiHWbkQyV8SvgxereMKEvBpRtjPhlwEKYQ= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.2.3 h1:qE9/iNHkwuIcSpsecG0L+rXX/dxULKWGZrSH4UHO0fA= -github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.2.3/go.mod h1:sE+tvtb7R7a9QJiLkct3WKQWKpTznLtbDRcXlnb5SNs= +github.com/DataDog/opentelemetry-mapping-go/pkg/internal/sketchtest v0.5.0 h1:bsK3Z6ZnjxgzQffKCQ/zv9y/gmq3f+zezdGlGH3FjyQ= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0 h1:a+jLcDKyqjUU1PNncHZREMyXYkenE/IdZQvINaduJT0= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.0/go.mod h1:Mixtnwg4RbENPVrodbdyxQSyVVOqBE8+qVW7GQuIKuk= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0 h1:HkcDmHBtfNp1U23Ae8GTh/t5RabvFTyP3NIU3iyW+tg= +github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.0/go.mod h1:H2553prGE5bRNEQXjo5svUvjL7TXCtuLE5MakF6jDU0= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0 h1:gKm5sSMHEeKkNUPgDAAqcCbzKCPXNf4g79C783DzTiY= +github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.0/go.mod h1:0ieak3dqhwyEF+KB1dIMikw0cn9ZHiinmQrSebaivRw= github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjvVA/o= github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=