From d68e9f5fb0622da6971994d308249886276e211b Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 12 May 2022 18:00:46 -0700 Subject: [PATCH] [Metrics builder] Add ability to override start time per resource Some scrapers require setting different start time per resource. Currently metrics builder maintains one start time per builder. This change adds an option to override start time when calling `EmitForResource` --- cmd/mdatagen/metrics_v2.tmpl | 45 ++++++--- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 45 ++++++--- .../internal/metadata/generated_metrics_v2.go | 51 +++++++--- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 75 +++++++++------ .../scraper/processscraper/process.go | 4 +- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 93 ++++++++++++------- .../internal/metadata/generated_metrics_v2.go | 45 ++++++--- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 57 ++++++++---- .../internal/metadata/generated_metrics_v2.go | 39 ++++++-- .../internal/metadata/generated_metrics_v2.go | 45 ++++++--- .../internal/metadata/generated_metrics_v2.go | 51 +++++++--- receiver/saphanareceiver/scraper.go | 2 +- .../internal/metadata/generated_metrics_v2.go | 45 ++++++--- .../internal/metadata/generated_metrics_v2.go | 51 +++++++--- receiver/zookeeperreceiver/scraper.go | 2 +- 31 files changed, 931 insertions(+), 343 deletions(-) diff --git a/cmd/mdatagen/metrics_v2.tmpl b/cmd/mdatagen/metrics_v2.tmpl index f7f0706dfe99..8b49d30d6b65 100644 --- a/cmd/mdatagen/metrics_v2.tmpl +++ b/cmd/mdatagen/metrics_v2.tmpl @@ -185,37 +185,58 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) {{- range $name, $attr := .ResourceAttributes }} // With{{ $name.Render }} sets provided value as "{{ $name }}" attribute for current resource. -func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().Upsert{{ $attr.Type }}("{{ $name }}", val) +func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().Upsert{{ $attr.Type }}("{{ $name }}", val) } } {{ end }} +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} + // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() {{- if .SemConvVersion }} rm.SetSchemaUrl(conventions.SchemaURL) {{- end }} rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/{{ .Name }}") ils.Metrics().EnsureCapacity(mb.metricsCapacity) {{- range $name, $metric := .Metrics }} mb.metric{{- $name.Render }}.emit(ils.Metrics()) {{- end }} + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -225,8 +246,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/activedirectorydsreceiver/internal/metadata/generated_metrics_v2.go b/receiver/activedirectorydsreceiver/internal/metadata/generated_metrics_v2.go index 3710ca8393f3..540d0486c930 100644 --- a/receiver/activedirectorydsreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/activedirectorydsreceiver/internal/metadata/generated_metrics_v2.go @@ -1293,19 +1293,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/activedirectorydsreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -1327,6 +1345,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricActiveDirectoryDsSecurityDescriptorPropagationsEventQueued.emit(ils.Metrics()) mb.metricActiveDirectoryDsSuboperationRate.emit(ils.Metrics()) mb.metricActiveDirectoryDsThreadCount.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -1336,8 +1357,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/apachereceiver/internal/metadata/generated_metrics_v2.go b/receiver/apachereceiver/internal/metadata/generated_metrics_v2.go index d719f2629292..36226ff22334 100644 --- a/receiver/apachereceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/apachereceiver/internal/metadata/generated_metrics_v2.go @@ -513,19 +513,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/apachereceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -535,6 +553,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricApacheTraffic.emit(ils.Metrics()) mb.metricApacheUptime.emit(ils.Metrics()) mb.metricApacheWorkers.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -544,8 +565,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/couchbasereceiver/internal/metadata/generated_metrics_v2.go b/receiver/couchbasereceiver/internal/metadata/generated_metrics_v2.go index 7614ce5a6b1f..e1cad270c7d0 100644 --- a/receiver/couchbasereceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/couchbasereceiver/internal/metadata/generated_metrics_v2.go @@ -62,22 +62,43 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/couchbasereceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -87,8 +108,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/couchdbreceiver/internal/metadata/generated_metrics_v2.go b/receiver/couchdbreceiver/internal/metadata/generated_metrics_v2.go index d537c2f70dc3..e82d561feebf 100644 --- a/receiver/couchdbreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/couchdbreceiver/internal/metadata/generated_metrics_v2.go @@ -623,26 +623,44 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithCouchdbNodeName sets provided value as "couchdb.node.name" attribute for current resource. -func WithCouchdbNodeName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("couchdb.node.name", val) +func WithCouchdbNodeName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("couchdb.node.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/couchdbreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -654,6 +672,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricCouchdbHttpdRequests.emit(ils.Metrics()) mb.metricCouchdbHttpdResponses.emit(ils.Metrics()) mb.metricCouchdbHttpdViews.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -663,8 +684,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/elasticsearchreceiver/internal/metadata/generated_metrics_v2.go b/receiver/elasticsearchreceiver/internal/metadata/generated_metrics_v2.go index 468fa456e3e6..b0eef09f0d59 100644 --- a/receiver/elasticsearchreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/elasticsearchreceiver/internal/metadata/generated_metrics_v2.go @@ -2038,33 +2038,51 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithElasticsearchClusterName sets provided value as "elasticsearch.cluster.name" attribute for current resource. -func WithElasticsearchClusterName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("elasticsearch.cluster.name", val) +func WithElasticsearchClusterName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("elasticsearch.cluster.name", val) } } // WithElasticsearchNodeName sets provided value as "elasticsearch.node.name" attribute for current resource. -func WithElasticsearchNodeName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("elasticsearch.node.name", val) +func WithElasticsearchNodeName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("elasticsearch.node.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/elasticsearchreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -2097,6 +2115,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricJvmMemoryPoolMax.emit(ils.Metrics()) mb.metricJvmMemoryPoolUsed.emit(ils.Metrics()) mb.metricJvmThreadsCount.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -2106,8 +2127,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata/generated_metrics_v2.go index dce24cc4117a..b4fd4cebd427 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata/generated_metrics_v2.go @@ -232,25 +232,46 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/cpu") ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemCPUTime.emit(ils.Metrics()) mb.metricSystemCPUUtilization.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -260,8 +281,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata/generated_metrics_v2.go index 357ca9f110dd..ef5a5e22f12b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata/generated_metrics_v2.go @@ -507,20 +507,38 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/disk") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -531,6 +549,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricSystemDiskOperations.emit(ils.Metrics()) mb.metricSystemDiskPendingOperations.emit(ils.Metrics()) mb.metricSystemDiskWeightedIoTime.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -540,8 +561,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_v2.go index 83e08a3c1acb..9c44b5fc3111 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata/generated_metrics_v2.go @@ -280,26 +280,47 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/filesystem") ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemFilesystemInodesUsage.emit(ils.Metrics()) mb.metricSystemFilesystemUsage.emit(ils.Metrics()) mb.metricSystemFilesystemUtilization.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -309,8 +330,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata/generated_metrics_v2.go index 5025a83611cf..e3a153167d0a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata/generated_metrics_v2.go @@ -229,26 +229,47 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/load") ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemCPULoadAverage15m.emit(ils.Metrics()) mb.metricSystemCPULoadAverage1m.emit(ils.Metrics()) mb.metricSystemCPULoadAverage5m.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -258,8 +279,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics_v2.go index 62d6da9f9bc7..80005cb05f0a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics_v2.go @@ -226,25 +226,46 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/memory") ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemMemoryUsage.emit(ils.Metrics()) mb.metricSystemMemoryUtilization.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -254,8 +275,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go index 5841f9688d7c..11a9de7e040f 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata/generated_metrics_v2.go @@ -412,20 +412,38 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/network") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -434,6 +452,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricSystemNetworkErrors.emit(ils.Metrics()) mb.metricSystemNetworkIo.emit(ils.Metrics()) mb.metricSystemNetworkPackets.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -443,8 +464,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata/generated_metrics_v2.go index 7a3c3c14e322..743f855f2a2b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata/generated_metrics_v2.go @@ -383,20 +383,38 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/paging") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -404,6 +422,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricSystemPagingOperations.emit(ils.Metrics()) mb.metricSystemPagingUsage.emit(ils.Metrics()) mb.metricSystemPagingUtilization.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -413,8 +434,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata/generated_metrics_v2.go index 1d6224aa0d07..d93a55bf9230 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata/generated_metrics_v2.go @@ -250,25 +250,46 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/processes") ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemProcessesCount.emit(ils.Metrics()) mb.metricSystemProcessesCreated.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -278,8 +299,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata/generated_metrics_v2.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata/generated_metrics_v2.go index a88451639d9c..5c4da09d853a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata/generated_metrics_v2.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata/generated_metrics_v2.go @@ -352,62 +352,80 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithProcessCommand sets provided value as "process.command" attribute for current resource. -func WithProcessCommand(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("process.command", val) +func WithProcessCommand(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("process.command", val) } } // WithProcessCommandLine sets provided value as "process.command_line" attribute for current resource. -func WithProcessCommandLine(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("process.command_line", val) +func WithProcessCommandLine(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("process.command_line", val) } } // WithProcessExecutableName sets provided value as "process.executable.name" attribute for current resource. -func WithProcessExecutableName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("process.executable.name", val) +func WithProcessExecutableName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("process.executable.name", val) } } // WithProcessExecutablePath sets provided value as "process.executable.path" attribute for current resource. -func WithProcessExecutablePath(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("process.executable.path", val) +func WithProcessExecutablePath(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("process.executable.path", val) } } // WithProcessOwner sets provided value as "process.owner" attribute for current resource. -func WithProcessOwner(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("process.owner", val) +func WithProcessOwner(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("process.owner", val) } } // WithProcessPid sets provided value as "process.pid" attribute for current resource. -func WithProcessPid(val int64) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertInt("process.pid", val) +func WithProcessPid(val int64) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertInt("process.pid", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/hostmetricsreceiver/process") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -415,6 +433,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricProcessDiskIo.emit(ils.Metrics()) mb.metricProcessMemoryPhysicalUsage.emit(ils.Metrics()) mb.metricProcessMemoryVirtualUsage.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -424,8 +445,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go index 4c705e8ad5c0..6afd59d717b6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process.go @@ -46,8 +46,8 @@ type commandMetadata struct { commandLineSlice []string } -func (m *processMetadata) resourceOptions() []metadata.ResourceOption { - opts := make([]metadata.ResourceOption, 0, 6) +func (m *processMetadata) resourceOptions() []metadata.ResourceMetricsOption { + opts := make([]metadata.ResourceMetricsOption, 0, 6) opts = append(opts, metadata.WithProcessPid(int64(m.pid)), metadata.WithProcessExecutableName(m.executable.name), diff --git a/receiver/iisreceiver/internal/metadata/generated_metrics_v2.go b/receiver/iisreceiver/internal/metadata/generated_metrics_v2.go index 298735eb1b45..258aa2f5b273 100644 --- a/receiver/iisreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/iisreceiver/internal/metadata/generated_metrics_v2.go @@ -821,19 +821,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/iisreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -849,6 +867,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricIisRequestRejected.emit(ils.Metrics()) mb.metricIisThreadActive.emit(ils.Metrics()) mb.metricIisUptime.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -858,8 +879,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/memcachedreceiver/internal/metadata/generated_metrics_v2.go b/receiver/memcachedreceiver/internal/metadata/generated_metrics_v2.go index 5beab606adc1..8f1f58ccb9ff 100644 --- a/receiver/memcachedreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/memcachedreceiver/internal/metadata/generated_metrics_v2.go @@ -839,19 +839,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/memcachedreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -866,6 +884,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricMemcachedOperationHitRatio.emit(ils.Metrics()) mb.metricMemcachedOperations.emit(ils.Metrics()) mb.metricMemcachedThreads.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -875,8 +896,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_v2.go b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_v2.go index 019a9aa5e628..1f7286268949 100644 --- a/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/mongodbatlasreceiver/internal/metadata/generated_metrics_v2.go @@ -4365,82 +4365,100 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithMongodbAtlasDbName sets provided value as "mongodb_atlas.db.name" attribute for current resource. -func WithMongodbAtlasDbName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.db.name", val) +func WithMongodbAtlasDbName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.db.name", val) } } // WithMongodbAtlasDiskPartition sets provided value as "mongodb_atlas.disk.partition" attribute for current resource. -func WithMongodbAtlasDiskPartition(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.disk.partition", val) +func WithMongodbAtlasDiskPartition(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.disk.partition", val) } } // WithMongodbAtlasHostName sets provided value as "mongodb_atlas.host.name" attribute for current resource. -func WithMongodbAtlasHostName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.host.name", val) +func WithMongodbAtlasHostName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.host.name", val) } } // WithMongodbAtlasOrgName sets provided value as "mongodb_atlas.org_name" attribute for current resource. -func WithMongodbAtlasOrgName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.org_name", val) +func WithMongodbAtlasOrgName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.org_name", val) } } // WithMongodbAtlasProcessID sets provided value as "mongodb_atlas.process.id" attribute for current resource. -func WithMongodbAtlasProcessID(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.process.id", val) +func WithMongodbAtlasProcessID(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.process.id", val) } } // WithMongodbAtlasProcessPort sets provided value as "mongodb_atlas.process.port" attribute for current resource. -func WithMongodbAtlasProcessPort(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.process.port", val) +func WithMongodbAtlasProcessPort(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.process.port", val) } } // WithMongodbAtlasProcessTypeName sets provided value as "mongodb_atlas.process.type_name" attribute for current resource. -func WithMongodbAtlasProcessTypeName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.process.type_name", val) +func WithMongodbAtlasProcessTypeName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.process.type_name", val) } } // WithMongodbAtlasProjectID sets provided value as "mongodb_atlas.project.id" attribute for current resource. -func WithMongodbAtlasProjectID(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.project.id", val) +func WithMongodbAtlasProjectID(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.project.id", val) } } // WithMongodbAtlasProjectName sets provided value as "mongodb_atlas.project.name" attribute for current resource. -func WithMongodbAtlasProjectName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("mongodb_atlas.project.name", val) +func WithMongodbAtlasProjectName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("mongodb_atlas.project.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/mongoatlasreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -4507,6 +4525,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricMongodbatlasSystemPagingIoMax.emit(ils.Metrics()) mb.metricMongodbatlasSystemPagingUsageAverage.emit(ils.Metrics()) mb.metricMongodbatlasSystemPagingUsageMax.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -4516,8 +4537,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/mongodbreceiver/internal/metadata/generated_metrics_v2.go b/receiver/mongodbreceiver/internal/metadata/generated_metrics_v2.go index 455e3b191ecb..054354e9c0c5 100644 --- a/receiver/mongodbreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/mongodbreceiver/internal/metadata/generated_metrics_v2.go @@ -895,26 +895,44 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithDatabase sets provided value as "database" attribute for current resource. -func WithDatabase(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("database", val) +func WithDatabase(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("database", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/mongodbreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -930,6 +948,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricMongodbObjectCount.emit(ils.Metrics()) mb.metricMongodbOperationCount.emit(ils.Metrics()) mb.metricMongodbStorageSize.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -939,8 +960,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/mysqlreceiver/internal/metadata/generated_metrics_v2.go b/receiver/mysqlreceiver/internal/metadata/generated_metrics_v2.go index d92223590810..7dc239e7de45 100644 --- a/receiver/mysqlreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/mysqlreceiver/internal/metadata/generated_metrics_v2.go @@ -1568,19 +1568,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/mysqlreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -1601,6 +1619,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricMysqlRowOperations.emit(ils.Metrics()) mb.metricMysqlSorts.emit(ils.Metrics()) mb.metricMysqlThreads.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -1610,8 +1631,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/nginxreceiver/internal/metadata/generated_metrics_v2.go b/receiver/nginxreceiver/internal/metadata/generated_metrics_v2.go index e3f3ccd81b80..b928532e85f9 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/nginxreceiver/internal/metadata/generated_metrics_v2.go @@ -325,19 +325,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/nginxreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -345,6 +363,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricNginxConnectionsCurrent.emit(ils.Metrics()) mb.metricNginxConnectionsHandled.emit(ils.Metrics()) mb.metricNginxRequests.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -354,8 +375,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go b/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go index f4f14ba4234c..18ea57b07451 100644 --- a/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go @@ -592,19 +592,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/postgresqlreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -615,6 +633,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricPostgresqlOperations.emit(ils.Metrics()) mb.metricPostgresqlRollbacks.emit(ils.Metrics()) mb.metricPostgresqlRows.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -624,8 +645,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/rabbitmqreceiver/internal/metadata/generated_metrics_v2.go b/receiver/rabbitmqreceiver/internal/metadata/generated_metrics_v2.go index 2092569553d3..72c0a6265206 100644 --- a/receiver/rabbitmqreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/rabbitmqreceiver/internal/metadata/generated_metrics_v2.go @@ -433,40 +433,58 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithRabbitmqNodeName sets provided value as "rabbitmq.node.name" attribute for current resource. -func WithRabbitmqNodeName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("rabbitmq.node.name", val) +func WithRabbitmqNodeName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("rabbitmq.node.name", val) } } // WithRabbitmqQueueName sets provided value as "rabbitmq.queue.name" attribute for current resource. -func WithRabbitmqQueueName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("rabbitmq.queue.name", val) +func WithRabbitmqQueueName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("rabbitmq.queue.name", val) } } // WithRabbitmqVhostName sets provided value as "rabbitmq.vhost.name" attribute for current resource. -func WithRabbitmqVhostName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("rabbitmq.vhost.name", val) +func WithRabbitmqVhostName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("rabbitmq.vhost.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/rabbitmqreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -476,6 +494,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricRabbitmqMessageDelivered.emit(ils.Metrics()) mb.metricRabbitmqMessageDropped.emit(ils.Metrics()) mb.metricRabbitmqMessagePublished.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -485,8 +506,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/redisreceiver/internal/metadata/generated_metrics_v2.go b/receiver/redisreceiver/internal/metadata/generated_metrics_v2.go index 59602961d028..ee8c1428a731 100644 --- a/receiver/redisreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/redisreceiver/internal/metadata/generated_metrics_v2.go @@ -1696,19 +1696,37 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } + } +} // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/redisreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -1741,6 +1759,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricRedisReplicationOffset.emit(ils.Metrics()) mb.metricRedisSlavesConnected.emit(ils.Metrics()) mb.metricRedisUptime.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -1750,8 +1771,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/riakreceiver/internal/metadata/generated_metrics_v2.go b/receiver/riakreceiver/internal/metadata/generated_metrics_v2.go index 47ca70a063d8..58f1ab267214 100644 --- a/receiver/riakreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/riakreceiver/internal/metadata/generated_metrics_v2.go @@ -467,26 +467,44 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithRiakNodeName sets provided value as "riak.node.name" attribute for current resource. -func WithRiakNodeName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("riak.node.name", val) +func WithRiakNodeName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("riak.node.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/riakreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -496,6 +514,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricRiakNodeReadRepairCount.emit(ils.Metrics()) mb.metricRiakVnodeIndexOperationCount.emit(ils.Metrics()) mb.metricRiakVnodeOperationCount.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -505,8 +526,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/saphanareceiver/internal/metadata/generated_metrics_v2.go b/receiver/saphanareceiver/internal/metadata/generated_metrics_v2.go index 0e4b13885d67..71d873940e8a 100644 --- a/receiver/saphanareceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/saphanareceiver/internal/metadata/generated_metrics_v2.go @@ -3240,33 +3240,51 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithDbSystem sets provided value as "db.system" attribute for current resource. -func WithDbSystem(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("db.system", val) +func WithDbSystem(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("db.system", val) } } // WithSaphanaHost sets provided value as "saphana.host" attribute for current resource. -func WithSaphanaHost(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("saphana.host", val) +func WithSaphanaHost(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("saphana.host", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/saphanareceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -3315,6 +3333,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricSaphanaVolumeOperationCount.emit(ils.Metrics()) mb.metricSaphanaVolumeOperationSize.emit(ils.Metrics()) mb.metricSaphanaVolumeOperationTime.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -3324,8 +3345,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/saphanareceiver/scraper.go b/receiver/saphanareceiver/scraper.go index e62bd9efdc74..b408985aef2f 100644 --- a/receiver/saphanareceiver/scraper.go +++ b/receiver/saphanareceiver/scraper.go @@ -91,7 +91,7 @@ func (s *sapHanaScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { errs.Add(fmt.Errorf("Error unmarshaling resource attributes for saphana scraper: %w", err)) continue } - resourceOptions := []metadata.ResourceOption{metadata.WithDbSystem("saphana")} + resourceOptions := []metadata.ResourceMetricsOption{metadata.WithDbSystem("saphana")} for attribute, value := range resourceAttributes { if attribute == "host" { resourceOptions = append(resourceOptions, metadata.WithSaphanaHost(value)) diff --git a/receiver/sqlserverreceiver/internal/metadata/generated_metrics_v2.go b/receiver/sqlserverreceiver/internal/metadata/generated_metrics_v2.go index 0b76192456ae..616eb96e14f9 100644 --- a/receiver/sqlserverreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/sqlserverreceiver/internal/metadata/generated_metrics_v2.go @@ -1195,26 +1195,44 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithSqlserverDatabaseName sets provided value as "sqlserver.database.name" attribute for current resource. -func WithSqlserverDatabaseName(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("sqlserver.database.name", val) +func WithSqlserverDatabaseName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("sqlserver.database.name", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/sqlserverreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -1238,6 +1256,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricSqlserverTransactionLogShrinkCount.emit(ils.Metrics()) mb.metricSqlserverTransactionLogUsage.emit(ils.Metrics()) mb.metricSqlserverUserConnectionCount.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -1247,8 +1268,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/zookeeperreceiver/internal/metadata/generated_metrics_v2.go b/receiver/zookeeperreceiver/internal/metadata/generated_metrics_v2.go index 9a2dda6f00fd..7c2e955f169c 100644 --- a/receiver/zookeeperreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/zookeeperreceiver/internal/metadata/generated_metrics_v2.go @@ -966,33 +966,51 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { } } -// ResourceOption applies changes to provided resource. -type ResourceOption func(pcommon.Resource) +// ResourceMetricsOption applies changes to provided resource metrics. +type ResourceMetricsOption func(pmetric.ResourceMetrics) // WithServerState sets provided value as "server.state" attribute for current resource. -func WithServerState(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("server.state", val) +func WithServerState(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("server.state", val) } } // WithZkVersion sets provided value as "zk.version" attribute for current resource. -func WithZkVersion(val string) ResourceOption { - return func(r pcommon.Resource) { - r.Attributes().UpsertString("zk.version", val) +func WithZkVersion(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("zk.version", val) + } +} + +// WithStartTimeOverride overrides start time for all the resource metrics data points. +// This option should be only used if different start time has to be set on metrics coming from different resources. +func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + metrics := rm.ScopeMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + dps := pmetric.NewNumberDataPointSlice() + switch metrics.At(i).DataType() { + case pmetric.MetricDataTypeGauge: + dps = metrics.At(i).Gauge().DataPoints() + case pmetric.MetricDataTypeSum: + dps = metrics.At(i).Sum().DataPoints() + } + for j := 0; j < dps.Len(); j++ { + dps.At(j).SetStartTimestamp(start) + } + } } } // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for // recording another set of data points as part of another resource. This function can be helpful when one scraper // needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. Resource attributes should be provided as ResourceOption arguments. -func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { +// just `Emit` function can be called instead. +// Resource attributes should be provided as ResourceMetricsOption arguments. +func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().EnsureCapacity(mb.resourceCapacity) - for _, op := range ro { - op(rm.Resource()) - } ils := rm.ScopeMetrics().AppendEmpty() ils.Scope().SetName("otelcol/zookeeperreceiver") ils.Metrics().EnsureCapacity(mb.metricsCapacity) @@ -1011,6 +1029,9 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { mb.metricZookeeperSyncPending.emit(ils.Metrics()) mb.metricZookeeperWatchCount.emit(ils.Metrics()) mb.metricZookeeperZnodeCount.emit(ils.Metrics()) + for _, op := range rmo { + op(rm) + } if ils.Metrics().Len() > 0 { mb.updateCapacity(rm) rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) @@ -1020,8 +1041,8 @@ func (mb *MetricsBuilder) EmitForResource(ro ...ResourceOption) { // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for // recording another set of metrics. This function will be responsible for applying all the transformations required to // produce metric representation defined in metadata and user settings, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(ro ...ResourceOption) pmetric.Metrics { - mb.EmitForResource(ro...) +func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { + mb.EmitForResource(rmo...) metrics := pmetric.NewMetrics() mb.metricsBuffer.MoveTo(metrics) return metrics diff --git a/receiver/zookeeperreceiver/scraper.go b/receiver/zookeeperreceiver/scraper.go index 4c40462637b7..38bd6da9c0bb 100644 --- a/receiver/zookeeperreceiver/scraper.go +++ b/receiver/zookeeperreceiver/scraper.go @@ -121,7 +121,7 @@ func (z *zookeeperMetricsScraper) getResourceMetrics(conn net.Conn) (pmetric.Met creator := newMetricCreator(z.mb) now := pcommon.NewTimestampFromTime(time.Now()) - resourceOpts := make([]metadata.ResourceOption, 0, 2) + resourceOpts := make([]metadata.ResourceMetricsOption, 0, 2) for scanner.Scan() { line := scanner.Text() parts := zookeeperFormatRE.FindStringSubmatch(line)