Skip to content

Commit

Permalink
[receiver/haproxyreceiver] add HAProxy receiver (open-telemetry#16842)
Browse files Browse the repository at this point in the history
* [receiver/haproxyreceiver] add HAProxy receiver

* don't expose CreateDefaultConfig

* code review

* remove component from configschema requirements

* undo unintented rename

* fix file uri

* tidy

* Update receiver/haproxyreceiver/README.md

Co-authored-by: Evan Bradley <[email protected]>

Co-authored-by: Evan Bradley <[email protected]>
  • Loading branch information
atoulme and evan-bradley committed Dec 15, 2022
1 parent d303152 commit 2b56579
Show file tree
Hide file tree
Showing 23 changed files with 1,596 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/add-haproxy.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: new_component

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: A receiver scraping metrics from the HAProxy stats command.

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

# (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:
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ receiver/flinkmetricsreceiver/ @open-telemetry/collector-c
receiver/fluentforwardreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax
receiver/googlecloudpubsubreceiver/ @open-telemetry/collector-contrib-approvers @alexvanboxel
receiver/googlecloudspannerreceiver/ @open-telemetry/collector-contrib-approvers @architjugran @varunraiko @kiranmayib
receiver/haproxyreceiver/ @open-telemetry/collector-contrib-approvers @atoulme @MovieStoreGuy
receiver/hostmetricsreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax
receiver/httpcheckreceiver/ @open-telemetry/collector-contrib-approvers @codeboten
receiver/influxdbreceiver/ @open-telemetry/collector-contrib-approvers @jacobmarble
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ body:
- receiver/fluentforward
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
- receiver/hostmetrics
- receiver/httpcheck
- receiver/iis
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ body:
- receiver/fluentforward
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
- receiver/hostmetrics
- receiver/httpcheck
- receiver/iis
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ body:
- receiver/fluentforward
- receiver/googlecloudpubsub
- receiver/googlecloudspanner
- receiver/haproxy
- receiver/hostmetrics
- receiver/httpcheck
- receiver/iis
Expand Down
2 changes: 2 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googl

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudspannerreceiver => ../../receiver/googlecloudspannerreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ../../receiver/haproxyreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver => ../../receiver/hostmetricsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver => ../../receiver/httpcheckreceiver
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windo

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver => ../../receiver/jaegerreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ../../receiver/haproxyreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver => ../../receiver/hostmetricsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter => ../../exporter/signalfxexporter
Expand Down
2 changes: 2 additions & 0 deletions cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/rout

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuredataexplorerexporter => ../../exporter/azuredataexplorerexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ../../receiver/haproxyreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver => ../../receiver/hostmetricsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension => ../../extension/bearertokenauthextension
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fluentforwardreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudpubsubreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudspannerreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.67.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.67.0
Expand Down Expand Up @@ -898,6 +899,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googl

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudpubsubreceiver => ./receiver/googlecloudpubsubreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ./receiver/haproxyreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver => ./receiver/hostmetricsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver => ./receiver/httpcheckreceiver
Expand Down
9 changes: 9 additions & 0 deletions internal/components/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/chronyreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otlpjsonfilereceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
Expand Down Expand Up @@ -168,6 +169,14 @@ func TestDefaultReceivers(t *testing.T) {
receiver: "googlecloudpubsub",
skipLifecyle: true, // Requires a pubsub subscription
},
{
receiver: "haproxy",
getConfigFn: func() component.Config {
cfg := rcvrFactories["haproxy"].CreateDefaultConfig().(*haproxyreceiver.Config)
cfg.Endpoint = "http:https://example.com"
return cfg
},
},
{
receiver: "hostmetrics",
},
Expand Down
1 change: 1 addition & 0 deletions receiver/haproxyreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
55 changes: 55 additions & 0 deletions receiver/haproxyreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# HAProxy Receiver

| Status | |
| ------------------------ |---------------|
| Stability | [development] |
| Supported pipeline types | metrics |
| Distributions | [contrib] |

The HAProxy receiver generates metrics by polling periodically the HAProxy process through a dedicated socket or HTTP URL.

Supported pipeline types: metrics

## Getting Started

## Configuration

### endpoint (required)
Path to the endpoint exposed by HAProxy for communications. It can be a local file socket or a HTTP URL.

### Collection interval settings (optional)
The scraping collection interval can be configured.

Default: 1 minute

### Example configuration

```yaml
haproxy:
endpoint: file:https:///var/run/haproxy.ipc
collection_interval: 1m
metrics:

```

## Enabling metrics.

See [documentation.md](./documentation.md).

You can enable or disable selective metrics.

Example:

```yaml
receivers:
haproxy:
endpoint: http:https://127.0.0.1:8080/stats
metrics:
haproxy.connection_rate:
enabled: false
haproxy.requests:
enabled: true
```

[development]: https://github.com/open-telemetry/opentelemetry-collector#development

39 changes: 39 additions & 0 deletions receiver/haproxyreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver"

import (
"errors"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/receiver/scraperhelper"

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

type Config struct {
config.ReceiverSettings `mapstructure:",squash"`
confighttp.HTTPClientSettings `mapstructure:",squash"`
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
MetricsSettings metadata.MetricsSettings `mapstructure:"metrics"`
}

func (c Config) Validate() error {
if c.HTTPClientSettings.Endpoint == "" {
return errors.New("'endpoint' cannot be empty")
}
return nil
}
18 changes: 18 additions & 0 deletions receiver/haproxyreceiver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate mdatagen metadata.yaml

// Package haproxyreceiver implements a receiver collecting metrics from HAProxy.
package haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver"
59 changes: 59 additions & 0 deletions receiver/haproxyreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# haproxyreceiver

## Default Metrics

The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:

```yaml
metrics:
<metric_name>:
enabled: false
```

### haproxy.connection_rate

Number of connections over the last elapsed second (frontend). Corresponds to HAProxy's `conn_rate` metric.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {connections} | Gauge | Int |

### haproxy.idle_percent

Ratio of system polling time versus total time. Corresponds to HAProxy's `I`dle_pct` metric.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {percent} | Gauge | Double |

### haproxy.requests

Total number of requests on this worker process since started. Corresponds to HAProxy's `CumReq` metric.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {requests} | Sum | Int | Cumulative | true |

### haproxy.sessions.count

Current sessions. Corresponds to HAProxy's `scur` metric.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {sessions} | Gauge | Int |

## Resource Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| haproxy.addr | address:port or "unix". IPv6 has brackets around the address. | Any Str |
| haproxy.algo | load balancing algorithm | Any Str |
| haproxy.iid | unique proxy id | Any Str |
| haproxy.pid | process id (0 for first instance, 1 for second, ...) | Any Str |
| haproxy.proxy_name | Proxy name | Any Str |
| haproxy.service_name | Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener) | Any Str |
| haproxy.sid | server id (unique inside a proxy) | Any Str |
| haproxy.type | (0=frontend, 1=backend, 2=server, 3=socket/listener) | Any Str |
| haproxy.url | The path to the HAProxy socket or HTTP URL. | Any Str |
79 changes: 79 additions & 0 deletions receiver/haproxyreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver"

import (
"context"
"time"

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

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

const (
typeStr = "haproxy"
stability = component.StabilityLevelDevelopment
)

// NewFactory creates a new HAProxy receiver factory.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
typeStr,
newDefaultConfig,
receiver.WithMetrics(newReceiver, stability))
}

func newDefaultConfig() component.Config {
return &Config{
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)),
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)),
CollectionInterval: 1 * time.Minute,
},
MetricsSettings: metadata.DefaultMetricsSettings(),
}
}

func newReceiver(
_ context.Context,
settings receiver.CreateSettings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
haProxyCfg := cfg.(*Config)
metricsBuilder := metadata.NewMetricsBuilder(haProxyCfg.MetricsSettings, settings)

mp, err := newScraper(settings.ID, metricsBuilder, haProxyCfg, settings.TelemetrySettings.Logger)
if err != nil {
return nil, err
}
s, err := scraperhelper.NewScraper(settings.ID.Name(), mp.Scrape)
if err != nil {
return nil, err
}
opt := scraperhelper.AddScraper(s)

return scraperhelper.NewScraperControllerReceiver(
&haProxyCfg.ScraperControllerSettings,
settings,
consumer,
opt,
)
}
Loading

0 comments on commit 2b56579

Please sign in to comment.