Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/nginx] Add featuregate to emit 'nginx.connections_current' as a non-monotonic sum #21686

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/nginx-connections-sum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: Add featuregate to emit 'nginx.connections_current' as a non-monotonic sum

# One or more tracking issues related to the change
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:
12 changes: 12 additions & 0 deletions receiver/nginxreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ receivers:
The full list of settings exposed for this receiver are documented [here](./config.go)
with detailed sample configurations [here](./testdata/config.yaml).

## Feature gate configurations

See the [Collector feature gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md#collector-feature-gates) for an overview of feature gates in the collector.

**ALPHA**: `receiver.nginx.emitCurrentConnectionsAsSum`

The feature gate `receiver.nginx.emitConnectionsCurrentAsSum` once enabled will change the data type of the
`nginx.connections_current` metric from a gauge to a non-monotonic sum.

This feature gate will eventually be enabled by default, and eventually the old implementation will be removed. It aims
to give users time to migrate to the new implementation. The target release for this featuregate to be enabled by default
is 0.80.0.
14 changes: 14 additions & 0 deletions receiver/nginxreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ Total number of requests made to the server since it started
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| requests | Sum | Int | Cumulative | true |

### temp.connections_current

Temporary placeholder for new version of nginx.connections_current. See featuregate 'nginx.connections_as_sum'.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| connections | Sum | Int | Cumulative | false |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| state | The state of a connection | Str: ``active``, ``reading``, ``writing``, ``waiting`` |
12 changes: 11 additions & 1 deletion receiver/nginxreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/nginxreceiver/internal/metadata"
)

const (
typeStr = "nginx"
typeStr = "nginx"
connectionsAsSum = "receiver.nginx.emitConnectionsCurrentAsSum"
)

var connectorsAsSumGate = featuregate.GlobalRegistry().MustRegister(
connectionsAsSum,
featuregate.StageAlpha,
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"),
)

// NewFactory creates a factory for nginx receiver.
Expand Down
2 changes: 1 addition & 1 deletion receiver/nginxreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
go.opentelemetry.io/collector/component v0.77.0
go.opentelemetry.io/collector/confmap v0.77.0
go.opentelemetry.io/collector/consumer v0.77.0
go.opentelemetry.io/collector/featuregate v0.77.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0011
go.opentelemetry.io/collector/receiver v0.77.0
go.uber.org/zap v1.24.0
Expand Down Expand Up @@ -61,7 +62,6 @@ require (
github.com/sirupsen/logrus v1.9.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/exporter v0.77.0 // indirect
go.opentelemetry.io/collector/featuregate v0.77.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.41.1 // indirect
go.opentelemetry.io/otel v1.15.1 // indirect
go.opentelemetry.io/otel/metric v0.38.1 // indirect
Expand Down

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.

61 changes: 61 additions & 0 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.

23 changes: 23 additions & 0 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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ all_set:
enabled: true
nginx.requests:
enabled: true
temp.connections_current:
enabled: true
none_set:
metrics:
nginx.connections_accepted:
Expand All @@ -19,3 +21,5 @@ none_set:
enabled: false
nginx.requests:
enabled: false
temp.connections_current:
enabled: false
13 changes: 13 additions & 0 deletions receiver/nginxreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,23 @@ 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:
value_type: int
attributes: [state]

# New version of metric, to be enabled 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'.
unit: connections
sum:
value_type: int
monotonic: false
aggregation: cumulative
attributes: [state]
24 changes: 19 additions & 5 deletions receiver/nginxreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ func newNginxScraper(
settings receiver.CreateSettings,
cfg *Config,
) *nginxScraper {
var mb *metadata.MetricsBuilder
if connectorsAsSumGate.IsEnabled() {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsSum())
} else {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsSumDisabled())
}
return &nginxScraper{
settings: settings.TelemetrySettings,
cfg: cfg,
mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings),
mb: mb,
}
}

Expand Down Expand Up @@ -81,10 +87,18 @@ func (r *nginxScraper) scrape(context.Context) (pmetric.Metrics, error) {
r.mb.RecordNginxRequestsDataPoint(now, stats.Requests)
r.mb.RecordNginxConnectionsAcceptedDataPoint(now, stats.Connections.Accepted)
r.mb.RecordNginxConnectionsHandledDataPoint(now, stats.Connections.Handled)
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)

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)
}

return r.mb.Emit(), nil
}
Loading