diff --git a/.chloggen/apache-remove-attr-feature-gates.yaml b/.chloggen/apache-remove-attr-feature-gates.yaml new file mode 100644 index 000000000000..d280db717b21 --- /dev/null +++ b/.chloggen/apache-remove-attr-feature-gates.yaml @@ -0,0 +1,12 @@ +# 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: apachereceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Remove feature gates that enable sending server name and port as resource attributes. + +# One or more tracking issues related to the change +issues: [14791] + diff --git a/receiver/apachereceiver/README.md b/receiver/apachereceiver/README.md index 8051eb823553..aa9156b8cf0e 100644 --- a/receiver/apachereceiver/README.md +++ b/receiver/apachereceiver/README.md @@ -41,27 +41,3 @@ Details about the metrics produced by this receiver can be found in [metadata.ya [beta]: https://github.com/open-telemetry/opentelemetry-collector#beta [contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib - -## 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. - -**BETA**: `receiver.apache.emitServerNameAsResourceAttribute` - -The feature gate `receiver.apache.emitServerNameAsResourceAttribute` once enabled starts emitting the metrics with a resource attribute `apache.server.name`. When the feature gate is disabled, the metrics are emitted with a `server_name` metric-level attribute instead. - -This is considered a breaking change for existing users of this receiver, and it is recommended to migrate to the new implementation when possible. Any new users planning to adopt this receiver should enable this feature gate to avoid having to migrate any visualisations or alerts. - -This feature gate is 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 the old implementation to be removed -is 0.69.0. - -**BETA**: `receiver.apache.emitPortAsResourceAttribute` - -The feature gate `receiver.apache.emitPortAsResourceAttribute` once enabled starts emitting the metrics with a resource attribute `apache.server.port`. - -This is considered a breaking change for existing users of this receiver, and it is recommended to migrate to the new implementation when possible. Any new users planning to adopt this receiver should enable this feature gate to avoid having to migrate any visualisations or alerts. - -This feature gate is 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 the old implementation to be removed -is 0.69.0. diff --git a/receiver/apachereceiver/go.mod b/receiver/apachereceiver/go.mod index b43f129b0206..5db18ad351e2 100644 --- a/receiver/apachereceiver/go.mod +++ b/receiver/apachereceiver/go.mod @@ -10,7 +10,6 @@ require ( go.opentelemetry.io/collector/component v0.68.0 go.opentelemetry.io/collector/confmap v0.68.0 go.opentelemetry.io/collector/consumer v0.68.0 - go.opentelemetry.io/collector/featuregate v0.68.0 go.opentelemetry.io/collector/pdata v1.0.0-rc2 go.uber.org/zap v1.24.0 ) @@ -59,6 +58,7 @@ require ( github.com/rs/cors v1.8.2 // indirect github.com/sirupsen/logrus v1.8.1 // indirect go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/collector/featuregate v0.68.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.37.0 // indirect go.opentelemetry.io/otel v1.11.2 // indirect go.opentelemetry.io/otel/metric v0.34.0 // indirect diff --git a/receiver/apachereceiver/integration_test.go b/receiver/apachereceiver/integration_test.go index 36c0f443c218..e87746029a34 100644 --- a/receiver/apachereceiver/integration_test.go +++ b/receiver/apachereceiver/integration_test.go @@ -34,7 +34,6 @@ import ( "github.com/testcontainers/testcontainers-go/wait" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/comparetest" @@ -57,10 +56,6 @@ func TestApacheIntegration(t *testing.T) { hostname, err := container.Host(context.Background()) require.NoError(t, err) - // Let this test check if it works with the features disabled and the unit test will test the feature enabled. - err = featuregate.GetRegistry().Apply(map[string]bool{EmitServerNameAsResourceAttribute: false, EmitPortAsResourceAttribute: false}) - require.NoError(t, err) - f := NewFactory() cfg := f.CreateDefaultConfig().(*Config) cfg.ScraperControllerSettings.CollectionInterval = 100 * time.Millisecond diff --git a/receiver/apachereceiver/internal/metadata/deprecated_metrics.go b/receiver/apachereceiver/internal/metadata/deprecated_metrics.go deleted file mode 100644 index 4db63a578965..000000000000 --- a/receiver/apachereceiver/internal/metadata/deprecated_metrics.go +++ /dev/null @@ -1,256 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "fmt" - "strconv" - - "go.opentelemetry.io/collector/pdata/pcommon" -) - -func (m *metricApacheCPULoad) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheCPUTime) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, serverNameAttributeValue string, cpuLevelAttributeValue string, cpuModeAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) - dp.Attributes().PutStr("level", cpuLevelAttributeValue) - dp.Attributes().PutStr("mode", cpuModeAttributeValue) -} - -func (m *metricApacheCurrentConnections) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheLoad1) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheLoad15) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheLoad5) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheRequestTime) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheRequests) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheScoreboard) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string, scoreboardStateAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) - dp.Attributes().PutStr("state", scoreboardStateAttributeValue) -} - -func (m *metricApacheTraffic) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheUptime) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) -} - -func (m *metricApacheWorkers) recordDataPointWithServerName(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, serverNameAttributeValue string, workersStateAttributeValue string) { - if !m.settings.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("server_name", serverNameAttributeValue) - dp.Attributes().PutStr("state", workersStateAttributeValue) -} - -// RecordApacheCPULoadDataPoint adds a data point to apache.cpu.load metric. -func (mb *MetricsBuilder) RecordApacheCPULoadDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseFloat(inputVal, 64) - if err != nil { - return fmt.Errorf("failed to parse float64 for ApacheCPULoad, value was %s: %w", inputVal, err) - } - mb.metricApacheCPULoad.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheCPUTimeDataPoint adds a data point to apache.cpu.time metric. -func (mb *MetricsBuilder) RecordApacheCPUTimeDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string, cpuLevelAttributeValue AttributeCPULevel, cpuModeAttributeValue AttributeCPUMode) error { - val, err := strconv.ParseFloat(inputVal, 64) - if err != nil { - return fmt.Errorf("failed to parse float64 for ApacheCPUTime, value was %s: %w", inputVal, err) - } - mb.metricApacheCPUTime.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue, cpuLevelAttributeValue.String(), cpuModeAttributeValue.String()) - return nil -} - -// RecordApacheCurrentConnectionsDataPoint adds a data point to apache.current_connections metric. -func (mb *MetricsBuilder) RecordApacheCurrentConnectionsDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for ApacheCurrentConnections, value was %s: %w", inputVal, err) - } - mb.metricApacheCurrentConnections.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheLoad1DataPoint adds a data point to apache.load.1 metric. -func (mb *MetricsBuilder) RecordApacheLoad1DataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseFloat(inputVal, 64) - if err != nil { - return fmt.Errorf("failed to parse float64 for ApacheLoad1, value was %s: %w", inputVal, err) - } - mb.metricApacheLoad1.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheLoad15DataPoint adds a data point to apache.load.15 metric. -func (mb *MetricsBuilder) RecordApacheLoad15DataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseFloat(inputVal, 64) - if err != nil { - return fmt.Errorf("failed to parse float64 for ApacheLoad15, value was %s: %w", inputVal, err) - } - mb.metricApacheLoad15.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheLoad5DataPoint adds a data point to apache.load.5 metric. -func (mb *MetricsBuilder) RecordApacheLoad5DataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseFloat(inputVal, 64) - if err != nil { - return fmt.Errorf("failed to parse float64 for ApacheLoad5, value was %s: %w", inputVal, err) - } - mb.metricApacheLoad5.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheRequestTimeDataPoint adds a data point to apache.request.time metric. -func (mb *MetricsBuilder) RecordApacheRequestTimeDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for ApacheRequestTime, value was %s: %w", inputVal, err) - } - mb.metricApacheRequestTime.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheRequestsDataPoint adds a data point to apache.requests metric. -func (mb *MetricsBuilder) RecordApacheRequestsDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for ApacheRequests, value was %s: %w", inputVal, err) - } - mb.metricApacheRequests.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheScoreboardDataPoint adds a data point to apache.scoreboard metric. -func (mb *MetricsBuilder) RecordApacheScoreboardDataPointWithServerName(ts pcommon.Timestamp, val int64, serverNameAttributeValue string, scoreboardStateAttributeValue AttributeScoreboardState) { - mb.metricApacheScoreboard.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue, scoreboardStateAttributeValue.String()) -} - -// RecordApacheTrafficDataPoint adds a data point to apache.traffic metric. -func (mb *MetricsBuilder) RecordApacheTrafficDataPointWithServerName(ts pcommon.Timestamp, val int64, serverNameAttributeValue string) { - mb.metricApacheTraffic.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) -} - -// RecordApacheUptimeDataPoint adds a data point to apache.uptime metric. -func (mb *MetricsBuilder) RecordApacheUptimeDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for ApacheUptime, value was %s: %w", inputVal, err) - } - mb.metricApacheUptime.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue) - return nil -} - -// RecordApacheWorkersDataPoint adds a data point to apache.workers metric. -func (mb *MetricsBuilder) RecordApacheWorkersDataPointWithServerName(ts pcommon.Timestamp, inputVal string, serverNameAttributeValue string, workersStateAttributeValue AttributeWorkersState) error { - val, err := strconv.ParseInt(inputVal, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse int64 for ApacheWorkers, value was %s: %w", inputVal, err) - } - mb.metricApacheWorkers.recordDataPointWithServerName(mb.startTime, ts, val, serverNameAttributeValue, workersStateAttributeValue.String()) - return nil -} diff --git a/receiver/apachereceiver/scraper.go b/receiver/apachereceiver/scraper.go index 323903110c61..4fd8dbfc8afd 100644 --- a/receiver/apachereceiver/scraper.go +++ b/receiver/apachereceiver/scraper.go @@ -17,7 +17,6 @@ package apachereceiver // import "github.com/open-telemetry/opentelemetry-collec import ( "context" "errors" - "fmt" "io" "net/http" "strconv" @@ -25,7 +24,6 @@ import ( "time" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver" @@ -35,27 +33,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/apachereceiver/internal/metadata" ) -const ( - readmeURL = "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/apachereceiver/README.md" - EmitServerNameAsResourceAttribute = "receiver.apache.emitServerNameAsResourceAttribute" - EmitPortAsResourceAttribute = "receiver.apache.emitPortAsResourceAttribute" -) - -func init() { - featuregate.GetRegistry().MustRegisterID( - EmitServerNameAsResourceAttribute, - featuregate.StageBeta, - featuregate.WithRegisterDescription("When enabled, the name of the server will be sent as an apache.server.name resource attribute instead of a metric-level server_name attribute."), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/14791"), - ) - featuregate.GetRegistry().MustRegisterID( - EmitPortAsResourceAttribute, - featuregate.StageBeta, - featuregate.WithRegisterDescription("When enabled, the port of the server will be sent as an apache.server.port resource attribute."), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/14791"), - ) -} - type apacheScraper struct { settings component.TelemetrySettings cfg *Config @@ -63,10 +40,6 @@ type apacheScraper struct { mb *metadata.MetricsBuilder serverName string port string - - // Feature gates regarding resource attributes - emitMetricsWithServerNameAsResourceAttribute bool - emitMetricsWithPortAsResourceAttribute bool } func newApacheScraper( @@ -81,20 +54,6 @@ func newApacheScraper( mb: metadata.NewMetricsBuilder(cfg.Metrics, settings), serverName: serverName, port: port, - emitMetricsWithServerNameAsResourceAttribute: featuregate.GetRegistry().IsEnabled(EmitServerNameAsResourceAttribute), - emitMetricsWithPortAsResourceAttribute: featuregate.GetRegistry().IsEnabled(EmitPortAsResourceAttribute), - } - - if !a.emitMetricsWithServerNameAsResourceAttribute { - settings.Logger.Warn( - fmt.Sprintf("Feature gate %s is not enabled. Please see the README for more information: %s", EmitServerNameAsResourceAttribute, readmeURL), - ) - } - - if !a.emitMetricsWithPortAsResourceAttribute { - settings.Logger.Warn( - fmt.Sprintf("Feature gate %s is not enabled. Please see the README for more information: %s", EmitPortAsResourceAttribute, readmeURL), - ) } return a @@ -120,88 +79,6 @@ func (r *apacheScraper) scrape(context.Context) (pmetric.Metrics, error) { return pmetric.Metrics{}, err } - emitWith := []metadata.ResourceMetricsOption{} - - if r.emitMetricsWithServerNameAsResourceAttribute { - err = r.scrapeWithoutServerNameAttr(stats) - emitWith = append(emitWith, metadata.WithApacheServerName(r.serverName)) - } else { - err = r.scrapeWithServerNameAttr(stats) - } - - if r.emitMetricsWithPortAsResourceAttribute { - emitWith = append(emitWith, metadata.WithApacheServerPort(r.port)) - } - - return r.mb.Emit(emitWith...), err -} - -func (r *apacheScraper) scrapeWithServerNameAttr(stats string) error { - errs := &scrapererror.ScrapeErrors{} - now := pcommon.NewTimestampFromTime(time.Now()) - for metricKey, metricValue := range parseStats(stats) { - switch metricKey { - case "ServerUptimeSeconds": - addPartialIfError(errs, r.mb.RecordApacheUptimeDataPointWithServerName(now, metricValue, r.serverName)) - case "ConnsTotal": - addPartialIfError(errs, r.mb.RecordApacheCurrentConnectionsDataPointWithServerName(now, metricValue, r.serverName)) - case "BusyWorkers": - addPartialIfError(errs, r.mb.RecordApacheWorkersDataPointWithServerName(now, metricValue, r.serverName, - metadata.AttributeWorkersStateBusy)) - case "IdleWorkers": - addPartialIfError(errs, r.mb.RecordApacheWorkersDataPointWithServerName(now, metricValue, r.serverName, - metadata.AttributeWorkersStateIdle)) - case "Total Accesses": - addPartialIfError(errs, r.mb.RecordApacheRequestsDataPointWithServerName(now, metricValue, r.serverName)) - case "Total kBytes": - i, err := strconv.ParseInt(metricValue, 10, 64) - if err != nil { - errs.AddPartial(1, err) - } else { - r.mb.RecordApacheTrafficDataPointWithServerName(now, kbytesToBytes(i), r.serverName) - } - case "CPUChildrenSystem": - addPartialIfError( - errs, - r.mb.RecordApacheCPUTimeDataPointWithServerName(now, metricValue, r.serverName, metadata.AttributeCPULevelChildren, metadata.AttributeCPUModeSystem), - ) - case "CPUChildrenUser": - addPartialIfError( - errs, - r.mb.RecordApacheCPUTimeDataPointWithServerName(now, metricValue, r.serverName, metadata.AttributeCPULevelChildren, metadata.AttributeCPUModeUser), - ) - case "CPUSystem": - addPartialIfError( - errs, - r.mb.RecordApacheCPUTimeDataPointWithServerName(now, metricValue, r.serverName, metadata.AttributeCPULevelSelf, metadata.AttributeCPUModeSystem), - ) - case "CPUUser": - addPartialIfError( - errs, - r.mb.RecordApacheCPUTimeDataPointWithServerName(now, metricValue, r.serverName, metadata.AttributeCPULevelSelf, metadata.AttributeCPUModeUser), - ) - case "CPULoad": - addPartialIfError(errs, r.mb.RecordApacheCPULoadDataPointWithServerName(now, metricValue, r.serverName)) - case "Load1": - addPartialIfError(errs, r.mb.RecordApacheLoad1DataPointWithServerName(now, metricValue, r.serverName)) - case "Load5": - addPartialIfError(errs, r.mb.RecordApacheLoad5DataPointWithServerName(now, metricValue, r.serverName)) - case "Load15": - addPartialIfError(errs, r.mb.RecordApacheLoad15DataPointWithServerName(now, metricValue, r.serverName)) - case "Total Duration": - addPartialIfError(errs, r.mb.RecordApacheRequestTimeDataPointWithServerName(now, metricValue, r.serverName)) - case "Scoreboard": - scoreboardMap := parseScoreboard(metricValue) - for state, score := range scoreboardMap { - r.mb.RecordApacheScoreboardDataPointWithServerName(now, score, r.serverName, state) - } - } - } - - return errs.Combine() -} - -func (r *apacheScraper) scrapeWithoutServerNameAttr(stats string) error { errs := &scrapererror.ScrapeErrors{} now := pcommon.NewTimestampFromTime(time.Now()) for metricKey, metricValue := range parseStats(stats) { @@ -261,7 +138,7 @@ func (r *apacheScraper) scrapeWithoutServerNameAttr(stats string) error { } } - return errs.Combine() + return r.mb.Emit(metadata.WithApacheServerName(r.serverName), metadata.WithApacheServerPort(r.port)), errs.Combine() } func addPartialIfError(errs *scrapererror.ScrapeErrors, err error) { diff --git a/receiver/apachereceiver/scraper_test.go b/receiver/apachereceiver/scraper_test.go index adbe32ab2899..bd47fa8ea599 100644 --- a/receiver/apachereceiver/scraper_test.go +++ b/receiver/apachereceiver/scraper_test.go @@ -42,8 +42,6 @@ func TestScraper(t *testing.T) { cfg.Endpoint = fmt.Sprintf("%s%s", apacheMock.URL, "/server-status?auto") require.NoError(t, component.ValidateConfig(cfg)) - // Let this test check if it works with the feature enabled and the integration test will test the feature disabled. - serverName, port, err := parseResourseAttributes(cfg.Endpoint) require.NoError(t, err) scraper := newApacheScraper(receivertest.NewNopCreateSettings(), cfg, serverName, port) diff --git a/receiver/apachereceiver/testdata/integration/expected.json b/receiver/apachereceiver/testdata/integration/expected.json index 53dea0ba9dc1..c8c2218e887a 100644 --- a/receiver/apachereceiver/testdata/integration/expected.json +++ b/receiver/apachereceiver/testdata/integration/expected.json @@ -1,576 +1,431 @@ { "resourceMetrics": [ - { - "scopeMetrics": [ - { - "scope": { - "name": "otelcol/apachereceiver", - "version": "latest" - }, - "metrics": [ - { - "description": "The amount of time that the server has been running in seconds.", - "name": "apache.uptime", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "1", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ], - "isMonotonic": true - }, - "unit": "s" - }, - { - "description": "The number of active connections currently attached to the HTTP server.", - "name": "apache.current_connections", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ] - }, - "unit": "{connections}" - }, - { - "description": "The number of workers currently attached to the HTTP server.", - "name": "apache.workers", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "74", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "idle" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "1", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "busy" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ] - }, - "unit": "{workers}" - }, - { - "description": "The number of requests serviced by the HTTP server per second.", - "name": "apache.requests", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "9", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ], - "isMonotonic": true - }, - "unit": "{requests}" - }, - { - "description": "Total HTTP server traffic.", - "name": "apache.traffic", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "9216", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ], - "isMonotonic": true - }, - "unit": "By" - }, - { - "name": "apache.cpu.time", - "description": "Jiffs used by processes of given category.", - "unit": "{jiff}", - "sum": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "level", - "value": { - "stringValue": "children" - } - }, - { - "key": "mode", - "value": { - "stringValue": "system" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.01" - }, - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "level", - "value": { - "stringValue": "children" - } - }, - { - "key": "mode", - "value": { - "stringValue": "user" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.02" - }, - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "level", - "value": { - "stringValue": "self" - } - }, - { - "key": "mode", - "value": { - "stringValue": "system" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.03" - }, - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "level", - "value": { - "stringValue": "self" - } - }, - { - "key": "mode", - "value": { - "stringValue": "user" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.04" - } + { + "resource": { + "attributes": [ + { + "key": "apache.server.name", + "value": { + "stringValue": "localhost" + } + }, + { + "key": "apache.server.port", + "value": { + "stringValue": "8081" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/apachereceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "apache.uptime", + "description": "The amount of time that the server has been running in seconds.", + "unit": "s", + "sum": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asInt": "410" + } + ], + "aggregationTemporality": 2, + "isMonotonic": true + } + }, + { + "name": "apache.current_connections", + "description": "The number of active connections currently attached to the HTTP server.", + "unit": "{connections}", + "sum": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asInt": "110" + } + ], + "aggregationTemporality": 2, + "isMonotonic": false + } + }, + { + "name": "apache.workers", + "description": "The number of workers currently attached to the HTTP server.", + "unit": "{workers}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "busy" + } + } ], - "aggregationTemporality": 2, - "isMonotonic": true - } - }, - { - "name": "apache.cpu.load", - "description": "Current load of the CPU.", - "unit": "%", - "gauge": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.66" - } - ] - } - }, - { - "name": "apache.load.1", - "description": "The average server load during the last minute.", - "unit": "%", - "gauge": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.9" - } - ] - } - }, - { - "name": "apache.load.5", - "description": "The average server load during the last 5 minutes.", - "unit": "%", - "gauge": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.4" - } - ] - } - }, - { - "name": "apache.load.15", - "description": "The average server load during the last 15 minutes.", - "unit": "%", - "gauge": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asDouble": "0.3" - } - ] - } - }, - { - "name": "apache.request.time", - "description": "Total time spent on handling requests.", - "unit": "ms", - "sum": { - "dataPoints": [ - { - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - } - ], - "timeUnixNano": "1632495518500962000", - "asInt": "1501" - } + "timeUnixNano": "1632495518500962000", + "asInt": "13" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "idle" + } + } ], - "aggregationTemporality": 2, - "isMonotonic": true - } - }, - { - "description": "The number of workers in each state.", - "name": "apache.scoreboard", - "sum": { - "aggregationTemporality": 2, - "dataPoints": [ - { - "asInt": "74", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "waiting" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "reading" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "1", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "sending" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "finishing" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "idle_cleanup" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "starting" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "keepalive" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "dnslookup" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "closing" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "0", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "logging" - } - } - ], - "timeUnixNano": "1643738099294864000" - }, - { - "asInt": "325", - "attributes": [ - { - "key": "server_name", - "value": { - "stringValue": "localhost" - } - }, - { - "key": "state", - "value": { - "stringValue": "open" - } - } - ], - "timeUnixNano": "1643738099294864000" - } - ] - }, - "unit": "{workers}" - } - ] - } - ], - "resource": {} - } + "timeUnixNano": "1632495518500962000", + "asInt": "227" + } + ], + "aggregationTemporality": 2, + "isMonotonic": false + } + }, + { + "name": "apache.requests", + "description": "The number of requests serviced by the HTTP server per second.", + "unit": "{requests}", + "sum": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asInt": "14169" + } + ], + "aggregationTemporality": 2, + "isMonotonic": true + } + }, + { + "name": "apache.traffic", + "description": "Total HTTP server traffic.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asInt": "21411840" + } + ], + "aggregationTemporality": 2, + "isMonotonic": true + } + }, + { + "name": "apache.cpu.time", + "description": "Jiffs used by processes of given category.", + "unit": "{jiff}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "level", + "value": { + "stringValue": "children" + } + }, + { + "key": "mode", + "value": { + "stringValue": "system" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.01" + }, + { + "attributes": [ + { + "key": "level", + "value": { + "stringValue": "children" + } + }, + { + "key": "mode", + "value": { + "stringValue": "user" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.02" + }, + { + "attributes": [ + { + "key": "level", + "value": { + "stringValue": "self" + } + }, + { + "key": "mode", + "value": { + "stringValue": "system" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.03" + }, + { + "attributes": [ + { + "key": "level", + "value": { + "stringValue": "self" + } + }, + { + "key": "mode", + "value": { + "stringValue": "user" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.04" + } + ], + "aggregationTemporality": 2, + "isMonotonic": true + } + }, + { + "name": "apache.cpu.load", + "description": "Current load of the CPU.", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.66" + } + ] + } + }, + { + "name": "apache.load.1", + "description": "The average server load during the last minute.", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.9" + } + ] + } + }, + { + "name": "apache.load.5", + "description": "The average server load during the last 5 minutes.", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.4" + } + ] + } + }, + { + "name": "apache.load.15", + "description": "The average server load during the last 15 minutes.", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asDouble": "0.3" + } + ] + } + }, + { + "name": "apache.request.time", + "description": "Total time spent on handling requests.", + "unit": "ms", + "sum": { + "dataPoints": [ + { + "attributes": [], + "timeUnixNano": "1632495518500962000", + "asInt": "1501" + } + ], + "aggregationTemporality": 2, + "isMonotonic": true + } + }, + { + "name": "apache.scoreboard", + "description": "The number of workers in each state.", + "unit": "{workers}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "waiting" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "217" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "keepalive" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "2" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "logging" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "1" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "finishing" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "3" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "open" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "150" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "idle_cleanup" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "4" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "starting" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "1" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "reading" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "4" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "sending" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "12" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dnslookup" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "2" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "closing" + } + } + ], + "timeUnixNano": "1632495518500962000", + "asInt": "4" + } + ], + "aggregationTemporality": 2, + "isMonotonic": false + } + } + ] + } + ] + } ] -} + } + + \ No newline at end of file