-
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] Refactor translation files into internal package #34160
Merged
jpkrohling
merged 3 commits into
open-telemetry:main
from
grafana:cedwards/refactor-internal
Jul 19, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
41 changes: 41 additions & 0 deletions
41
receiver/datadogreceiver/internal/translator/metrics_translator.go
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,41 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver/internal/translator" | ||
|
||
import ( | ||
"sync" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics/identity" | ||
) | ||
|
||
type MetricsTranslator struct { | ||
sync.RWMutex | ||
buildInfo component.BuildInfo | ||
lastTs map[identity.Stream]pcommon.Timestamp | ||
stringPool *StringPool | ||
} | ||
|
||
func NewMetricsTranslator(buildInfo component.BuildInfo) *MetricsTranslator { | ||
return &MetricsTranslator{ | ||
buildInfo: buildInfo, | ||
lastTs: make(map[identity.Stream]pcommon.Timestamp), | ||
stringPool: newStringPool(), | ||
} | ||
} | ||
|
||
func (mt *MetricsTranslator) streamHasTimestamp(stream identity.Stream) (pcommon.Timestamp, bool) { | ||
mt.RLock() | ||
defer mt.RUnlock() | ||
ts, ok := mt.lastTs[stream] | ||
return ts, ok | ||
} | ||
|
||
func (mt *MetricsTranslator) updateLastTsForStream(stream identity.Stream, ts pcommon.Timestamp) { | ||
mt.Lock() | ||
defer mt.Unlock() | ||
mt.lastTs[stream] = ts | ||
} |
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 |
---|---|---|
@@ -1,47 +1,18 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package datadogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver" | ||
package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver/internal/translator" | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
datadogV1 "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics/identity" | ||
) | ||
|
||
type MetricsTranslator struct { | ||
sync.RWMutex | ||
buildInfo component.BuildInfo | ||
lastTs map[identity.Stream]pcommon.Timestamp | ||
stringPool *StringPool | ||
} | ||
|
||
func newMetricsTranslator() *MetricsTranslator { | ||
return &MetricsTranslator{ | ||
lastTs: make(map[identity.Stream]pcommon.Timestamp), | ||
stringPool: newStringPool(), | ||
} | ||
} | ||
|
||
func (mt *MetricsTranslator) streamHasTimestamp(stream identity.Stream) (pcommon.Timestamp, bool) { | ||
mt.RLock() | ||
defer mt.RUnlock() | ||
ts, ok := mt.lastTs[stream] | ||
return ts, ok | ||
} | ||
|
||
func (mt *MetricsTranslator) updateLastTsForStream(stream identity.Stream, ts pcommon.Timestamp) { | ||
mt.Lock() | ||
defer mt.Unlock() | ||
mt.lastTs[stream] = ts | ||
} | ||
|
||
const ( | ||
TypeGauge string = "gauge" | ||
TypeRate string = "rate" | ||
|
@@ -52,7 +23,7 @@ type SeriesList struct { | |
Series []datadogV1.Series `json:"series"` | ||
} | ||
|
||
func (mt *MetricsTranslator) translateMetricsV1(series SeriesList) pmetric.Metrics { | ||
func (mt *MetricsTranslator) TranslateSeriesV1(series SeriesList) pmetric.Metrics { | ||
bt := newBatcher() | ||
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. Over time the same batchers will be created again and again. This is not for this PR but I wonder if an improvement for the receiver would be to have a pool of the maps we've seen in the past and reuse them instead of reallocating them on every request handling. |
||
|
||
for _, serie := range series.Series { | ||
|
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
2 changes: 1 addition & 1 deletion
2
receiver/datadogreceiver/tags.go → ...tadogreceiver/internal/translator/tags.go
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
2 changes: 1 addition & 1 deletion
2
receiver/datadogreceiver/tags_test.go → ...receiver/internal/translator/tags_test.go
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
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
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
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.
I think both Batcher and DImensions could be unexported.