Skip to content

Commit

Permalink
[receiver/nginx] Bump 'receiver.nginx.emitConnectionsCurrentAsSum' fe…
Browse files Browse the repository at this point in the history
…aturegate to beta (open-telemetry#23255)
  • Loading branch information
djaglowski authored Jun 12, 2023
1 parent bbea8aa commit 9d5526c
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 67 deletions.
20 changes: 20 additions & 0 deletions .chloggen/nginx-beta-featuregate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: nginxreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Bump 'receiver.nginx.emitConnectionsCurrentAsSum' featuregate to beta (enabled by default)

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [4326]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
14 changes: 7 additions & 7 deletions receiver/nginxreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ The total number of accepted client connections
The current number of nginx connections by state
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| connections | Gauge | Int |
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| connections | Sum | Int | Cumulative | false |
#### Attributes
Expand All @@ -52,11 +52,11 @@ Total number of requests made to the server since it started
### temp.connections_current
Temporary placeholder for new version of nginx.connections_current. See featuregate 'nginx.connections_as_sum'.
Temporary placeholder for old version of nginx.connections_current. See featuregate 'nginx.connections_as_sum'.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| connections | Sum | Int | Cumulative | false |
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| connections | Gauge | Int |
#### Attributes
Expand Down
2 changes: 1 addition & 1 deletion receiver/nginxreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

var connectorsAsSumGate = featuregate.GlobalRegistry().MustRegister(
connectionsAsSum,
featuregate.StageAlpha,
featuregate.StageBeta,
featuregate.WithRegisterDescription("When enabled, the receiver will emit the 'nginx.connections_current' metric as a nonmonotonic sum, rather than a gauge."),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/4326"),
featuregate.WithRegisterFromVersion("v0.78.0"),
Expand Down
30 changes: 15 additions & 15 deletions receiver/nginxreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions receiver/nginxreceiver/internal/metadata/temporary_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions receiver/nginxreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,21 @@ metrics:
monotonic: true
aggregation: cumulative
attributes: []

# Old version of metric, to be enabled when featuregate is stable
nginx.connections_current:
enabled: true
description: The current number of nginx connections by state
unit: connections
gauge:
sum:
value_type: int
monotonic: false
aggregation: cumulative
attributes: [state]

# New version of metric, to be enabled when featuregate is stable
# Old version of metric, to be removed when featuregate is stable
temp.connections_current:
enabled: true # must be enabled by default in order to apply necessary MetricBuilder option
description: Temporary placeholder for new version of nginx.connections_current. See featuregate 'nginx.connections_as_sum'.
description: Temporary placeholder for old version of nginx.connections_current. See featuregate 'nginx.connections_as_sum'.
unit: connections
sum:
gauge:
value_type: int
monotonic: false
aggregation: cumulative
attributes: [state]
14 changes: 7 additions & 7 deletions receiver/nginxreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func newNginxScraper(
) *nginxScraper {
var mb *metadata.MetricsBuilder
if connectorsAsSumGate.IsEnabled() {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsSum())
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsGaugeDisabled())
} else {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsSumDisabled())
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsGauge())
}
return &nginxScraper{
settings: settings.TelemetrySettings,
Expand Down Expand Up @@ -78,15 +78,15 @@ func (r *nginxScraper) scrape(context.Context) (pmetric.Metrics, error) {
r.mb.RecordNginxConnectionsHandledDataPoint(now, stats.Connections.Handled)

if connectorsAsSumGate.IsEnabled() {
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Active, metadata.AttributeStateActive)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Reading, metadata.AttributeStateReading)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Writing, metadata.AttributeStateWriting)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Waiting, metadata.AttributeStateWaiting)
} else {
r.mb.RecordNginxConnectionsCurrentDataPoint(now, stats.Connections.Active, metadata.AttributeStateActive)
r.mb.RecordNginxConnectionsCurrentDataPoint(now, stats.Connections.Reading, metadata.AttributeStateReading)
r.mb.RecordNginxConnectionsCurrentDataPoint(now, stats.Connections.Writing, metadata.AttributeStateWriting)
r.mb.RecordNginxConnectionsCurrentDataPoint(now, stats.Connections.Waiting, metadata.AttributeStateWaiting)
} else {
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Active, metadata.AttributeStateActive)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Reading, metadata.AttributeStateReading)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Writing, metadata.AttributeStateWriting)
r.mb.RecordTempConnectionsCurrentDataPoint(now, stats.Connections.Waiting, metadata.AttributeStateWaiting)
}

