-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[chore] [receiver/datadog] Add support for v1 series #33957
Merged
jpkrohling
merged 11 commits into
open-telemetry:main
from
grafana:cedwards/datadog-v1-metrics
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4010573
Add logic to batch metrics by attribute types
carrieedwards 83dd84e
Add support for V1 series endpoint
carrieedwards d5f7724
Add test helper functions
fedetorres93 0fedbe2
Add tests for V1 series endpoint
carrieedwards e42f62f
Add tests for batching by attributes
carrieedwards ee4e3e4
Update vendoring
carrieedwards c8f8665
Add end-to-end test for v1 series
carrieedwards 9f9d651
Refactoring of batching and v1 series translation code
carrieedwards 7344265
Fix linting
carrieedwards 57c35ad
Ignore err on writing header for V1 series
carrieedwards bb6240c
Updating go.mod
carrieedwards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package datadogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver" | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics/identity" | ||
) | ||
|
||
type Batcher struct { | ||
pmetric.Metrics | ||
|
||
resourceMetrics map[identity.Resource]pmetric.ResourceMetrics | ||
scopeMetrics map[identity.Scope]pmetric.ScopeMetrics | ||
metrics map[identity.Metric]pmetric.Metric | ||
} | ||
|
||
func newBatcher() Batcher { | ||
return Batcher{ | ||
Metrics: pmetric.NewMetrics(), | ||
resourceMetrics: make(map[identity.Resource]pmetric.ResourceMetrics), | ||
scopeMetrics: make(map[identity.Scope]pmetric.ScopeMetrics), | ||
metrics: make(map[identity.Metric]pmetric.Metric), | ||
} | ||
} | ||
|
||
// Dimensions stores the properties of the series that are needed in order | ||
// to unique identify the series. This is needed in order to batch metrics by | ||
// resource, scope, and datapoint attributes | ||
type Dimensions struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
name string | ||
metricType pmetric.MetricType | ||
resourceAttrs pcommon.Map | ||
scopeAttrs pcommon.Map | ||
dpAttrs pcommon.Map | ||
buildInfo string | ||
} | ||
|
||
var metricTypeMap = map[string]pmetric.MetricType{ | ||
"count": pmetric.MetricTypeSum, | ||
"gauge": pmetric.MetricTypeGauge, | ||
"rate": pmetric.MetricTypeSum, | ||
"service_check": pmetric.MetricTypeGauge, | ||
"sketch": pmetric.MetricTypeExponentialHistogram, | ||
} | ||
|
||
func parseSeriesProperties(name string, metricType string, tags []string, host string, version string, stringPool *StringPool) Dimensions { | ||
resourceAttrs, scopeAttrs, dpAttrs := tagsToAttributes(tags, host, stringPool) | ||
return Dimensions{ | ||
name: name, | ||
metricType: metricTypeMap[metricType], | ||
buildInfo: version, | ||
resourceAttrs: resourceAttrs, | ||
scopeAttrs: scopeAttrs, | ||
dpAttrs: dpAttrs, | ||
} | ||
} | ||
|
||
func (b Batcher) Lookup(dim Dimensions) (pmetric.Metric, identity.Metric) { | ||
resource := dim.Resource() | ||
resourceID := identity.OfResource(resource) | ||
resourceMetrics, ok := b.resourceMetrics[resourceID] | ||
if !ok { | ||
resourceMetrics = b.Metrics.ResourceMetrics().AppendEmpty() | ||
resource.MoveTo(resourceMetrics.Resource()) | ||
b.resourceMetrics[resourceID] = resourceMetrics | ||
} | ||
|
||
scope := dim.Scope() | ||
scopeID := identity.OfScope(resourceID, scope) | ||
scopeMetrics, ok := b.scopeMetrics[scopeID] | ||
if !ok { | ||
scopeMetrics = resourceMetrics.ScopeMetrics().AppendEmpty() | ||
scope.MoveTo(scopeMetrics.Scope()) | ||
b.scopeMetrics[scopeID] = scopeMetrics | ||
} | ||
|
||
m := dim.Metric() | ||
metricID := identity.OfMetric(scopeID, m) | ||
metric, ok := b.metrics[metricID] | ||
if !ok { | ||
metric = scopeMetrics.Metrics().AppendEmpty() | ||
m.MoveTo(metric) | ||
b.metrics[metricID] = metric | ||
} | ||
|
||
return metric, metricID | ||
} | ||
|
||
func (d Dimensions) Resource() pcommon.Resource { | ||
resource := pcommon.NewResource() | ||
d.resourceAttrs.CopyTo(resource.Attributes()) // TODO(jesus.vazquez) review this copy | ||
return resource | ||
} | ||
|
||
func (d Dimensions) Scope() pcommon.InstrumentationScope { | ||
scope := pcommon.NewInstrumentationScope() | ||
scope.SetName("otelcol/datadogreceiver") | ||
scope.SetVersion(d.buildInfo) | ||
d.scopeAttrs.CopyTo(scope.Attributes()) | ||
return scope | ||
} | ||
|
||
func (d Dimensions) Metric() pmetric.Metric { | ||
metric := pmetric.NewMetric() | ||
metric.SetName(d.name) | ||
switch d.metricType { | ||
case pmetric.MetricTypeSum: | ||
metric.SetEmptySum() | ||
case pmetric.MetricTypeGauge: | ||
metric.SetEmptyGauge() | ||
case pmetric.MetricTypeExponentialHistogram: | ||
metric.SetEmptyExponentialHistogram() | ||
} | ||
return metric | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be inside an internal package, otherwise it's part of this component's public API. Unless you meant to expose this to external consumers?