Skip to content

Commit

Permalink
Support bool metrics (#637)
Browse files Browse the repository at this point in the history
* Add support for bool valued metrics

* Adds collector specific example

* Remove debug print statements

* Add unit tests

* Remove lingering debug statement

* Fix go lint error(s)

* Remove special attribute keys prior to GCM export

The keys are removed from labelDescriptors and metricLabels so as to
prevent creation of separate time-series data for distinct values for
those labels.

* Refactor: early return for better readability

* Revert "Adds collector specific example"

This reverts commit 1c68822.

* Fix linter error

* Support boolean metrics via units

* Add log warning explaining failed bool conversion

* Add missing tests to increase coverage

* Add fixture based test for bool metrics

* Invert check in convertMetricKindToBoolIfSupported

Co-authored-by: Mike Dame <mikedame@google.com>

* Update test fixtures with additional cases

* Fix documentation for numberDataPointToValue

Co-authored-by: Aaron Abbott <aaronabbott@google.com>

* Update code formatting

Co-authored-by: Aaron Abbott <aaronabbott@google.com>

* Remove boolean support for Non-Monotonic Sum

* Rename convertMetricKindToBoolIfSupported -> convertToBoolIfMetricKindSupported

---------

Co-authored-by: Mike Dame <mikedame@google.com>
Co-authored-by: Aaron Abbott <aaronabbott@google.com>
  • Loading branch information
3 people committed Jun 30, 2023
1 parent ddd884e commit 207e0d8
Show file tree
Hide file tree
Showing 5 changed files with 1,030 additions and 8 deletions.
Expand Up @@ -78,6 +78,12 @@ var MetricsTestCases = []TestCase{
cfg.MetricConfig.Prefix = "workload.googleapis.com"
},
},
{
Name: "Boolean valued gauge metrics represented through int gauges",
OTLPInputFixturePath: "testdata/fixtures/metrics/boolean_gauge_metrics.json",
ExpectFixturePath: "testdata/fixtures/metrics/boolean_gauge_metrics_expect.json",
SkipForSDK: true, // Boolean valued metrics not implemented in SDK
},
{
Name: "Delta Counter",
OTLPInputFixturePath: "testdata/fixtures/metrics/delta_counter_metrics.json",
Expand Down
@@ -0,0 +1,91 @@
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "unknown_service:sample"
}
},
{
"key": "telemetry.sdk.language",
"value": {
"stringValue": "go"
}
},
{
"key": "telemetry.sdk.name",
"value": {
"stringValue": "opentelemetry"
}
},
{
"key": "telemetry.sdk.version",
"value": {
"stringValue": "1.16.0"
}
}
]
},
"scopeMetrics": [
{
"scope": {
"name": "github.com/GoogleCloudPlatform/opentelemetry-operations-go/example/collector/metric"
},
"metrics": [
{
"name": "observer-boolean-collector",
"unit": "{gcp.BOOL}",
"gauge": {
"dataPoints": [
{
"attributes": [
{
"key": "key",
"value": {
"stringValue": "value-1"
}
}
],
"startTimeUnixNano": "11651379494838206464",
"timeUnixNano": "1687377293673694987",
"asInt": "0"
},
{
"attributes": [
{
"key": "key",
"value": {
"stringValue": "value-2"
}
}
],
"startTimeUnixNano": "1688083417576000000",
"timeUnixNano": "1688083820000000000",
"asInt": "393"
},
{
"attributes": [
{
"key": "key",
"value": {
"stringValue": "value-3"
}
}
],
"startTimeUnixNano": "1688083940000000000",
"timeUnixNano": "1688084000000000000",
"asInt": "-272"
}
]
}
}
]
}
],
"schemaUrl": "https://opentelemetry.io/schemas/1.17.0"
}
]
}

0 comments on commit 207e0d8

Please sign in to comment.