Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/integration.go
5287 views
1
package integrations
2
3
import (
4
"context"
5
"net/http"
6
7
"github.com/go-kit/log"
8
"github.com/grafana/agent/pkg/integrations/config"
9
)
10
11
// Config provides the configuration and constructor for an integration.
12
type Config interface {
13
// Name returns the name of the integration and the key that will be used to
14
// pull the configuration from the Agent config YAML.
15
Name() string
16
17
// InstanceKey should return the key that represents the config, which will be
18
// used to populate the value of the `instance` label for metrics.
19
//
20
// InstanceKey is given an agentKey that represents the agent process. This
21
// may be used if the integration being configured applies to an entire
22
// machine.
23
//
24
// This method may not be invoked if the instance key for a Config is
25
// overridden.
26
InstanceKey(agentKey string) (string, error)
27
28
// NewIntegration returns an integration for the given with the given logger.
29
NewIntegration(l log.Logger) (Integration, error)
30
}
31
32
// An Integration is a process that integrates with some external system and
33
// pulls telemetry data.
34
type Integration interface {
35
// MetricsHandler returns an http.Handler that will return metrics.
36
MetricsHandler() (http.Handler, error)
37
38
// ScrapeConfigs returns a set of scrape configs that determine where metrics
39
// can be scraped.
40
ScrapeConfigs() []config.ScrapeConfig
41
42
// Run should start the integration and do any required tasks, if necessary.
43
// For example, an Integration that requires a persistent connection to a
44
// database would establish that connection here. If the integration doesn't
45
// need to do anything, it should wait for the ctx to be canceled.
46
//
47
// An error will be returned if the integration failed. Integrations should
48
// not return the ctx error.
49
Run(ctx context.Context) error
50
}
51
52