diff --git a/receiver/nginxreceiver/documentation.md b/receiver/nginxreceiver/documentation.md index 8ca02722b47b..b83659e28c6a 100644 --- a/receiver/nginxreceiver/documentation.md +++ b/receiver/nginxreceiver/documentation.md @@ -114,9 +114,9 @@ The number of responses with 1xx status code. The number of responses with 2xx status code. -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| response | Gauge | Int | +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| response | Sum | Int | Cumulative | true | #### Attributes @@ -142,9 +142,9 @@ The number of responses with 3xx status code. The number of responses with 4xx status code. -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| response | Gauge | Int | +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| response | Sum | Int | Cumulative | true | #### Attributes @@ -156,9 +156,9 @@ The number of responses with 4xx status code. The number of responses with 5xx status code. -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| response | Gauge | Int | +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| response | Sum | Int | Cumulative | true | #### Attributes diff --git a/receiver/nginxreceiver/internal/metadata/generated_metrics.go b/receiver/nginxreceiver/internal/metadata/generated_metrics.go index 2d3e96dfeb2d..ac5db99530bf 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_metrics.go +++ b/receiver/nginxreceiver/internal/metadata/generated_metrics.go @@ -562,15 +562,17 @@ func (m *metricNginxServerZoneResponses2xx) init() { m.data.SetName("nginx.server_zone.responses.2xx") m.data.SetDescription("The number of responses with 2xx status code.") m.data.SetUnit("response") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } func (m *metricNginxServerZoneResponses2xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverzoneNameAttributeValue string) { if !m.config.Enabled { return } - dp := m.data.Gauge().DataPoints().AppendEmpty() + dp := m.data.Sum().DataPoints().AppendEmpty() dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) @@ -579,14 +581,14 @@ func (m *metricNginxServerZoneResponses2xx) recordDataPoint(start pcommon.Timest // updateCapacity saves max length of data point slices that will be used for the slice capacity. func (m *metricNginxServerZoneResponses2xx) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. func (m *metricNginxServerZoneResponses2xx) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) m.init() @@ -664,15 +666,17 @@ func (m *metricNginxServerZoneResponses4xx) init() { m.data.SetName("nginx.server_zone.responses.4xx") m.data.SetDescription("The number of responses with 4xx status code.") m.data.SetUnit("response") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } func (m *metricNginxServerZoneResponses4xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverzoneNameAttributeValue string) { if !m.config.Enabled { return } - dp := m.data.Gauge().DataPoints().AppendEmpty() + dp := m.data.Sum().DataPoints().AppendEmpty() dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) @@ -681,14 +685,14 @@ func (m *metricNginxServerZoneResponses4xx) recordDataPoint(start pcommon.Timest // updateCapacity saves max length of data point slices that will be used for the slice capacity. func (m *metricNginxServerZoneResponses4xx) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. func (m *metricNginxServerZoneResponses4xx) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) m.init() @@ -715,15 +719,17 @@ func (m *metricNginxServerZoneResponses5xx) init() { m.data.SetName("nginx.server_zone.responses.5xx") m.data.SetDescription("The number of responses with 5xx status code.") m.data.SetUnit("response") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) } func (m *metricNginxServerZoneResponses5xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverzoneNameAttributeValue string) { if !m.config.Enabled { return } - dp := m.data.Gauge().DataPoints().AppendEmpty() + dp := m.data.Sum().DataPoints().AppendEmpty() dp.SetStartTimestamp(start) dp.SetTimestamp(ts) dp.SetIntValue(val) @@ -732,14 +738,14 @@ func (m *metricNginxServerZoneResponses5xx) recordDataPoint(start pcommon.Timest // updateCapacity saves max length of data point slices that will be used for the slice capacity. func (m *metricNginxServerZoneResponses5xx) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() } } // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. func (m *metricNginxServerZoneResponses5xx) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) m.init() diff --git a/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go b/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go index b61298a0b9c4..566e34284e21 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go @@ -331,11 +331,13 @@ func TestMetricsBuilder(t *testing.T) { case "nginx.server_zone.responses.2xx": assert.False(t, validatedMetrics["nginx.server_zone.responses.2xx"], "Found a duplicate in the metrics slice: nginx.server_zone.responses.2xx") validatedMetrics["nginx.server_zone.responses.2xx"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "The number of responses with 2xx status code.", ms.At(i).Description()) assert.Equal(t, "response", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) @@ -361,11 +363,13 @@ func TestMetricsBuilder(t *testing.T) { case "nginx.server_zone.responses.4xx": assert.False(t, validatedMetrics["nginx.server_zone.responses.4xx"], "Found a duplicate in the metrics slice: nginx.server_zone.responses.4xx") validatedMetrics["nginx.server_zone.responses.4xx"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "The number of responses with 4xx status code.", ms.At(i).Description()) assert.Equal(t, "response", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) @@ -376,11 +380,13 @@ func TestMetricsBuilder(t *testing.T) { case "nginx.server_zone.responses.5xx": assert.False(t, validatedMetrics["nginx.server_zone.responses.5xx"], "Found a duplicate in the metrics slice: nginx.server_zone.responses.5xx") validatedMetrics["nginx.server_zone.responses.5xx"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) assert.Equal(t, "The number of responses with 5xx status code.", ms.At(i).Description()) assert.Equal(t, "response", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) assert.Equal(t, start, dp.StartTimestamp()) assert.Equal(t, ts, dp.Timestamp()) assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) diff --git a/receiver/nginxreceiver/metadata.yaml b/receiver/nginxreceiver/metadata.yaml index b51f5f2899d2..492e3a0a5a35 100644 --- a/receiver/nginxreceiver/metadata.yaml +++ b/receiver/nginxreceiver/metadata.yaml @@ -37,7 +37,7 @@ metrics: value_type: int monotonic: true aggregation_temporality: cumulative - attributes: [] + attributes: [] nginx.connections_accepted: enabled: true description: The total number of accepted client connections @@ -120,11 +120,12 @@ metrics: attributes: - serverzone_name description: The number of responses with 2xx status code. - gauge: + sum: value_type: int + monotonic: true + aggregation_temporality: cumulative unit: response - nginx.server_zone.responses.3xx: enabled: true attributes: @@ -140,21 +141,23 @@ metrics: attributes: - serverzone_name description: The number of responses with 4xx status code. - gauge: + sum: value_type: int + monotonic: true + aggregation_temporality: cumulative unit: response - nginx.server_zone.responses.5xx: enabled: true attributes: - serverzone_name description: The number of responses with 5xx status code. - gauge: + sum: value_type: int + monotonic: true + aggregation_temporality: cumulative unit: response - nginx.server_zone.received: enabled: true attributes: @@ -165,7 +168,6 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: By - nginx.server_zone.sent: enabled: true attributes: @@ -176,12 +178,6 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: By - - ### Request and Traffic -# - `nginx.upstream.peers.requests` - Number of requests made to upstream servers -# - `nginx.upstream.peers.received` - Bytes received from upstream servers -# - `nginx.upstream.peers.sent` - Bytes sent to upstream servers - nginx.upstream.peers.requests: enabled: true attributes: @@ -193,7 +189,6 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: requests - nginx.upstream.peers.received: enabled: true attributes: @@ -218,13 +213,6 @@ metrics: aggregation_temporality: cumulative unit: By - ### Response Codes -# - `nginx.upstream.peers.responses.1xx` - Number of responses from upstream with 1xx status codes -# - `nginx.upstream.peers.responses.2xx` - Number of responses from upstream with 2xx status codes -# - `nginx.upstream.peers.responses.3xx` - Number of responses from upstream with 3xx status codes -# - `nginx.upstream.peers.responses.4xx` - Number of responses from upstream with 4xx status codes -# - `nginx.upstream.peers.responses.5xx` - Number of responses from upstream with 5xx status codes - nginx.upstream.peers.responses.1xx: enabled: true attributes: @@ -248,7 +236,7 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: responses - + nginx.upstream.peers.responses.3xx: enabled: true attributes: @@ -272,7 +260,7 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: responses - + nginx.upstream.peers.responses.5xx: enabled: true attributes: @@ -284,11 +272,6 @@ metrics: monotonic: true aggregation_temporality: cumulative unit: responses - - ### Server Configuration -# - `nginx.upstream.peers.weight` - Weight of upstream server -# - `nginx.upstream.peers.backup` - Whether upstream server is a backup server -# - `nginx.upstream.peers.health_checks.last_passed` - Status of last health check for upstream server nginx.upstream.peers.weight: enabled: true diff --git a/receiver/nginxreceiver/scraper.go b/receiver/nginxreceiver/scraper.go index 5ab3dfb3b762..7f3f1ebc9ad4 100644 --- a/receiver/nginxreceiver/scraper.go +++ b/receiver/nginxreceiver/scraper.go @@ -14,7 +14,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.uber.org/zap" - "github.com/k0kubun/pp" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/nginxreceiver/internal/metadata" ) @@ -50,7 +49,6 @@ func (r *nginxScraper) start(ctx context.Context, host component.Host) error { } func (r *nginxScraper) scrape(context.Context) (pmetric.Metrics, error) { - // Init client in scrape method in case there are transient errors in the constructor. if r.client == nil { var err error r.client, err = NewNginxClient(r.httpClient, r.cfg.ClientConfig.Endpoint, r.cfg.VTSEndpoint) @@ -74,8 +72,6 @@ func (r *nginxScraper) scrape(context.Context) (pmetric.Metrics, error) { return pmetric.Metrics{}, err } - // pp.Println(vtsStats) - now := pcommon.NewTimestampFromTime(time.Now()) r.recordVtsStats(now, vtsStats) @@ -182,8 +178,6 @@ func (r *nginxScraper) recordTimingStats(now pcommon.Timestamp, vtsStats *NginxV for upstreamZones, v := range vtsStats.UpstreamZones { for _, val := range v { - pp.Println(val.Server) - pp.Println(val.ResponseMsec) r.mb.RecordNginxUpstreamPeersResponseTimeDataPoint( now, val.ResponseMsec, upstreamZones, val.Server,