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

ApplyConfig for integrations #486

Merged
merged 5 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions pkg/integrations/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package agent

import (
"context"
"net/http"

"github.com/go-kit/kit/log"
"github.com/gorilla/mux"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/config"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -48,14 +48,9 @@ func New(c *Config) *Integration {
return &Integration{c: c}
}

// RegisterRoutes satisfies Integration.RegisterRoutes.
func (i *Integration) RegisterRoutes(r *mux.Router) error {
// Note that if the weaveworks common server is set to not register
// instrumentation endpoints, this lets the agent integration still be able
// to scrape itself, just at /integrations/agent/metrics.
r.Handle("/metrics", promhttp.Handler())

return nil
// MetricsHandler satisfies Integration.RegisterRoutes.
func (i *Integration) MetricsHandler() (http.Handler, error) {
return promhttp.Handler(), nil
}

// ScrapeConfigs satisfies Integration.ScrapeConfigs.
Expand Down
17 changes: 2 additions & 15 deletions pkg/integrations/collector_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"

"github.com/gorilla/mux"
"github.com/grafana/agent/pkg/integrations/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -61,20 +60,8 @@ func WithExporterMetricsIncluded(included bool) CollectorIntegrationConfig {
}
}

// RegisterRoutes satisfies Integration.RegisterRoutes. The mux.Router provided
// here is expected to be a subrouter, where all registered paths will be
// registered within that subroute.
func (i *CollectorIntegration) RegisterRoutes(r *mux.Router) error {
handler, err := i.handler()
if err != nil {
return err
}

r.Handle("/metrics", handler)
return nil
}

func (i *CollectorIntegration) handler() (http.Handler, error) {
// MetricsHandler returns the HTTP handler for the integration.
func (i *CollectorIntegration) MetricsHandler() (http.Handler, error) {
r := prometheus.NewRegistry()
for _, c := range i.cs {
if err := r.Register(c); err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/integrations/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package integrations

import (
"context"
"net/http"

"github.com/go-kit/kit/log"
"github.com/gorilla/mux"
"github.com/grafana/agent/pkg/integrations/config"
)

Expand All @@ -25,11 +25,8 @@ type Config interface {
// An Integration is a process that integrates with some external system and
// pulls telemetry data.
type Integration interface {
// RegisterRoutes should register any HTTP handlers needed for the
// integrations. The mux router provided will be a subrouter for the path
// /integrations/<integration name>, where the integration name is retrieved
// by the config that created this integration.
RegisterRoutes(r *mux.Router) error
// MetricsHandler returns an http.Handler that will return metrics.
MetricsHandler() (http.Handler, error)

// ScrapeConfigs returns a set of scrape configs that determine where metrics
// can be scraped.
Expand Down
Loading