-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add Catchpoint Exporter (#1027)
- Loading branch information
1 parent
80c313d
commit c636f0e
Showing
11 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
docs/sources/reference/components/prometheus.exporter.catchpoint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
canonical: https://grafana.com/docs/alloy/latest/reference/components/prometheus.exporter.catchpoint/ | ||
description: Learn about prometheus.exporter.catchpoint | ||
title: prometheus.exporter.catchpoint | ||
--- | ||
|
||
# prometheus.exporter.catchpoint | ||
|
||
{{< docs/shared lookup="stability/experimental.md" source="alloy" version="<ALLOY_VERSION>" >}} | ||
|
||
The `prometheus.exporter.catchpoint` component uses the [catchpoint_exporter](https://github.com/grafana/catchpoint-prometheus-exporter) for collecting statistics from a Catchpoint account. | ||
|
||
## Usage | ||
|
||
```alloy | ||
prometheus.exporter.catchpoint "<LABEL>" { | ||
port = PORT | ||
verbose_logging = <VERBOSE_LOGGING> | ||
webhook_path = <WEBHOOK_PATH> | ||
} | ||
``` | ||
|
||
## Arguments | ||
|
||
The following arguments can be used to configure the exporter's behavior. | ||
Omitted fields take their default values. | ||
|
||
| Name | Type | Description | Default | Required | | ||
| ----------------- | -------- | ------------------------------------------------------------------------------- | ----------------------- | -------- | | ||
| `port` | `string` | Sets the port on which the exporter will run. | `"9090"` | no | | ||
| `verbose_logging` | `bool` | Enables verbose logging to provide more detailed output for debugging purposes. | `false` | no | | ||
| `webhook_path` | `string` | Defines the path where the exporter will receive webhook data from Catchpoint | `"/catchpoint-webhook"` | no | | ||
|
||
## Blocks | ||
|
||
The `prometheus.exporter.catchpoint` component does not support any blocks, and is configured | ||
fully through arguments. | ||
|
||
## Exported fields | ||
|
||
{{< docs/shared lookup="reference/components/exporter-component-exports.md" source="alloy" version="<ALLOY_VERSION>" >}} | ||
|
||
## Component health | ||
|
||
`prometheus.exporter.catchpoint` is only reported as unhealthy if given | ||
an invalid configuration. In those cases, exported fields retain their last | ||
healthy values. | ||
|
||
## Debug information | ||
|
||
`prometheus.exporter.catchpoint` does not expose any component-specific | ||
debug information. | ||
|
||
## Debug metrics | ||
|
||
`prometheus.exporter.catchpoint` does not expose any component-specific | ||
debug metrics. | ||
|
||
## Example | ||
|
||
This example uses a [`prometheus.scrape` component][scrape] to collect metrics | ||
from `prometheus.exporter.catchpoint`: | ||
|
||
```alloy | ||
prometheus.exporter.catchpoint "example" { | ||
port = "9090" | ||
verbose_logging = false | ||
webhook_path = "/catchpoint-webhook" | ||
} | ||
// Configure a prometheus.scrape component to collect catchpoint metrics. | ||
prometheus.scrape "demo" { | ||
targets = prometheus.exporter.catchpoint.example.targets | ||
forward_to = [prometheus.remote_write.demo.receiver] | ||
} | ||
prometheus.remote_write "demo" { | ||
endpoint { | ||
url = <PROMETHEUS_REMOTE_WRITE_URL> | ||
basic_auth { | ||
username = <USERNAME> | ||
password = <PASSWORD> | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Replace the following: | ||
|
||
- _`<PROMETHEUS_REMOTE_WRITE_URL>`_: The URL of the Prometheus remote_write-compatible server to send metrics to. | ||
- _`<USERNAME>`_: The username to use for authentication to the remote_write API. | ||
- _`<PASSWORD>`_: The password to use for authentication to the remote_write API. | ||
|
||
[scrape]: ../prometheus.scrape/ | ||
|
||
<!-- START GENERATED COMPATIBLE COMPONENTS --> | ||
|
||
## Compatible components | ||
|
||
`prometheus.exporter.catchpoint` has exports that can be consumed by the following components: | ||
|
||
- Components that consume [Targets](../../compatibility/#targets-consumers) | ||
|
||
{{< admonition type="note" >}} | ||
Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. | ||
Refer to the linked documentation for more details. | ||
{{< /admonition >}} | ||
|
||
<!-- END GENERATED COMPATIBLE COMPONENTS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
internal/component/prometheus/exporter/catchpoint/catchpoint.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package catchpoint | ||
|
||
import ( | ||
"github.com/grafana/alloy/internal/component" | ||
"github.com/grafana/alloy/internal/component/prometheus/exporter" | ||
"github.com/grafana/alloy/internal/featuregate" | ||
"github.com/grafana/alloy/internal/static/integrations" | ||
"github.com/grafana/alloy/internal/static/integrations/catchpoint_exporter" | ||
) | ||
|
||
func init() { | ||
component.Register(component.Registration{ | ||
Name: "prometheus.exporter.catchpoint", | ||
Stability: featuregate.StabilityExperimental, | ||
Args: Arguments{}, | ||
Exports: exporter.Exports{}, | ||
Build: exporter.New(createExporter, "catchpoint"), | ||
}) | ||
} | ||
|
||
func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) { | ||
a := args.(Arguments) | ||
return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey) | ||
} | ||
|
||
// DefaultArguments holds the default settings for the catchpoint exporter | ||
var DefaultArguments = Arguments{ | ||
VerboseLogging: false, | ||
WebhookPath: "/catchpoint-webhook", | ||
Port: "9090", | ||
} | ||
|
||
// Arguments controls the catchpoint exporter. | ||
type Arguments struct { | ||
VerboseLogging bool `alloy:"verbose_logging,attr,optional"` | ||
WebhookPath string `alloy:"webhook_path,attr,optional"` | ||
Port string `alloy:"port,attr,optional"` | ||
} | ||
|
||
// SetToDefault implements syntax.Defaulter. | ||
func (a *Arguments) SetToDefault() { | ||
*a = DefaultArguments | ||
} | ||
|
||
func (a *Arguments) Convert() *catchpoint_exporter.Config { | ||
return &catchpoint_exporter.Config{ | ||
VerboseLogging: a.VerboseLogging, | ||
WebhookPath: a.WebhookPath, | ||
Port: a.Port, | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/component/prometheus/exporter/catchpoint/catchpoint_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package catchpoint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/grafana/alloy/internal/static/integrations/catchpoint_exporter" | ||
"github.com/grafana/alloy/syntax" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRiverUnmarshal(t *testing.T) { | ||
alloyConfig := ` | ||
port = "3030" | ||
verbose_logging = true | ||
webhook_path = "/nondefault-webhook-path" | ||
` | ||
|
||
var args Arguments | ||
err := syntax.Unmarshal([]byte(alloyConfig), &args) | ||
require.NoError(t, err) | ||
|
||
expected := Arguments{ | ||
VerboseLogging: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
} | ||
|
||
require.Equal(t, expected, args) | ||
} | ||
|
||
func TestConvert(t *testing.T) { | ||
alloyConfig := ` | ||
port = "3030" | ||
verbose_logging = true | ||
webhook_path = "/nondefault-webhook-path" | ||
` | ||
|
||
var args Arguments | ||
err := syntax.Unmarshal([]byte(alloyConfig), &args) | ||
require.NoError(t, err) | ||
|
||
res := args.Convert() | ||
|
||
expected := catchpoint_exporter.Config{ | ||
VerboseLogging: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
} | ||
require.Equal(t, expected, *res) | ||
} |
66 changes: 66 additions & 0 deletions
66
internal/static/integrations/catchpoint_exporter/catchpoint_exporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package catchpoint_exporter | ||
|
||
import ( | ||
"github.com/go-kit/log" | ||
"github.com/grafana/alloy/internal/static/integrations" | ||
integrations_v2 "github.com/grafana/alloy/internal/static/integrations/v2" | ||
"github.com/grafana/alloy/internal/static/integrations/v2/metricsutils" | ||
|
||
collector "github.com/grafana/catchpoint-prometheus-exporter/collector" | ||
) | ||
|
||
// DefaultConfig is the default config for the catchpoint integration | ||
var DefaultConfig = Config{ | ||
VerboseLogging: false, | ||
WebhookPath: "/catchpoint-webhook", | ||
Port: "9090", | ||
} | ||
|
||
// Config is the configuration for the catchpoint integration | ||
type Config struct { | ||
VerboseLogging bool `yaml:"verbose_logging,omitempty"` | ||
WebhookPath string `yaml:"webhook_path,omitempty"` | ||
Port string `yaml:"port,omitempty"` | ||
} | ||
|
||
func (c *Config) exporterConfig() *collector.Config { | ||
return &collector.Config{ | ||
VerboseLogging: c.VerboseLogging, | ||
WebhookPath: c.WebhookPath, | ||
Port: c.Port, | ||
} | ||
} | ||
|
||
// Identifier returns a string that identifies the integration. | ||
func (c *Config) InstanceKey(agentKey string) (string, error) { | ||
return c.Port, nil | ||
} | ||
|
||
// UnmarshalYAML implements yaml.Unmarshaler for Config | ||
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
*c = DefaultConfig | ||
|
||
type plain Config | ||
return unmarshal((*plain)(c)) | ||
} | ||
|
||
// Name returns the name of the integration this config is for. | ||
func (c *Config) Name() string { | ||
return "catchpoint" | ||
} | ||
|
||
func init() { | ||
integrations.RegisterIntegration(&Config{}) | ||
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("catchpoint")) | ||
} | ||
|
||
// NewIntegration creates a new integration from the config. | ||
func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) { | ||
exporterConfig := c.exporterConfig() | ||
|
||
col := collector.NewCollector(l, exporterConfig) | ||
return integrations.NewCollectorIntegration( | ||
c.Name(), | ||
integrations.WithCollectors(col), | ||
), nil | ||
} |
52 changes: 52 additions & 0 deletions
52
internal/static/integrations/catchpoint_exporter/catchpoint_exporter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package catchpoint_exporter | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestConfig_UnmarshalYaml(t *testing.T) { | ||
strConfig := ` | ||
port: "3030" | ||
verbose_logging: true | ||
webhook_path: "/nondefault-webhook-path"` | ||
|
||
var c Config | ||
|
||
require.NoError(t, yaml.UnmarshalStrict([]byte(strConfig), &c)) | ||
|
||
require.Equal(t, Config{ | ||
VerboseLogging: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
}, c) | ||
} | ||
|
||
func TestConfig_NewIntegration(t *testing.T) { | ||
t.Run("integration with valid config", func(t *testing.T) { | ||
c := &Config{ | ||
VerboseLogging: true, | ||
Port: "3030", | ||
WebhookPath: "/nondefault-webhook-path", | ||
} | ||
|
||
i, err := c.NewIntegration(log.NewJSONLogger(os.Stdout)) | ||
require.NoError(t, err) | ||
require.NotNil(t, i) | ||
}) | ||
|
||
} | ||
|
||
func TestConfig_AgentKey(t *testing.T) { | ||
c := DefaultConfig | ||
c.Port = "3030" | ||
|
||
ik := "agent-key" | ||
id, err := c.InstanceKey(ik) | ||
require.NoError(t, err) | ||
require.Equal(t, "3030", id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters