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/apache]: add optional apache.server.name resource attribute #14926

Merged
16 changes: 16 additions & 0 deletions .chloggen/apache-server-name-feature-gate.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: enhancement

# 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: Extract server name as resource attribute

# One or more tracking issues related to the change
issues: [14791]

# (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: The feature is enabled through a feature gate and will be enabled by default in v0.65.
14 changes: 14 additions & 0 deletions receiver/apachereceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ 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.

**ALPHA**: `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 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.65.0.
1 change: 1 addition & 0 deletions receiver/apachereceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
confighttp.HTTPClientSettings `mapstructure:",squash"`
serverName string
emitServerNameAsResourceAttribute bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a config option, not a feature gate. Please take a look at this feature gates example

emitMetricsWithDirectionAttributeFeatureGate = featuregate.Gate{

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a feature gate used, just not directly in the scraper, but in the factory:
https://github.com/aboguszewski-sumo/opentelemetry-collector-contrib/blob/6bac04c5014dbda6dfe8a424c02b9ab93459cbcc/receiver/apachereceiver/factory.go#L38-L50
I just thought that a pattern where it is injected in the scraper with the config seems more reasonable. I'll just move this code to the scraper then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Metrics metadata.MetricsSettings `mapstructure:"metrics"`
}

Expand Down
31 changes: 18 additions & 13 deletions receiver/apachereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ These are the metrics available for this scraper.

| Name | Description | Unit | Type | Attributes |
| ---- | ----------- | ---- | ---- | ---------- |
| **apache.cpu.load** | Current load of the CPU. | % | Gauge(Double) | <ul> <li>server_name</li> </ul> |
| **apache.cpu.time** | Jiffs used by processes of given category. | {jiff} | Sum(Double) | <ul> <li>server_name</li> <li>cpu_level</li> <li>cpu_mode</li> </ul> |
| **apache.current_connections** | The number of active connections currently attached to the HTTP server. | {connections} | Sum(Int) | <ul> <li>server_name</li> </ul> |
| **apache.load.1** | The average server load during the last minute. | % | Gauge(Double) | <ul> <li>server_name</li> </ul> |
| **apache.load.15** | The average server load during the last 15 minutes. | % | Gauge(Double) | <ul> <li>server_name</li> </ul> |
| **apache.load.5** | The average server load during the last 5 minutes. | % | Gauge(Double) | <ul> <li>server_name</li> </ul> |
| **apache.request.time** | Total time spent on handling requests. | ms | Sum(Int) | <ul> <li>server_name</li> </ul> |
| **apache.requests** | The number of requests serviced by the HTTP server per second. | {requests} | Sum(Int) | <ul> <li>server_name</li> </ul> |
| **apache.scoreboard** | The number of workers in each state. The apache scoreboard is an encoded representation of the state of all the server's workers. This metric decodes the scoreboard and presents a count of workers in each state. Additional details can be found [here](https://metacpan.org/pod/Apache::Scoreboard#DESCRIPTION). | {workers} | Sum(Int) | <ul> <li>server_name</li> <li>scoreboard_state</li> </ul> |
| **apache.traffic** | Total HTTP server traffic. | By | Sum(Int) | <ul> <li>server_name</li> </ul> |
| **apache.uptime** | The amount of time that the server has been running in seconds. | s | Sum(Int) | <ul> <li>server_name</li> </ul> |
| **apache.workers** | The number of workers currently attached to the HTTP server. | {workers} | Sum(Int) | <ul> <li>server_name</li> <li>workers_state</li> </ul> |
| **apache.cpu.load** | Current load of the CPU. | % | Gauge(Double) | <ul> </ul> |
| **apache.cpu.time** | Jiffs used by processes of given category. | {jiff} | Sum(Double) | <ul> <li>cpu_level</li> <li>cpu_mode</li> </ul> |
| **apache.current_connections** | The number of active connections currently attached to the HTTP server. | {connections} | Sum(Int) | <ul> </ul> |
| **apache.load.1** | The average server load during the last minute. | % | Gauge(Double) | <ul> </ul> |
| **apache.load.15** | The average server load during the last 15 minutes. | % | Gauge(Double) | <ul> </ul> |
| **apache.load.5** | The average server load during the last 5 minutes. | % | Gauge(Double) | <ul> </ul> |
| **apache.request.time** | Total time spent on handling requests. | ms | Sum(Int) | <ul> </ul> |
| **apache.requests** | The number of requests serviced by the HTTP server per second. | {requests} | Sum(Int) | <ul> </ul> |
| **apache.scoreboard** | The number of workers in each state. The apache scoreboard is an encoded representation of the state of all the server's workers. This metric decodes the scoreboard and presents a count of workers in each state. Additional details can be found [here](https://metacpan.org/pod/Apache::Scoreboard#DESCRIPTION). | {workers} | Sum(Int) | <ul> <li>scoreboard_state</li> </ul> |
| **apache.traffic** | Total HTTP server traffic. | By | Sum(Int) | <ul> </ul> |
| **apache.uptime** | The amount of time that the server has been running in seconds. | s | Sum(Int) | <ul> </ul> |
| **apache.workers** | The number of workers currently attached to the HTTP server. | {workers} | Sum(Int) | <ul> <li>workers_state</li> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Any metric can be enabled or disabled with the following scraper configuration:
Expand All @@ -30,12 +30,17 @@ metrics:
enabled: <true|false>
```

## Resource attributes

| Name | Description | Type |
| ---- | ----------- | ---- |
| apache.server.name | The name of the Apache HTTP server. | Str |

## Metric attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu_level (level) | Level of processes. | self, children |
| cpu_mode (mode) | Mode of processes. | system, user |
| scoreboard_state (state) | The state of a connection. | open, waiting, starting, reading, sending, keepalive, dnslookup, closing, logging, finishing, idle_cleanup, unknown |
| server_name | The name of the Apache HTTP server. | |
| workers_state (state) | The state of workers. | busy, idle |
28 changes: 26 additions & 2 deletions receiver/apachereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@ package apachereceiver // import "github.com/open-telemetry/opentelemetry-collec

import (
"context"
"fmt"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver/scraperhelper"

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

const (
typeStr = "apache"
stability = component.StabilityLevelBeta
typeStr = "apache"
stability = component.StabilityLevelBeta
EmitServerNameAsResourceAttribute = "receiver.apache.emitServerNameAsResourceAttribute"
)

var (
emitServerNameAsResourceAttribute = featuregate.Gate{
ID: EmitServerNameAsResourceAttribute,
Enabled: false,
Description: "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.",
}
)

func init() {
featuregate.GetRegistry().MustRegister(emitServerNameAsResourceAttribute)
}

// NewFactory creates a factory for apache receiver.
func NewFactory() component.ReceiverFactory {
return component.NewReceiverFactory(
Expand Down Expand Up @@ -62,6 +78,14 @@ func createMetricsReceiver(
) (component.MetricsReceiver, error) {
cfg := rConf.(*Config)

emitServerNameAsResourceAttributeEnabled := featuregate.GetRegistry().IsEnabled(EmitServerNameAsResourceAttribute)

if !emitServerNameAsResourceAttributeEnabled {
params.Logger.Warn(fmt.Sprintf("Feature gate %s is not enabled. Please see the README.md file of apache receiver for more information.", EmitServerNameAsResourceAttribute))
}

cfg.emitServerNameAsResourceAttribute = emitServerNameAsResourceAttributeEnabled

ns := newApacheScraper(params, cfg)
scraper, err := scraperhelper.NewScraper(typeStr, ns.scrape, scraperhelper.WithStart(ns.start))
if err != nil {
Expand Down
Loading