-
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
Add container tags #31642
Merged
dmitryax
merged 15 commits into
open-telemetry:main
from
dineshg13:dinesh.gurumurthy/add-container-stats
Mar 20, 2024
Merged
Add container tags #31642
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fd276c1
Add container tags
dineshg13 ddf6b68
use cache
dineshg13 f676454
fix dups
dineshg13 1ffa692
fix dups
dineshg13 e471439
Merge remote-tracking branch 'origin/main' into dinesh.gurumurthy/add…
dineshg13 d564a21
Merge remote-tracking branch 'origin/main' into dinesh.gurumurthy/add…
dineshg13 0a513fc
add test for connector
dineshg13 060ea77
add changelog
dineshg13 2458021
add unique test
dineshg13 b9773ee
fix lint errors
dineshg13 24716cd
fix api
dineshg13 3499beb
PR feedback
dineshg13 8d1409a
merge main
dineshg13 5b18d82
PR feedback
dineshg13 8966fd3
Merge branch 'main' into dinesh.gurumurthy/add-container-stats
dineshg13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
semconv "go.opentelemetry.io/collector/semconv/v1.17.0" | ||
"go.opentelemetry.io/otel/metric/noop" | ||
"go.uber.org/zap" | ||
|
||
|
@@ -36,6 +37,10 @@ type traceToMetricConnector struct { | |
// from the agent to OTLP Metrics. | ||
translator *metrics.Translator | ||
|
||
enableContainerStats bool | ||
containerTagAttrs map[string]string | ||
containerTagCache map[string][]string | ||
|
||
// in specifies the channel through which the agent will output Stats Payloads | ||
// resulting from ingested traces. | ||
in chan *pb.StatsPayload | ||
|
@@ -60,14 +65,23 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co | |
return nil, fmt.Errorf("failed to create metrics translator: %w", err) | ||
} | ||
|
||
ctags := make(map[string]string, len(cfg.(*Config).Traces.ContainerTagAttributes)) | ||
for _, val := range cfg.(*Config).Traces.ContainerTagAttributes { | ||
ctags[val] = "" | ||
} | ||
ddtags := attributes.ContainerTagFromAttributes(ctags) | ||
|
||
ctx := context.Background() | ||
return &traceToMetricConnector{ | ||
logger: set.Logger, | ||
agent: datadog.NewAgentWithConfig(ctx, getTraceAgentCfg(cfg.(*Config).Traces, attributesTranslator), in, metricsClient, timingReporter), | ||
translator: trans, | ||
in: in, | ||
metricsConsumer: metricsConsumer, | ||
exit: make(chan struct{}), | ||
logger: set.Logger, | ||
agent: datadog.NewAgentWithConfig(ctx, getTraceAgentCfg(cfg.(*Config).Traces, attributesTranslator), in, metricsClient, timingReporter), | ||
translator: trans, | ||
in: in, | ||
metricsConsumer: metricsConsumer, | ||
enableContainerStats: cfg.(*Config).Traces.EnableContainerStats, | ||
containerTagAttrs: ddtags, | ||
containerTagCache: make(map[string][]string), | ||
exit: make(chan struct{}), | ||
}, nil | ||
} | ||
|
||
|
@@ -80,6 +94,9 @@ func getTraceAgentCfg(cfg TracesConfig, attributesTranslator *attributes.Transla | |
acfg.ComputeStatsBySpanKind = cfg.ComputeStatsBySpanKind | ||
acfg.PeerTagsAggregation = cfg.PeerTagsAggregation | ||
acfg.PeerTags = cfg.PeerTags | ||
if cfg.EnableContainerStats { | ||
acfg.Features["enable_cid_stats"] = struct{}{} | ||
songy23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if v := cfg.TraceBuffer; v > 0 { | ||
acfg.TraceBuffer = v | ||
} | ||
|
@@ -113,6 +130,23 @@ func (c *traceToMetricConnector) Capabilities() consumer.Capabilities { | |
|
||
func (c *traceToMetricConnector) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error { | ||
c.agent.Ingest(ctx, traces) | ||
if c.enableContainerStats && len(c.containerTagAttrs) > 0 { | ||
dineshg13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i := 0; i < traces.ResourceSpans().Len(); i++ { | ||
rs := traces.ResourceSpans().At(i) | ||
attrs := rs.Resource().Attributes() | ||
containerID, ok := attrs.Get(semconv.AttributeContainerID) | ||
if !ok { | ||
continue | ||
} | ||
ddContainerTags := attributes.ContainerTagsFromResourceAttributes(attrs) | ||
for attr := range c.containerTagAttrs { | ||
if val, ok := ddContainerTags[attr]; ok { | ||
c.containerTagCache[containerID.AsString()] = append(c.containerTagCache[containerID.AsString()], val) | ||
} | ||
} | ||
|
||
} | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -128,7 +162,19 @@ func (c *traceToMetricConnector) run() { | |
} | ||
var mx pmetric.Metrics | ||
var err error | ||
// Enrich the stats with container tags | ||
dineshg13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if c.enableContainerStats && len(c.containerTagCache) > 0 { | ||
for _, stat := range stats.Stats { | ||
if stat.ContainerID != "" { | ||
if tags, ok := c.containerTagCache[stat.ContainerID]; ok { | ||
stat.Tags = append(stat.Tags, tags...) | ||
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. 👍 |
||
} | ||
} | ||
} | ||
} | ||
|
||
c.logger.Debug("Received stats payload", zap.Any("stats", stats)) | ||
|
||
mx, err = c.translator.StatsToMetrics(stats) | ||
if err != nil { | ||
c.logger.Error("Failed to convert stats to metrics", zap.Error(err)) | ||
|
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.
👍