Skip to content

Commit

Permalink
Add client_config block to remote_write (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Aug 4, 2022
1 parent 87fb377 commit 8c9399e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 14 additions & 0 deletions component/common/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"net/url"

"github.com/grafana/agent/pkg/river"

"github.com/grafana/agent/pkg/flow/rivertypes"
"github.com/prometheus/common/config"
)
Expand All @@ -23,6 +25,16 @@ type HTTPClientConfig struct {
EnableHTTP2 bool `river:"enable_http2,attr,optional"`
}

// UnmarshalRiver implements the umarshaller
func (h *HTTPClientConfig) UnmarshalRiver(f func(v interface{}) error) error {
*h = HTTPClientConfig{
FollowRedirects: true,
EnableHTTP2: true,
}
type config HTTPClientConfig
return f((*config)(h))
}

// Convert converts our type to the native prometheus type
func (h *HTTPClientConfig) Convert() *config.HTTPClientConfig {
return &config.HTTPClientConfig{
Expand All @@ -44,6 +56,8 @@ var DefaultHTTPClientConfig = HTTPClientConfig{
EnableHTTP2: true,
}

var _ river.Unmarshaler = (*HTTPClientConfig)(nil)

// BasicAuth configures Basic HTTP authentication credentials.
type BasicAuth struct {
Username string `river:"username,attr,optional"`
Expand Down
16 changes: 11 additions & 5 deletions component/metrics/remotewrite/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/prometheus/prometheus/config"

types "github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/metrics"
"github.com/grafana/agent/pkg/flow/rivertypes"
"github.com/grafana/agent/pkg/river"
Expand Down Expand Up @@ -41,11 +42,12 @@ type RemoteConfig struct {
// Config is the metrics_fowarder's configuration for where to send
// metrics stored in the WAL.
type Config struct {
Name string `river:"name,attr,optional"`
URL string `river:"url,attr"`
SendExemplars bool `river:"send_exemplars,attr,optional"`
BasicAuth *BasicAuthConfig `river:"basic_auth,block,optional"`
QueueConfig *QueueConfig `river:"queue_config,block,optional"`
Name string `river:"name,attr,optional"`
URL string `river:"url,attr"`
SendExemplars bool `river:"send_exemplars,attr,optional"`
BasicAuth *BasicAuthConfig `river:"basic_auth,block,optional"`
QueueConfig *QueueConfig `river:"queue_config,block,optional"`
HTTPClientConfig *types.HTTPClientConfig `river:"client_config,block,optional"`
}

// QueueConfig handles the low level queue config options for a remote_write
Expand Down Expand Up @@ -131,6 +133,10 @@ func convertConfigs(cfg RemoteConfig) (*config.Config, error) {
}
}

if rw.HTTPClientConfig != nil {
rwc.HTTPClientConfig = *rw.HTTPClientConfig.Convert()
}

rwc.SendExemplars = rw.SendExemplars

rwConfigs = append(rwConfigs, rwc)
Expand Down

0 comments on commit 8c9399e

Please sign in to comment.