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] Bump current_connections feature gate to stable #27024

Merged
merged 1 commit into from
Sep 21, 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
27 changes: 27 additions & 0 deletions .chloggen/nginx-gate-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: receiver/nginx

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Bump 'nginx.connections_current' gate to stable

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
13 changes: 0 additions & 13 deletions receiver/nginxreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,3 @@ 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.
7 changes: 3 additions & 4 deletions receiver/nginxreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ const (
connectionsAsSum = "receiver.nginx.emitConnectionsCurrentAsSum"
)

var connectorsAsSumGate = featuregate.GlobalRegistry().MustRegister(
var _ = featuregate.GlobalRegistry().MustRegister(
connectionsAsSum,
featuregate.StageBeta,
featuregate.WithRegisterDescription("When enabled, the receiver will emit the 'nginx.connections_current' metric as a nonmonotonic sum, rather than a gauge."),
featuregate.StageStable,
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/4326"),
featuregate.WithRegisterFromVersion("v0.78.0"),
featuregate.WithRegisterToVersion("v0.87.0"),
)

// NewFactory creates a factory for nginx receiver.
Expand Down
25 changes: 5 additions & 20 deletions receiver/nginxreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ func newNginxScraper(
settings receiver.CreateSettings,
cfg *Config,
) *nginxScraper {
var mb *metadata.MetricsBuilder
if connectorsAsSumGate.IsEnabled() {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsGaugeDisabled())
} else {
mb = metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsGauge())
}
mb := metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings, metadata.WithCurrentConnectionsAsGaugeDisabled())
return &nginxScraper{
settings: settings.TelemetrySettings,
cfg: cfg,
Expand Down Expand Up @@ -72,22 +67,12 @@ func (r *nginxScraper) scrape(context.Context) (pmetric.Metrics, error) {
}

now := pcommon.NewTimestampFromTime(time.Now())

r.mb.RecordNginxRequestsDataPoint(now, stats.Requests)
r.mb.RecordNginxConnectionsAcceptedDataPoint(now, stats.Connections.Accepted)
r.mb.RecordNginxConnectionsHandledDataPoint(now, stats.Connections.Handled)

if connectorsAsSumGate.IsEnabled() {
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)
}

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
}
31 changes: 0 additions & 31 deletions receiver/nginxreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver/receivertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/golden"
Expand Down Expand Up @@ -48,36 +47,6 @@ func TestScraper(t *testing.T) {
pmetrictest.IgnoreMetricsOrder()))
}

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, false))
defer func() {
require.NoError(t, featuregate.GlobalRegistry().Set(connectionsAsSum, true))
}()

scraper := newNginxScraper(receivertest.NewNopCreateSettings(), cfg)

err := scraper.start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)

actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)

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(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricsOrder()))
}

func TestScraperError(t *testing.T) {
nginxMock := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/status" {
Expand Down
Loading