return r.mb.Emit(), nil
Expand Down
22 changes: 12 additions & 10 deletions receiver/nginxreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ func TestScraper(t *testing.T) {
expectedMetrics, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics, pmetrictest.IgnoreStartTimestamp(),
require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics,
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreTimestamp()))
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricsOrder()))
}

func TestScraperWithConnectionsAsSum(t *testing.T) {
func TestScraperWithConnectionsAsGauge(t *testing.T) {
nginxMock := newMockServer(t)
cfg := createDefaultConfig().(*Config)
cfg.Endpoint = nginxMock.URL + "/status"
require.NoError(t, component.ValidateConfig(cfg))

require.NoError(t, featuregate.GlobalRegistry().Set(connectionsAsSum, true))
require.NoError(t, featuregate.GlobalRegistry().Set(connectionsAsSum, false))
defer func() {
require.NoError(t, featuregate.GlobalRegistry().Set(connectionsAsSum, false))
require.NoError(t, featuregate.GlobalRegistry().Set(connectionsAsSum, true))
}()

scraper := newNginxScraper(receivertest.NewNopCreateSettings(), cfg)
Expand All @@ -66,14 +67,15 @@ func TestScraperWithConnectionsAsSum(t *testing.T) {
actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)

expectedFile := filepath.Join("testdata", "scraper", "expected_with_connections_as_sum.yaml")
expectedFile := filepath.Join("testdata", "scraper", "expected_with_connections_as_gauge.yaml")
expectedMetrics, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics, pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics,
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreTimestamp(), pmetrictest.IgnoreMetricsOrder()))
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricsOrder()))
}

func TestScraperError(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion receiver/nginxreceiver/testdata/integration/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ resourceMetrics:
isMonotonic: true
unit: connections
- description: The current number of nginx connections by state
gauge:
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "1"
attributes:
Expand All @@ -38,6 +39,7 @@ resourceMetrics:
value:
stringValue: waiting
timeUnixNano: "1643729289485220000"
isMonotonic: false
name: nginx.connections_current
unit: connections
- description: The total number of handled connections. Generally, the parameter value is the same as nginx.connections_accepted unless some resource limits have been reached (for example, the worker_connections limit).
Expand Down
5 changes: 3 additions & 2 deletions receiver/nginxreceiver/testdata/scraper/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ resourceMetrics:
isMonotonic: true
unit: connections
- description: The current number of nginx connections by state
gauge:
name: nginx.connections_current
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "291"
attributes:
Expand All @@ -38,7 +40,6 @@ resourceMetrics:
value:
stringValue: writing
timeUnixNano: "1638471548185885000"
name: nginx.connections_current
unit: connections
- description: The total number of handled connections. Generally, the parameter value is the same as nginx.connections_accepted unless some resource limits have been reached (for example, the worker_connections limit).
name: nginx.connections_handled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ resourceMetrics:
isMonotonic: true
unit: connections
- description: The current number of nginx connections by state
name: nginx.connections_current
sum:
aggregationTemporality: 2
gauge:
dataPoints:
- asInt: "291"
attributes:
Expand All @@ -40,6 +38,7 @@ resourceMetrics:
value:
stringValue: writing
timeUnixNano: "1638471548185885000"
name: nginx.connections_current
unit: connections
- description: The total number of handled connections. Generally, the parameter value is the same as nginx.connections_accepted unless some resource limits have been reached (for example, the worker_connections limit).
name: nginx.connections_handled
Expand Down

0 comments on commit 9d5526c

Please sign in to comment.