-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into spartan0x117/cloudwatch-exporter-docsfix
- Loading branch information
Showing
21 changed files
with
407 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package linode | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/grafana/agent/component" | ||
"github.com/grafana/agent/component/common/config" | ||
"github.com/grafana/agent/component/discovery" | ||
"github.com/prometheus/common/model" | ||
prom_discovery "github.com/prometheus/prometheus/discovery/linode" | ||
) | ||
|
||
func init() { | ||
component.Register(component.Registration{ | ||
Name: "discovery.linode", | ||
Args: Arguments{}, | ||
Exports: discovery.Exports{}, | ||
|
||
Build: func(opts component.Options, args component.Arguments) (component.Component, error) { | ||
return New(opts, args.(Arguments)) | ||
}, | ||
}) | ||
} | ||
|
||
// Arguments configure the discovery.linode component. | ||
type Arguments struct { | ||
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"` | ||
Port int `river:"port,attr,optional"` | ||
TagSeparator string `river:"tag_separator,attr,optional"` | ||
HTTPClientConfig config.HTTPClientConfig `river:",squash"` | ||
} | ||
|
||
// DefaultArguments is used to initialize default values for Arguments. | ||
var DefaultArguments = Arguments{ | ||
TagSeparator: ",", | ||
Port: 80, | ||
RefreshInterval: 60 * time.Second, | ||
|
||
HTTPClientConfig: config.DefaultHTTPClientConfig, | ||
} | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Arguments) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
// Validate implements river.Validator. | ||
func (args *Arguments) Validate() error { | ||
if args.RefreshInterval <= 0 { | ||
return fmt.Errorf("refresh_interval must be greater than 0") | ||
} | ||
return args.HTTPClientConfig.Validate() | ||
} | ||
|
||
// Convert returns the upstream configuration struct. | ||
func (args *Arguments) Convert() *prom_discovery.SDConfig { | ||
return &prom_discovery.SDConfig{ | ||
RefreshInterval: model.Duration(args.RefreshInterval), | ||
Port: args.Port, | ||
TagSeparator: args.TagSeparator, | ||
HTTPClientConfig: *(args.HTTPClientConfig.Convert()), | ||
} | ||
} | ||
|
||
// New returns a new instance of a discovery.linode component. | ||
func New(opts component.Options, args Arguments) (*discovery.Component, error) { | ||
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) { | ||
newArgs := args.(Arguments) | ||
return prom_discovery.NewDiscovery(newArgs.Convert(), opts.Logger) | ||
}) | ||
} |
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 linode | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/agent/component/common/config" | ||
"github.com/grafana/river" | ||
promconfig "github.com/prometheus/common/config" | ||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRiverConfig(t *testing.T) { | ||
var exampleRiverConfig = ` | ||
refresh_interval = "10s" | ||
port = 8080 | ||
tag_separator = ";" | ||
` | ||
var args Arguments | ||
err := river.Unmarshal([]byte(exampleRiverConfig), &args) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestConvert(t *testing.T) { | ||
riverArgs := Arguments{ | ||
Port: 8080, | ||
RefreshInterval: 15 * time.Second, | ||
TagSeparator: ";", | ||
HTTPClientConfig: config.HTTPClientConfig{ | ||
BearerToken: "FOO", | ||
}, | ||
} | ||
|
||
promArgs := riverArgs.Convert() | ||
require.Equal(t, 8080, promArgs.Port) | ||
require.Equal(t, model.Duration(15*time.Second), promArgs.RefreshInterval) | ||
require.Equal(t, ";", promArgs.TagSeparator) | ||
require.Equal(t, promconfig.Secret("FOO"), promArgs.HTTPClientConfig.BearerToken) | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
t.Run("validate RefreshInterval", func(t *testing.T) { | ||
riverArgs := Arguments{ | ||
RefreshInterval: 0, | ||
} | ||
err := riverArgs.Validate() | ||
require.ErrorContains(t, err, "refresh_interval must be greater than 0") | ||
}) | ||
} |
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,36 @@ | ||
package prometheusconvert | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/agent/component/discovery/linode" | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/grafana/agent/converter/internal/common" | ||
prom_linode "github.com/prometheus/prometheus/discovery/linode" | ||
) | ||
|
||
func appendDiscoveryLinode(pb *prometheusBlocks, label string, sdConfig *prom_linode.SDConfig) discovery.Exports { | ||
discoveryLinodeArgs := ToDiscoveryLinode(sdConfig) | ||
name := []string{"discovery", "linode"} | ||
block := common.NewBlockWithOverride(name, label, discoveryLinodeArgs) | ||
pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) | ||
return NewDiscoveryExports("discovery.linode." + label + ".targets") | ||
} | ||
|
||
func validateDiscoveryLinode(sdConfig *prom_linode.SDConfig) diag.Diagnostics { | ||
return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) | ||
} | ||
|
||
func ToDiscoveryLinode(sdConfig *prom_linode.SDConfig) *linode.Arguments { | ||
if sdConfig == nil { | ||
return nil | ||
} | ||
|
||
return &linode.Arguments{ | ||
RefreshInterval: time.Duration(sdConfig.RefreshInterval), | ||
Port: sdConfig.Port, | ||
TagSeparator: sdConfig.TagSeparator, | ||
HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
converter/internal/prometheusconvert/testdata/linode.river
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,34 @@ | ||
discovery.linode "prometheus1" { | ||
refresh_interval = "1m40s" | ||
port = 8080 | ||
} | ||
|
||
discovery.linode "prometheus2" { } | ||
|
||
prometheus.scrape "prometheus1" { | ||
targets = concat( | ||
discovery.linode.prometheus1.targets, | ||
[{ | ||
__address__ = "localhost:9090", | ||
}], | ||
) | ||
forward_to = [prometheus.remote_write.default.receiver] | ||
job_name = "prometheus1" | ||
} | ||
|
||
prometheus.scrape "prometheus2" { | ||
targets = discovery.linode.prometheus2.targets | ||
forward_to = [prometheus.remote_write.default.receiver] | ||
job_name = "prometheus2" | ||
} | ||
|
||
prometheus.remote_write "default" { | ||
endpoint { | ||
name = "remote1" | ||
url = "http://remote-write-url1" | ||
|
||
queue_config { } | ||
|
||
metadata_config { } | ||
} | ||
} |
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,15 @@ | ||
scrape_configs: | ||
- job_name: "prometheus1" | ||
static_configs: | ||
- targets: ["localhost:9090"] | ||
linode_sd_configs: | ||
- refresh_interval: "100s" | ||
port: 8080 | ||
- job_name: "prometheus2" | ||
linode_sd_configs: | ||
- {} | ||
|
||
remote_write: | ||
- name: "remote1" | ||
url: "http://remote-write-url1" | ||
|
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
Oops, something went wrong.