Skip to content

Commit

Permalink
cache resource instead of resourcemetrics
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Silva Sens <[email protected]>
  • Loading branch information
ArthurSens committed Dec 10, 2024
1 parent 138f143 commit 0f5a554
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions receiver/prometheusremotewritereceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newRemoteWriteReceiver(settings receiver.Settings, cfg *Config, nextConsume
settings: settings,
nextConsumer: nextConsumer,
config: cfg,
jobInstanceCache: make(map[uint64]pmetric.ResourceMetrics),
jobInstanceCache: make(map[uint64]pcommon.Resource),
server: &http.Server{
ReadTimeout: 60 * time.Second,
},
Expand All @@ -43,7 +43,7 @@ type prometheusRemoteWriteReceiver struct {
settings receiver.Settings
nextConsumer consumer.Metrics

jobInstanceCache map[uint64]pmetric.ResourceMetrics
jobInstanceCache map[uint64]pcommon.Resource
config *Config
server *http.Server
}
Expand Down Expand Up @@ -182,14 +182,15 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
cacheEntry, ok := prw.jobInstanceCache[hashedJobAndInstance]
if ok {
rm = pmetric.NewResourceMetrics()
cacheEntry.CopyTo(rm)
cacheEntry.CopyTo(rm.Resource())
} else {
// A remote-write request can have multiple timeseries with the same instance and job labels.
// While they are different timeseries in Prometheus, we're handling it as the same OTLP metric
// until we support 'target_info'.
// TODO: Use 'target_info' to populate the resource attributes instead of caching job and instance.
rm = otelMetrics.ResourceMetrics().AppendEmpty()
parseJobAndInstance(rm.Resource().Attributes(), ls.Get("job"), ls.Get("instance"))
prw.jobInstanceCache[hashedJobAndInstance] = rm
prw.jobInstanceCache[hashedJobAndInstance] = rm.Resource()
}

switch ts.Metadata.Type {
Expand Down

0 comments on commit 0f5a554

Please sign in to comment.