diff --git a/converter/internal/common/convert_targets.go b/converter/internal/common/convert_targets.go index 1ffe5d6819e2..8956cc0e20c6 100644 --- a/converter/internal/common/convert_targets.go +++ b/converter/internal/common/convert_targets.go @@ -7,6 +7,24 @@ import ( "github.com/grafana/river/token/builder" ) +// NewDiscoveryExports will return a new [discovery.Exports] with a specific +// key for converter component exports. The argument will be tokenized +// as a component export string rather than the standard [discovery.Target] +// RiverTokenize. +func NewDiscoveryExports(expr string) discovery.Exports { + return discovery.Exports{ + Targets: NewDiscoveryTargets(expr), + } +} + +// NewDiscoveryTargets will return a new [[]discovery.Target] with a specific +// key for converter component exports. The argument will be tokenized +// as a component export string rather than the standard [discovery.Target] +// RiverTokenize. +func NewDiscoveryTargets(expr string) []discovery.Target { + return []discovery.Target{map[string]string{"__expr__": expr}} +} + // ConvertTargets implements [builder.Tokenizer]. This allows us to set // component.Arguments with an implementation that can be tokenized with // custom behaviour for converting. diff --git a/converter/internal/prometheusconvert/common.go b/converter/internal/common/http_client_config.go similarity index 80% rename from converter/internal/prometheusconvert/common.go rename to converter/internal/common/http_client_config.go index 63a78ce2daa2..ce082f0c68bb 100644 --- a/converter/internal/prometheusconvert/common.go +++ b/converter/internal/common/http_client_config.go @@ -1,8 +1,7 @@ -package prometheusconvert +package common import ( "github.com/grafana/agent/component/common/config" - "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/converter/diag" "github.com/grafana/river/rivertypes" prom_config "github.com/prometheus/common/config" @@ -108,21 +107,3 @@ func ToTLSConfig(tlsConfig *prom_config.TLSConfig) *config.TLSConfig { MinVersion: config.TLSVersion(tlsConfig.MinVersion), } } - -// NewDiscoveryExports will return a new [discovery.Exports] with a specific -// key for converter component exports. The argument will be tokenized -// as a component export string rather than the standard [discovery.Target] -// RiverTokenize. -func NewDiscoveryExports(expr string) discovery.Exports { - return discovery.Exports{ - Targets: newDiscoveryTargets(expr), - } -} - -// newDiscoveryTargets will return a new [[]discovery.Target] with a specific -// key for converter component exports. The argument will be tokenized -// as a component export string rather than the standard [discovery.Target] -// RiverTokenize. -func newDiscoveryTargets(expr string) []discovery.Target { - return []discovery.Target{map[string]string{"__expr__": expr}} -} diff --git a/converter/internal/prometheusconvert/prometheus_blocks.go b/converter/internal/prometheusconvert/build/prometheus_blocks.go similarity index 58% rename from converter/internal/prometheusconvert/prometheus_blocks.go rename to converter/internal/prometheusconvert/build/prometheus_blocks.go index cf2b5388a28d..076045f3225c 100644 --- a/converter/internal/prometheusconvert/prometheus_blocks.go +++ b/converter/internal/prometheusconvert/build/prometheus_blocks.go @@ -1,4 +1,4 @@ -package prometheusconvert +package build import ( "fmt" @@ -8,24 +8,24 @@ import ( "github.com/grafana/river/token/builder" ) -// prometheusBlocks is a type for categorizing River Blocks before appending +// PrometheusBlocks is a type for categorizing River Blocks before appending // them to a River File. This gives control over the order they are written // versus appending them in the order the Blocks are created. -type prometheusBlocks struct { - discoveryBlocks []prometheusBlock - discoveryRelabelBlocks []prometheusBlock - prometheusScrapeBlocks []prometheusBlock - prometheusRelabelBlocks []prometheusBlock - prometheusRemoteWriteBlocks []prometheusBlock +type PrometheusBlocks struct { + DiscoveryBlocks []prometheusBlock + DiscoveryRelabelBlocks []prometheusBlock + PrometheusScrapeBlocks []prometheusBlock + PrometheusRelabelBlocks []prometheusBlock + PrometheusRemoteWriteBlocks []prometheusBlock } -func NewPrometheusBlocks() *prometheusBlocks { - return &prometheusBlocks{ - discoveryBlocks: []prometheusBlock{}, - discoveryRelabelBlocks: []prometheusBlock{}, - prometheusScrapeBlocks: []prometheusBlock{}, - prometheusRelabelBlocks: []prometheusBlock{}, - prometheusRemoteWriteBlocks: []prometheusBlock{}, +func NewPrometheusBlocks() *PrometheusBlocks { + return &PrometheusBlocks{ + DiscoveryBlocks: []prometheusBlock{}, + DiscoveryRelabelBlocks: []prometheusBlock{}, + PrometheusScrapeBlocks: []prometheusBlock{}, + PrometheusRelabelBlocks: []prometheusBlock{}, + PrometheusRemoteWriteBlocks: []prometheusBlock{}, } } @@ -37,47 +37,47 @@ func NewPrometheusBlocks() *prometheusBlocks { // 3. Prometheus scrape component(s) // 4. Prometheus relabel component(s) (if any) // 5. Prometheus remote_write -func (pb *prometheusBlocks) AppendToFile(f *builder.File) { - for _, promBlock := range pb.discoveryBlocks { +func (pb *PrometheusBlocks) AppendToFile(f *builder.File) { + for _, promBlock := range pb.DiscoveryBlocks { f.Body().AppendBlock(promBlock.block) } - for _, promBlock := range pb.discoveryRelabelBlocks { + for _, promBlock := range pb.DiscoveryRelabelBlocks { f.Body().AppendBlock(promBlock.block) } - for _, promBlock := range pb.prometheusScrapeBlocks { + for _, promBlock := range pb.PrometheusScrapeBlocks { f.Body().AppendBlock(promBlock.block) } - for _, promBlock := range pb.prometheusRelabelBlocks { + for _, promBlock := range pb.PrometheusRelabelBlocks { f.Body().AppendBlock(promBlock.block) } - for _, promBlock := range pb.prometheusRemoteWriteBlocks { + for _, promBlock := range pb.PrometheusRemoteWriteBlocks { f.Body().AppendBlock(promBlock.block) } } -func (pb *prometheusBlocks) getScrapeInfo() diag.Diagnostics { +func (pb *PrometheusBlocks) GetScrapeInfo() diag.Diagnostics { var diags diag.Diagnostics - for _, promScrapeBlock := range pb.prometheusScrapeBlocks { + for _, promScrapeBlock := range pb.PrometheusScrapeBlocks { detail := promScrapeBlock.detail - for _, promDiscoveryBlock := range pb.discoveryBlocks { + for _, promDiscoveryBlock := range pb.DiscoveryBlocks { if strings.HasPrefix(promDiscoveryBlock.label, promScrapeBlock.label) { detail = fmt.Sprintln(detail) + fmt.Sprintf(" A %s.%s component", strings.Join(promDiscoveryBlock.name, "."), promDiscoveryBlock.label) } } - for _, promDiscoveryRelabelBlock := range pb.discoveryRelabelBlocks { + for _, promDiscoveryRelabelBlock := range pb.DiscoveryRelabelBlocks { if strings.HasPrefix(promDiscoveryRelabelBlock.label, promScrapeBlock.label) { detail = fmt.Sprintln(detail) + fmt.Sprintf(" A %s.%s component", strings.Join(promDiscoveryRelabelBlock.name, "."), promDiscoveryRelabelBlock.label) } } - for _, promRelabelBlock := range pb.prometheusRelabelBlocks { + for _, promRelabelBlock := range pb.PrometheusRelabelBlocks { if strings.HasPrefix(promRelabelBlock.label, promScrapeBlock.label) { detail = fmt.Sprintln(detail) + fmt.Sprintf(" A %s.%s component", strings.Join(promRelabelBlock.name, "."), promRelabelBlock.label) } @@ -86,7 +86,7 @@ func (pb *prometheusBlocks) getScrapeInfo() diag.Diagnostics { diags.AddWithDetail(diag.SeverityLevelInfo, promScrapeBlock.summary, detail) } - for _, promRemoteWriteBlock := range pb.prometheusRemoteWriteBlocks { + for _, promRemoteWriteBlock := range pb.PrometheusRemoteWriteBlocks { diags.AddWithDetail(diag.SeverityLevelInfo, promRemoteWriteBlock.summary, promRemoteWriteBlock.detail) } @@ -101,7 +101,7 @@ type prometheusBlock struct { detail string } -func newPrometheusBlock(block *builder.Block, name []string, label string, summary string, detail string) prometheusBlock { +func NewPrometheusBlock(block *builder.Block, name []string, label string, summary string, detail string) prometheusBlock { return prometheusBlock{ block: block, name: name, diff --git a/converter/internal/prometheusconvert/azure.go b/converter/internal/prometheusconvert/component/azure.go similarity index 73% rename from converter/internal/prometheusconvert/azure.go rename to converter/internal/prometheusconvert/component/azure.go index 17c41e4a042d..754c9765f32c 100644 --- a/converter/internal/prometheusconvert/azure.go +++ b/converter/internal/prometheusconvert/component/azure.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -8,16 +8,17 @@ import ( "github.com/grafana/agent/component/discovery/azure" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_azure "github.com/prometheus/prometheus/discovery/azure" ) -func appendDiscoveryAzure(pb *prometheusBlocks, label string, sdConfig *prom_azure.SDConfig) discovery.Exports { +func appendDiscoveryAzure(pb *build.PrometheusBlocks, label string, sdConfig *prom_azure.SDConfig) discovery.Exports { discoveryAzureArgs := toDiscoveryAzure(sdConfig) name := []string{"discovery", "azure"} block := common.NewBlockWithOverride(name, label, discoveryAzureArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.azure." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.azure." + label + ".targets") } func toDiscoveryAzure(sdConfig *prom_azure.SDConfig) *azure.Arguments { @@ -36,12 +37,12 @@ func toDiscoveryAzure(sdConfig *prom_azure.SDConfig) *azure.Arguments { ProxyURL: config.URL(sdConfig.HTTPClientConfig.ProxyURL), FollowRedirects: sdConfig.HTTPClientConfig.FollowRedirects, EnableHTTP2: sdConfig.HTTPClientConfig.EnableHTTP2, - TLSConfig: *ToTLSConfig(&sdConfig.HTTPClientConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&sdConfig.HTTPClientConfig.TLSConfig), } } -func validateDiscoveryAzure(sdConfig *prom_azure.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryAzure(sdConfig *prom_azure.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toManagedIdentity(sdConfig *prom_azure.SDConfig) *azure.ManagedIdentity { diff --git a/converter/internal/prometheusconvert/consul.go b/converter/internal/prometheusconvert/component/consul.go similarity index 68% rename from converter/internal/prometheusconvert/consul.go rename to converter/internal/prometheusconvert/component/consul.go index dad35e109978..dc738869e872 100644 --- a/converter/internal/prometheusconvert/consul.go +++ b/converter/internal/prometheusconvert/component/consul.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,20 +7,21 @@ import ( "github.com/grafana/agent/component/discovery/consul" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_consul "github.com/prometheus/prometheus/discovery/consul" ) -func appendDiscoveryConsul(pb *prometheusBlocks, label string, sdConfig *prom_consul.SDConfig) discovery.Exports { +func appendDiscoveryConsul(pb *build.PrometheusBlocks, label string, sdConfig *prom_consul.SDConfig) discovery.Exports { discoveryConsulArgs := toDiscoveryConsul(sdConfig) name := []string{"discovery", "consul"} block := common.NewBlockWithOverride(name, label, discoveryConsulArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.consul." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.consul." + label + ".targets") } -func validateDiscoveryConsul(sdConfig *prom_consul.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryConsul(sdConfig *prom_consul.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryConsul(sdConfig *prom_consul.SDConfig) *consul.Arguments { @@ -43,6 +44,6 @@ func toDiscoveryConsul(sdConfig *prom_consul.SDConfig) *consul.Arguments { ServiceTags: sdConfig.ServiceTags, NodeMeta: sdConfig.NodeMeta, RefreshInterval: time.Duration(sdConfig.RefreshInterval), - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), } } diff --git a/converter/internal/prometheusconvert/digitalocean.go b/converter/internal/prometheusconvert/component/digitalocean.go similarity index 77% rename from converter/internal/prometheusconvert/digitalocean.go rename to converter/internal/prometheusconvert/component/digitalocean.go index c34e90ef6a70..2529442bfa22 100644 --- a/converter/internal/prometheusconvert/digitalocean.go +++ b/converter/internal/prometheusconvert/component/digitalocean.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "reflect" @@ -9,20 +9,21 @@ import ( "github.com/grafana/agent/component/discovery/digitalocean" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_config "github.com/prometheus/common/config" prom_digitalocean "github.com/prometheus/prometheus/discovery/digitalocean" ) -func appendDiscoveryDigitalOcean(pb *prometheusBlocks, label string, sdConfig *prom_digitalocean.SDConfig) discovery.Exports { +func appendDiscoveryDigitalOcean(pb *build.PrometheusBlocks, label string, sdConfig *prom_digitalocean.SDConfig) discovery.Exports { discoveryDigitalOceanArgs := toDiscoveryDigitalOcean(sdConfig) name := []string{"discovery", "digitalocean"} block := common.NewBlockWithOverride(name, label, discoveryDigitalOceanArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.digitalocean." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.digitalocean." + label + ".targets") } -func validateDiscoveryDigitalOcean(sdConfig *prom_digitalocean.SDConfig) diag.Diagnostics { +func ValidateDiscoveryDigitalOcean(sdConfig *prom_digitalocean.SDConfig) diag.Diagnostics { var diags diag.Diagnostics if sdConfig.HTTPClientConfig.BasicAuth != nil { @@ -41,7 +42,7 @@ func validateDiscoveryDigitalOcean(sdConfig *prom_digitalocean.SDConfig) diag.Di diags.Add(diag.SeverityLevelError, "unsupported oauth2 for digitalocean_sd_configs") } - diags.AddAll(ValidateHttpClientConfig(&sdConfig.HTTPClientConfig)) + diags.AddAll(common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig)) return diags } diff --git a/converter/internal/prometheusconvert/dns.go b/converter/internal/prometheusconvert/component/dns.go similarity index 63% rename from converter/internal/prometheusconvert/dns.go rename to converter/internal/prometheusconvert/component/dns.go index 70e5a145ccef..c22624015a19 100644 --- a/converter/internal/prometheusconvert/dns.go +++ b/converter/internal/prometheusconvert/component/dns.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,18 +7,19 @@ import ( "github.com/grafana/agent/component/discovery/dns" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_dns "github.com/prometheus/prometheus/discovery/dns" ) -func appendDiscoveryDns(pb *prometheusBlocks, label string, sdConfig *prom_dns.SDConfig) discovery.Exports { +func appendDiscoveryDns(pb *build.PrometheusBlocks, label string, sdConfig *prom_dns.SDConfig) discovery.Exports { discoveryDnsArgs := toDiscoveryDns(sdConfig) name := []string{"discovery", "dns"} block := common.NewBlockWithOverride(name, label, discoveryDnsArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.dns." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.dns." + label + ".targets") } -func validateDiscoveryDns(sdConfig *prom_dns.SDConfig) diag.Diagnostics { +func ValidateDiscoveryDns(sdConfig *prom_dns.SDConfig) diag.Diagnostics { return make(diag.Diagnostics, 0) } diff --git a/converter/internal/prometheusconvert/docker.go b/converter/internal/prometheusconvert/component/docker.go similarity index 65% rename from converter/internal/prometheusconvert/docker.go rename to converter/internal/prometheusconvert/component/docker.go index ec58f0b2b9e2..206cf9fdf415 100644 --- a/converter/internal/prometheusconvert/docker.go +++ b/converter/internal/prometheusconvert/component/docker.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,19 +7,20 @@ import ( "github.com/grafana/agent/component/discovery/docker" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_docker "github.com/prometheus/prometheus/discovery/moby" ) -func appendDiscoveryDocker(pb *prometheusBlocks, label string, sdConfig *prom_docker.DockerSDConfig) discovery.Exports { +func appendDiscoveryDocker(pb *build.PrometheusBlocks, label string, sdConfig *prom_docker.DockerSDConfig) discovery.Exports { discoveryDockerArgs := toDiscoveryDocker(sdConfig) name := []string{"discovery", "docker"} block := common.NewBlockWithOverride(name, label, discoveryDockerArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.docker." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.docker." + label + ".targets") } -func validateDiscoveryDocker(sdConfig *prom_docker.DockerSDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryDocker(sdConfig *prom_docker.DockerSDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryDocker(sdConfig *prom_docker.DockerSDConfig) *docker.Arguments { @@ -33,7 +34,7 @@ func toDiscoveryDocker(sdConfig *prom_docker.DockerSDConfig) *docker.Arguments { HostNetworkingHost: sdConfig.HostNetworkingHost, RefreshInterval: time.Duration(sdConfig.RefreshInterval), Filters: toDockerFilters(sdConfig.Filters), - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), } } diff --git a/converter/internal/prometheusconvert/dockerswarm.go b/converter/internal/prometheusconvert/component/dockerswarm.go similarity index 69% rename from converter/internal/prometheusconvert/dockerswarm.go rename to converter/internal/prometheusconvert/component/dockerswarm.go index 43ecf149cda4..18af10be48f4 100644 --- a/converter/internal/prometheusconvert/dockerswarm.go +++ b/converter/internal/prometheusconvert/component/dockerswarm.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,19 +7,20 @@ import ( "github.com/grafana/agent/component/discovery/dockerswarm" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_moby "github.com/prometheus/prometheus/discovery/moby" ) -func appendDiscoveryDockerswarm(pb *prometheusBlocks, label string, sdConfig *prom_moby.DockerSwarmSDConfig) discovery.Exports { +func appendDiscoveryDockerswarm(pb *build.PrometheusBlocks, label string, sdConfig *prom_moby.DockerSwarmSDConfig) discovery.Exports { discoveryDockerswarmArgs := toDiscoveryDockerswarm(sdConfig) name := []string{"discovery", "dockerswarm"} block := common.NewBlockWithOverride(name, label, discoveryDockerswarmArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.dockerswarm." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.dockerswarm." + label + ".targets") } -func validateDiscoveryDockerswarm(sdConfig *prom_moby.DockerSwarmSDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryDockerswarm(sdConfig *prom_moby.DockerSwarmSDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryDockerswarm(sdConfig *prom_moby.DockerSwarmSDConfig) *dockerswarm.Arguments { @@ -33,7 +34,7 @@ func toDiscoveryDockerswarm(sdConfig *prom_moby.DockerSwarmSDConfig) *dockerswar Port: sdConfig.Port, Filters: convertFilters(sdConfig.Filters), RefreshInterval: time.Duration(sdConfig.RefreshInterval), - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), } } diff --git a/converter/internal/prometheusconvert/ec2.go b/converter/internal/prometheusconvert/component/ec2.go similarity index 87% rename from converter/internal/prometheusconvert/ec2.go rename to converter/internal/prometheusconvert/component/ec2.go index f1641a9fb4ff..f7f820ce98d9 100644 --- a/converter/internal/prometheusconvert/ec2.go +++ b/converter/internal/prometheusconvert/component/ec2.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "reflect" @@ -8,20 +8,21 @@ import ( "github.com/grafana/agent/component/discovery/aws" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_config "github.com/prometheus/common/config" prom_aws "github.com/prometheus/prometheus/discovery/aws" ) -func appendDiscoveryEC2(pb *prometheusBlocks, label string, sdConfig *prom_aws.EC2SDConfig) discovery.Exports { +func appendDiscoveryEC2(pb *build.PrometheusBlocks, label string, sdConfig *prom_aws.EC2SDConfig) discovery.Exports { discoveryec2Args := toDiscoveryEC2(sdConfig) name := []string{"discovery", "ec2"} block := common.NewBlockWithOverride(name, label, discoveryec2Args) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.ec2." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.ec2." + label + ".targets") } -func validateDiscoveryEC2(sdConfig *prom_aws.EC2SDConfig) diag.Diagnostics { +func ValidateDiscoveryEC2(sdConfig *prom_aws.EC2SDConfig) diag.Diagnostics { var diags diag.Diagnostics if sdConfig.HTTPClientConfig.BasicAuth != nil { diff --git a/converter/internal/prometheusconvert/file.go b/converter/internal/prometheusconvert/component/file.go similarity index 61% rename from converter/internal/prometheusconvert/file.go rename to converter/internal/prometheusconvert/component/file.go index 4c5283e60f03..9d5f606ab608 100644 --- a/converter/internal/prometheusconvert/file.go +++ b/converter/internal/prometheusconvert/component/file.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,18 +7,19 @@ import ( "github.com/grafana/agent/component/discovery/file" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_file "github.com/prometheus/prometheus/discovery/file" ) -func appendDiscoveryFile(pb *prometheusBlocks, label string, sdConfig *prom_file.SDConfig) discovery.Exports { +func appendDiscoveryFile(pb *build.PrometheusBlocks, label string, sdConfig *prom_file.SDConfig) discovery.Exports { discoveryFileArgs := toDiscoveryFile(sdConfig) name := []string{"discovery", "file"} block := common.NewBlockWithOverride(name, label, discoveryFileArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.file." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.file." + label + ".targets") } -func validateDiscoveryFile(sdConfig *prom_file.SDConfig) diag.Diagnostics { +func ValidateDiscoveryFile(sdConfig *prom_file.SDConfig) diag.Diagnostics { return make(diag.Diagnostics, 0) } diff --git a/converter/internal/prometheusconvert/gce.go b/converter/internal/prometheusconvert/component/gce.go similarity index 65% rename from converter/internal/prometheusconvert/gce.go rename to converter/internal/prometheusconvert/component/gce.go index f7c19a81e57f..0a40d936c17e 100644 --- a/converter/internal/prometheusconvert/gce.go +++ b/converter/internal/prometheusconvert/component/gce.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,18 +7,19 @@ import ( "github.com/grafana/agent/component/discovery/gce" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_gce "github.com/prometheus/prometheus/discovery/gce" ) -func appendDiscoveryGCE(pb *prometheusBlocks, label string, sdConfig *prom_gce.SDConfig) discovery.Exports { +func appendDiscoveryGCE(pb *build.PrometheusBlocks, label string, sdConfig *prom_gce.SDConfig) discovery.Exports { discoveryGCEArgs := toDiscoveryGCE(sdConfig) name := []string{"discovery", "gce"} block := common.NewBlockWithOverride(name, label, discoveryGCEArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.gce." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.gce." + label + ".targets") } -func validateDiscoveryGCE(sdConfig *prom_gce.SDConfig) diag.Diagnostics { +func ValidateDiscoveryGCE(sdConfig *prom_gce.SDConfig) diag.Diagnostics { return make(diag.Diagnostics, 0) } diff --git a/converter/internal/prometheusconvert/ionos.go b/converter/internal/prometheusconvert/component/ionos.go similarity index 55% rename from converter/internal/prometheusconvert/ionos.go rename to converter/internal/prometheusconvert/component/ionos.go index 44db7beb3bb8..bcb094c8662c 100644 --- a/converter/internal/prometheusconvert/ionos.go +++ b/converter/internal/prometheusconvert/component/ionos.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,19 +7,20 @@ import ( "github.com/grafana/agent/component/discovery/ionos" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_ionos "github.com/prometheus/prometheus/discovery/ionos" ) -func appendDiscoveryIonos(pb *prometheusBlocks, label string, sdConfig *prom_ionos.SDConfig) discovery.Exports { +func appendDiscoveryIonos(pb *build.PrometheusBlocks, label string, sdConfig *prom_ionos.SDConfig) discovery.Exports { discoveryIonosArgs := toDiscoveryIonos(sdConfig) name := []string{"discovery", "ionos"} block := common.NewBlockWithOverride(name, label, discoveryIonosArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.ionos." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.ionos." + label + ".targets") } -func validateDiscoveryIonos(sdConfig *prom_ionos.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryIonos(sdConfig *prom_ionos.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryIonos(sdConfig *prom_ionos.SDConfig) *ionos.Arguments { @@ -31,6 +32,6 @@ func toDiscoveryIonos(sdConfig *prom_ionos.SDConfig) *ionos.Arguments { DatacenterID: sdConfig.DatacenterID, RefreshInterval: time.Duration(sdConfig.RefreshInterval), Port: sdConfig.Port, - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), } } diff --git a/converter/internal/prometheusconvert/kubernetes.go b/converter/internal/prometheusconvert/component/kubernetes.go similarity index 74% rename from converter/internal/prometheusconvert/kubernetes.go rename to converter/internal/prometheusconvert/component/kubernetes.go index c84dac76bc55..bae0eb8c7dd3 100644 --- a/converter/internal/prometheusconvert/kubernetes.go +++ b/converter/internal/prometheusconvert/component/kubernetes.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "github.com/grafana/agent/component/common/config" @@ -6,19 +6,20 @@ import ( "github.com/grafana/agent/component/discovery/kubernetes" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_kubernetes "github.com/prometheus/prometheus/discovery/kubernetes" ) -func appendDiscoveryKubernetes(pb *prometheusBlocks, label string, sdConfig *prom_kubernetes.SDConfig) discovery.Exports { +func appendDiscoveryKubernetes(pb *build.PrometheusBlocks, label string, sdConfig *prom_kubernetes.SDConfig) discovery.Exports { discoveryKubernetesArgs := toDiscoveryKubernetes(sdConfig) name := []string{"discovery", "kubernetes"} block := common.NewBlockWithOverride(name, label, discoveryKubernetesArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.kubernetes." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.kubernetes." + label + ".targets") } -func validateDiscoveryKubernetes(sdConfig *prom_kubernetes.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryKubernetes(sdConfig *prom_kubernetes.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryKubernetes(sdConfig *prom_kubernetes.SDConfig) *kubernetes.Arguments { @@ -30,7 +31,7 @@ func toDiscoveryKubernetes(sdConfig *prom_kubernetes.SDConfig) *kubernetes.Argum APIServer: config.URL(sdConfig.APIServer), Role: string(sdConfig.Role), KubeConfig: sdConfig.KubeConfig, - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), NamespaceDiscovery: toNamespaceDiscovery(&sdConfig.NamespaceDiscovery), Selectors: toSelectorConfig(sdConfig.Selectors), AttachMetadata: toAttachMetadata(&sdConfig.AttachMetadata), diff --git a/converter/internal/prometheusconvert/component/kuma.go b/converter/internal/prometheusconvert/component/kuma.go new file mode 100644 index 000000000000..0687edc15ef9 --- /dev/null +++ b/converter/internal/prometheusconvert/component/kuma.go @@ -0,0 +1,38 @@ +package component + +import ( + "time" + + "github.com/grafana/agent/component/discovery" + "github.com/grafana/agent/component/discovery/kuma" + "github.com/grafana/agent/converter/diag" + "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" + prom_kuma "github.com/prometheus/prometheus/discovery/xds" +) + +func appendDiscoveryKuma(pb *build.PrometheusBlocks, label string, sdConfig *prom_kuma.SDConfig) discovery.Exports { + discoveryKumaArgs := toDiscoveryKuma(sdConfig) + name := []string{"discovery", "kuma"} + block := common.NewBlockWithOverride(name, label, discoveryKumaArgs) + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.kuma." + label + ".targets") +} + +func ValidateDiscoveryKuma(sdConfig *prom_kuma.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +} + +func toDiscoveryKuma(sdConfig *prom_kuma.SDConfig) *kuma.Arguments { + if sdConfig == nil { + return nil + } + + return &kuma.Arguments{ + Server: sdConfig.Server, + RefreshInterval: time.Duration(sdConfig.RefreshInterval), + FetchTimeout: time.Duration(sdConfig.FetchTimeout), + + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), + } +} diff --git a/converter/internal/prometheusconvert/lightsail.go b/converter/internal/prometheusconvert/component/lightsail.go similarity index 85% rename from converter/internal/prometheusconvert/lightsail.go rename to converter/internal/prometheusconvert/component/lightsail.go index cda98952ba46..b796502d9a53 100644 --- a/converter/internal/prometheusconvert/lightsail.go +++ b/converter/internal/prometheusconvert/component/lightsail.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "reflect" @@ -8,20 +8,21 @@ import ( "github.com/grafana/agent/component/discovery/aws" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_config "github.com/prometheus/common/config" prom_aws "github.com/prometheus/prometheus/discovery/aws" ) -func appendDiscoveryLightsail(pb *prometheusBlocks, label string, sdConfig *prom_aws.LightsailSDConfig) discovery.Exports { +func appendDiscoveryLightsail(pb *build.PrometheusBlocks, label string, sdConfig *prom_aws.LightsailSDConfig) discovery.Exports { discoverylightsailArgs := toDiscoveryLightsail(sdConfig) name := []string{"discovery", "lightsail"} block := common.NewBlockWithOverride(name, label, discoverylightsailArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.lightsail." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.lightsail." + label + ".targets") } -func validateDiscoveryLightsail(sdConfig *prom_aws.LightsailSDConfig) diag.Diagnostics { +func ValidateDiscoveryLightsail(sdConfig *prom_aws.LightsailSDConfig) diag.Diagnostics { var diags diag.Diagnostics if sdConfig.HTTPClientConfig.BasicAuth != nil { diff --git a/converter/internal/prometheusconvert/component/linode.go b/converter/internal/prometheusconvert/component/linode.go new file mode 100644 index 000000000000..145d3dd0adb9 --- /dev/null +++ b/converter/internal/prometheusconvert/component/linode.go @@ -0,0 +1,37 @@ +package component + +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" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" + prom_linode "github.com/prometheus/prometheus/discovery/linode" +) + +func appendDiscoveryLinode(pb *build.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, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.linode." + label + ".targets") +} + +func ValidateDiscoveryLinode(sdConfig *prom_linode.SDConfig) diag.Diagnostics { + return common.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: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), + } +} diff --git a/converter/internal/prometheusconvert/marathon.go b/converter/internal/prometheusconvert/component/marathon.go similarity index 59% rename from converter/internal/prometheusconvert/marathon.go rename to converter/internal/prometheusconvert/component/marathon.go index 53ecb88f7744..57fd118e1e53 100644 --- a/converter/internal/prometheusconvert/marathon.go +++ b/converter/internal/prometheusconvert/component/marathon.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,20 +7,21 @@ import ( "github.com/grafana/agent/component/discovery/marathon" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_marathon "github.com/prometheus/prometheus/discovery/marathon" ) -func appendDiscoveryMarathon(pb *prometheusBlocks, label string, sdConfig *prom_marathon.SDConfig) discovery.Exports { +func appendDiscoveryMarathon(pb *build.PrometheusBlocks, label string, sdConfig *prom_marathon.SDConfig) discovery.Exports { discoveryMarathonArgs := toDiscoveryMarathon(sdConfig) name := []string{"discovery", "marathon"} block := common.NewBlockWithOverride(name, label, discoveryMarathonArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.marathon." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.marathon." + label + ".targets") } -func validateDiscoveryMarathon(sdConfig *prom_marathon.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) +func ValidateDiscoveryMarathon(sdConfig *prom_marathon.SDConfig) diag.Diagnostics { + return common.ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) } func toDiscoveryMarathon(sdConfig *prom_marathon.SDConfig) *marathon.Arguments { @@ -33,6 +34,6 @@ func toDiscoveryMarathon(sdConfig *prom_marathon.SDConfig) *marathon.Arguments { AuthToken: rivertypes.Secret(sdConfig.AuthToken), AuthTokenFile: sdConfig.AuthTokenFile, RefreshInterval: time.Duration(sdConfig.RefreshInterval), - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&sdConfig.HTTPClientConfig), } } diff --git a/converter/internal/prometheusconvert/nerve.go b/converter/internal/prometheusconvert/component/nerve.go similarity index 61% rename from converter/internal/prometheusconvert/nerve.go rename to converter/internal/prometheusconvert/component/nerve.go index dfe5f1d3aa43..015eb2d27fcc 100644 --- a/converter/internal/prometheusconvert/nerve.go +++ b/converter/internal/prometheusconvert/component/nerve.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,18 +7,19 @@ import ( "github.com/grafana/agent/component/discovery/nerve" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_nerve "github.com/prometheus/prometheus/discovery/zookeeper" ) -func appendDiscoveryNerve(pb *prometheusBlocks, label string, sdConfig *prom_nerve.NerveSDConfig) discovery.Exports { +func appendDiscoveryNerve(pb *build.PrometheusBlocks, label string, sdConfig *prom_nerve.NerveSDConfig) discovery.Exports { discoveryNerveArgs := toDiscoveryNerve(sdConfig) name := []string{"discovery", "nerve"} block := common.NewBlockWithOverride(name, label, discoveryNerveArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.nerve." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.nerve." + label + ".targets") } -func validateDiscoveryNerve(sdConfig *prom_nerve.NerveSDConfig) diag.Diagnostics { +func ValidateDiscoveryNerve(sdConfig *prom_nerve.NerveSDConfig) diag.Diagnostics { return nil } diff --git a/converter/internal/prometheusconvert/openstack.go b/converter/internal/prometheusconvert/component/openstack.go similarity index 75% rename from converter/internal/prometheusconvert/openstack.go rename to converter/internal/prometheusconvert/component/openstack.go index 1e140ea99eea..27d719b9df66 100644 --- a/converter/internal/prometheusconvert/openstack.go +++ b/converter/internal/prometheusconvert/component/openstack.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,19 +7,20 @@ import ( "github.com/grafana/agent/component/discovery/openstack" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_openstack "github.com/prometheus/prometheus/discovery/openstack" ) -func appendDiscoveryOpenstack(pb *prometheusBlocks, label string, sdConfig *prom_openstack.SDConfig) discovery.Exports { +func appendDiscoveryOpenstack(pb *build.PrometheusBlocks, label string, sdConfig *prom_openstack.SDConfig) discovery.Exports { discoveryOpenstackArgs := toDiscoveryOpenstack(sdConfig) name := []string{"discovery", "openstack"} block := common.NewBlockWithOverride(name, label, discoveryOpenstackArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.openstack." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.openstack." + label + ".targets") } -func validateDiscoveryOpenstack(sdConfig *prom_openstack.SDConfig) diag.Diagnostics { +func ValidateDiscoveryOpenstack(sdConfig *prom_openstack.SDConfig) diag.Diagnostics { return nil } @@ -45,7 +46,7 @@ func toDiscoveryOpenstack(sdConfig *prom_openstack.SDConfig) *openstack.Argument RefreshInterval: time.Duration(sdConfig.RefreshInterval), Port: sdConfig.Port, AllTenants: sdConfig.AllTenants, - TLSConfig: *ToTLSConfig(&sdConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&sdConfig.TLSConfig), Availability: sdConfig.Availability, } } diff --git a/converter/internal/prometheusconvert/relabel.go b/converter/internal/prometheusconvert/component/relabel.go similarity index 77% rename from converter/internal/prometheusconvert/relabel.go rename to converter/internal/prometheusconvert/component/relabel.go index 9b9aa2d9abc4..de6ec420ec21 100644 --- a/converter/internal/prometheusconvert/relabel.go +++ b/converter/internal/prometheusconvert/component/relabel.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "fmt" @@ -8,11 +8,12 @@ import ( disc_relabel "github.com/grafana/agent/component/discovery/relabel" "github.com/grafana/agent/component/prometheus/relabel" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_relabel "github.com/prometheus/prometheus/model/relabel" "github.com/prometheus/prometheus/storage" ) -func appendPrometheusRelabel(pb *prometheusBlocks, relabelConfigs []*prom_relabel.Config, forwardTo []storage.Appendable, label string) *relabel.Exports { +func AppendPrometheusRelabel(pb *build.PrometheusBlocks, relabelConfigs []*prom_relabel.Config, forwardTo []storage.Appendable, label string) *relabel.Exports { if len(relabelConfigs) == 0 { return nil } @@ -20,7 +21,7 @@ func appendPrometheusRelabel(pb *prometheusBlocks, relabelConfigs []*prom_relabe relabelArgs := toRelabelArguments(relabelConfigs, forwardTo) name := []string{"prometheus", "relabel"} block := common.NewBlockWithOverride(name, label, relabelArgs) - pb.prometheusRelabelBlocks = append(pb.prometheusRelabelBlocks, newPrometheusBlock(block, name, label, "", "")) + pb.PrometheusRelabelBlocks = append(pb.PrometheusRelabelBlocks, build.NewPrometheusBlock(block, name, label, "", "")) return &relabel.Exports{ Receiver: common.ConvertAppendable{Expr: fmt.Sprintf("prometheus.relabel.%s.receiver", label)}, @@ -38,7 +39,7 @@ func toRelabelArguments(relabelConfigs []*prom_relabel.Config, forwardTo []stora } } -func appendDiscoveryRelabel(pb *prometheusBlocks, relabelConfigs []*prom_relabel.Config, targets []discovery.Target, label string) *disc_relabel.Exports { +func AppendDiscoveryRelabel(pb *build.PrometheusBlocks, relabelConfigs []*prom_relabel.Config, targets []discovery.Target, label string) *disc_relabel.Exports { if len(relabelConfigs) == 0 { return nil } @@ -46,10 +47,10 @@ func appendDiscoveryRelabel(pb *prometheusBlocks, relabelConfigs []*prom_relabel relabelArgs := toDiscoveryRelabelArguments(relabelConfigs, targets) name := []string{"discovery", "relabel"} block := common.NewBlockWithOverride(name, label, relabelArgs) - pb.discoveryRelabelBlocks = append(pb.discoveryRelabelBlocks, newPrometheusBlock(block, name, label, "", "")) + pb.DiscoveryRelabelBlocks = append(pb.DiscoveryRelabelBlocks, build.NewPrometheusBlock(block, name, label, "", "")) return &disc_relabel.Exports{ - Output: newDiscoveryTargets(fmt.Sprintf("discovery.relabel.%s.output", label)), + Output: common.NewDiscoveryTargets(fmt.Sprintf("discovery.relabel.%s.output", label)), } } diff --git a/converter/internal/prometheusconvert/remote_write.go b/converter/internal/prometheusconvert/component/remote_write.go similarity index 86% rename from converter/internal/prometheusconvert/remote_write.go rename to converter/internal/prometheusconvert/component/remote_write.go index 3ecd1e51d795..4756f84d6674 100644 --- a/converter/internal/prometheusconvert/remote_write.go +++ b/converter/internal/prometheusconvert/component/remote_write.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "fmt" @@ -8,13 +8,14 @@ import ( "github.com/grafana/agent/component/prometheus/remotewrite" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" "github.com/prometheus/common/sigv4" prom_config "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/storage/remote/azuread" ) -func appendPrometheusRemoteWrite(pb *prometheusBlocks, globalConfig prom_config.GlobalConfig, remoteWriteConfigs []*prom_config.RemoteWriteConfig, label string) *remotewrite.Exports { +func AppendPrometheusRemoteWrite(pb *build.PrometheusBlocks, globalConfig prom_config.GlobalConfig, remoteWriteConfigs []*prom_config.RemoteWriteConfig, label string) *remotewrite.Exports { remoteWriteArgs := toRemotewriteArguments(globalConfig, remoteWriteConfigs) remoteWriteLabel := label @@ -32,7 +33,7 @@ func appendPrometheusRemoteWrite(pb *prometheusBlocks, globalConfig prom_config. } summary := fmt.Sprintf("Converted %d remote_write[s] %q into...", len(remoteWriteConfigs), strings.Join(names, ",")) detail := fmt.Sprintf(" A prometheus.remote_write.%s component", remoteWriteLabel) - pb.prometheusRemoteWriteBlocks = append(pb.prometheusRemoteWriteBlocks, newPrometheusBlock(block, name, remoteWriteLabel, summary, detail)) + pb.PrometheusRemoteWriteBlocks = append(pb.PrometheusRemoteWriteBlocks, build.NewPrometheusBlock(block, name, remoteWriteLabel, summary, detail)) } return &remotewrite.Exports{ @@ -40,10 +41,10 @@ func appendPrometheusRemoteWrite(pb *prometheusBlocks, globalConfig prom_config. } } -func validateRemoteWriteConfig(remoteWriteConfig *prom_config.RemoteWriteConfig) diag.Diagnostics { +func ValidateRemoteWriteConfig(remoteWriteConfig *prom_config.RemoteWriteConfig) diag.Diagnostics { var diags diag.Diagnostics - diags.AddAll(ValidateHttpClientConfig(&remoteWriteConfig.HTTPClientConfig)) + diags.AddAll(common.ValidateHttpClientConfig(&remoteWriteConfig.HTTPClientConfig)) return diags } @@ -71,7 +72,7 @@ func getEndpointOptions(remoteWriteConfigs []*prom_config.RemoteWriteConfig) []* Headers: remoteWriteConfig.Headers, SendExemplars: remoteWriteConfig.SendExemplars, SendNativeHistograms: remoteWriteConfig.SendNativeHistograms, - HTTPClientConfig: ToHttpClientConfig(&remoteWriteConfig.HTTPClientConfig), + HTTPClientConfig: common.ToHttpClientConfig(&remoteWriteConfig.HTTPClientConfig), QueueOptions: toQueueOptions(&remoteWriteConfig.QueueConfig), MetadataOptions: toMetadataOptions(&remoteWriteConfig.MetadataConfig), WriteRelabelConfigs: ToFlowRelabelConfigs(remoteWriteConfig.WriteRelabelConfigs), diff --git a/converter/internal/prometheusconvert/scaleway.go b/converter/internal/prometheusconvert/component/scaleway.go similarity index 66% rename from converter/internal/prometheusconvert/scaleway.go rename to converter/internal/prometheusconvert/component/scaleway.go index f75cf0c56e76..8cc25b7470c0 100644 --- a/converter/internal/prometheusconvert/scaleway.go +++ b/converter/internal/prometheusconvert/component/scaleway.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -8,23 +8,24 @@ import ( "github.com/grafana/agent/component/discovery/scaleway" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/river/rivertypes" prom_scaleway "github.com/prometheus/prometheus/discovery/scaleway" ) -func appendDiscoveryScaleway(pb *prometheusBlocks, label string, sdConfig *prom_scaleway.SDConfig) discovery.Exports { - discoveryScalewayArgs := ToDiscoveryScaleway(sdConfig) +func appendDiscoveryScaleway(pb *build.PrometheusBlocks, label string, sdConfig *prom_scaleway.SDConfig) discovery.Exports { + discoveryScalewayArgs := toDiscoveryScaleway(sdConfig) name := []string{"discovery", "scaleway"} block := common.NewBlockWithOverride(name, label, discoveryScalewayArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.scaleway." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.scaleway." + label + ".targets") } -func validateDiscoveryScaleway(sdConfig *prom_scaleway.SDConfig) diag.Diagnostics { +func ValidateDiscoveryScaleway(sdConfig *prom_scaleway.SDConfig) diag.Diagnostics { return nil } -func ToDiscoveryScaleway(sdConfig *prom_scaleway.SDConfig) *scaleway.Arguments { +func toDiscoveryScaleway(sdConfig *prom_scaleway.SDConfig) *scaleway.Arguments { if sdConfig == nil { return nil } @@ -42,7 +43,7 @@ func ToDiscoveryScaleway(sdConfig *prom_scaleway.SDConfig) *scaleway.Arguments { RefreshInterval: time.Duration(sdConfig.RefreshInterval), Port: sdConfig.Port, ProxyURL: config.URL(sdConfig.HTTPClientConfig.ProxyURL), - TLSConfig: *ToTLSConfig(&sdConfig.HTTPClientConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&sdConfig.HTTPClientConfig.TLSConfig), FollowRedirects: sdConfig.HTTPClientConfig.FollowRedirects, EnableHTTP2: sdConfig.HTTPClientConfig.EnableHTTP2, } diff --git a/converter/internal/prometheusconvert/scrape.go b/converter/internal/prometheusconvert/component/scrape.go similarity index 81% rename from converter/internal/prometheusconvert/scrape.go rename to converter/internal/prometheusconvert/component/scrape.go index 533c86458f4d..d115bbb09cf0 100644 --- a/converter/internal/prometheusconvert/scrape.go +++ b/converter/internal/prometheusconvert/component/scrape.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "fmt" @@ -11,28 +11,29 @@ import ( "github.com/grafana/agent/component/prometheus/scrape" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_config "github.com/prometheus/prometheus/config" prom_discovery "github.com/prometheus/prometheus/discovery" "github.com/prometheus/prometheus/storage" ) -func appendPrometheusScrape(pb *prometheusBlocks, scrapeConfig *prom_config.ScrapeConfig, forwardTo []storage.Appendable, targets []discovery.Target, label string) { +func AppendPrometheusScrape(pb *build.PrometheusBlocks, scrapeConfig *prom_config.ScrapeConfig, forwardTo []storage.Appendable, targets []discovery.Target, label string) { scrapeArgs := toScrapeArguments(scrapeConfig, forwardTo, targets) name := []string{"prometheus", "scrape"} block := common.NewBlockWithOverride(name, label, scrapeArgs) summary := fmt.Sprintf("Converted scrape_configs job_name %q into...", scrapeConfig.JobName) detail := fmt.Sprintf(" A %s.%s component", strings.Join(name, "."), label) - pb.prometheusScrapeBlocks = append(pb.prometheusScrapeBlocks, newPrometheusBlock(block, name, label, summary, detail)) + pb.PrometheusScrapeBlocks = append(pb.PrometheusScrapeBlocks, build.NewPrometheusBlock(block, name, label, summary, detail)) } -func validatePrometheusScrape(scrapeConfig *prom_config.ScrapeConfig) diag.Diagnostics { +func ValidatePrometheusScrape(scrapeConfig *prom_config.ScrapeConfig) diag.Diagnostics { var diags diag.Diagnostics if scrapeConfig.NativeHistogramBucketLimit != 0 { diags.Add(diag.SeverityLevelError, "unsupported native_histogram_bucket_limit for scrape_configs") } - diags.AddAll(ValidateHttpClientConfig(&scrapeConfig.HTTPClientConfig)) + diags.AddAll(common.ValidateHttpClientConfig(&scrapeConfig.HTTPClientConfig)) return diags } @@ -60,7 +61,7 @@ func toScrapeArguments(scrapeConfig *prom_config.ScrapeConfig, forwardTo []stora LabelLimit: scrapeConfig.LabelLimit, LabelNameLengthLimit: scrapeConfig.LabelNameLengthLimit, LabelValueLengthLimit: scrapeConfig.LabelValueLengthLimit, - HTTPClientConfig: *ToHttpClientConfig(&scrapeConfig.HTTPClientConfig), + HTTPClientConfig: *common.ToHttpClientConfig(&scrapeConfig.HTTPClientConfig), ExtraMetrics: false, EnableProtobufNegotiation: false, Clustering: scrape.Clustering{Enabled: false}, @@ -90,6 +91,6 @@ func getScrapeTargets(staticConfig prom_discovery.StaticConfig) []discovery.Targ return targets } -func validateScrapeTargets(staticConfig prom_discovery.StaticConfig) diag.Diagnostics { +func ValidateScrapeTargets(staticConfig prom_discovery.StaticConfig) diag.Diagnostics { return make(diag.Diagnostics, 0) } diff --git a/converter/internal/prometheusconvert/serverset.go b/converter/internal/prometheusconvert/component/serverset.go similarity index 51% rename from converter/internal/prometheusconvert/serverset.go rename to converter/internal/prometheusconvert/component/serverset.go index 19c033d9b32c..6b3241ce9dc2 100644 --- a/converter/internal/prometheusconvert/serverset.go +++ b/converter/internal/prometheusconvert/component/serverset.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,18 +7,19 @@ import ( "github.com/grafana/agent/component/discovery/serverset" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_zk "github.com/prometheus/prometheus/discovery/zookeeper" ) -func appendDiscoveryServerset(pb *prometheusBlocks, label string, sdc *prom_zk.ServersetSDConfig) discovery.Exports { - discoveryServersetArgs := ToDiscoveryServerset(sdc) +func appendDiscoveryServerset(pb *build.PrometheusBlocks, label string, sdc *prom_zk.ServersetSDConfig) discovery.Exports { + discoveryServersetArgs := toDiscoveryServerset(sdc) name := []string{"discovery", "serverset"} block := common.NewBlockWithOverride(name, label, discoveryServersetArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.serverset." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.serverset." + label + ".targets") } -func ToDiscoveryServerset(sdc *prom_zk.ServersetSDConfig) *serverset.Arguments { +func toDiscoveryServerset(sdc *prom_zk.ServersetSDConfig) *serverset.Arguments { if sdc == nil { return nil } @@ -30,6 +31,6 @@ func ToDiscoveryServerset(sdc *prom_zk.ServersetSDConfig) *serverset.Arguments { } } -func validateDiscoveryServerset(_ *prom_zk.ServersetSDConfig) diag.Diagnostics { +func ValidateDiscoveryServerset(_ *prom_zk.ServersetSDConfig) diag.Diagnostics { return nil } diff --git a/converter/internal/prometheusconvert/component/service_discovery.go b/converter/internal/prometheusconvert/component/service_discovery.go new file mode 100644 index 000000000000..75c84c86ad34 --- /dev/null +++ b/converter/internal/prometheusconvert/component/service_discovery.go @@ -0,0 +1,153 @@ +package component + +import ( + "fmt" + + "github.com/grafana/agent/component/discovery" + "github.com/grafana/agent/converter/diag" + "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" + + prom_discover "github.com/prometheus/prometheus/discovery" + _ "github.com/prometheus/prometheus/discovery/install" // Register Prometheus SDs + + prom_aws "github.com/prometheus/prometheus/discovery/aws" + prom_azure "github.com/prometheus/prometheus/discovery/azure" + prom_consul "github.com/prometheus/prometheus/discovery/consul" + prom_digitalocean "github.com/prometheus/prometheus/discovery/digitalocean" + prom_dns "github.com/prometheus/prometheus/discovery/dns" + prom_file "github.com/prometheus/prometheus/discovery/file" + prom_gce "github.com/prometheus/prometheus/discovery/gce" + prom_ionos "github.com/prometheus/prometheus/discovery/ionos" + prom_kubernetes "github.com/prometheus/prometheus/discovery/kubernetes" + prom_linode "github.com/prometheus/prometheus/discovery/linode" + prom_marathon "github.com/prometheus/prometheus/discovery/marathon" + prom_docker "github.com/prometheus/prometheus/discovery/moby" + prom_openstack "github.com/prometheus/prometheus/discovery/openstack" + prom_scaleway "github.com/prometheus/prometheus/discovery/scaleway" + prom_triton "github.com/prometheus/prometheus/discovery/triton" + prom_xds "github.com/prometheus/prometheus/discovery/xds" + prom_zk "github.com/prometheus/prometheus/discovery/zookeeper" +) + +func AppendServiceDiscoveryConfig(pb *build.PrometheusBlocks, serviceDiscoveryConfig prom_discover.Config, label string, labelCounts map[string]int) discovery.Exports { + switch sdc := serviceDiscoveryConfig.(type) { + case prom_discover.StaticConfig: + return discovery.Exports{ + Targets: getScrapeTargets(sdc), + } + case *prom_azure.SDConfig: + labelCounts["azure"]++ + return appendDiscoveryAzure(pb, common.LabelWithIndex(labelCounts["azure"]-1, label), sdc) + case *prom_consul.SDConfig: + labelCounts["consul"]++ + return appendDiscoveryConsul(pb, common.LabelWithIndex(labelCounts["consul"]-1, label), sdc) + case *prom_digitalocean.SDConfig: + labelCounts["digitalocean"]++ + return appendDiscoveryDigitalOcean(pb, common.LabelWithIndex(labelCounts["digitalocean"]-1, label), sdc) + case *prom_dns.SDConfig: + labelCounts["dns"]++ + return appendDiscoveryDns(pb, common.LabelWithIndex(labelCounts["dns"]-1, label), sdc) + case *prom_docker.DockerSDConfig: + labelCounts["docker"]++ + return appendDiscoveryDocker(pb, common.LabelWithIndex(labelCounts["docker"]-1, label), sdc) + case *prom_aws.EC2SDConfig: + labelCounts["ec2"]++ + return appendDiscoveryEC2(pb, common.LabelWithIndex(labelCounts["ec2"]-1, label), sdc) + case *prom_file.SDConfig: + labelCounts["file"]++ + return appendDiscoveryFile(pb, common.LabelWithIndex(labelCounts["file"]-1, label), sdc) + case *prom_gce.SDConfig: + labelCounts["gce"]++ + return appendDiscoveryGCE(pb, common.LabelWithIndex(labelCounts["gce"]-1, label), sdc) + case *prom_kubernetes.SDConfig: + labelCounts["kubernetes"]++ + return appendDiscoveryKubernetes(pb, common.LabelWithIndex(labelCounts["kubernetes"]-1, label), sdc) + case *prom_aws.LightsailSDConfig: + labelCounts["lightsail"]++ + return appendDiscoveryLightsail(pb, common.LabelWithIndex(labelCounts["lightsail"]-1, label), sdc) + case *prom_marathon.SDConfig: + labelCounts["marathon"]++ + return appendDiscoveryMarathon(pb, common.LabelWithIndex(labelCounts["marathon"]-1, label), sdc) + case *prom_ionos.SDConfig: + labelCounts["ionos"]++ + return appendDiscoveryIonos(pb, common.LabelWithIndex(labelCounts["ionos"]-1, label), sdc) + case *prom_triton.SDConfig: + labelCounts["triton"]++ + return appendDiscoveryTriton(pb, common.LabelWithIndex(labelCounts["triton"]-1, label), sdc) + case *prom_xds.SDConfig: + labelCounts["kuma"]++ + return appendDiscoveryKuma(pb, common.LabelWithIndex(labelCounts["kuma"]-1, label), sdc) + case *prom_scaleway.SDConfig: + labelCounts["scaleway"]++ + return appendDiscoveryScaleway(pb, common.LabelWithIndex(labelCounts["scaleway"]-1, label), sdc) + case *prom_zk.ServersetSDConfig: + labelCounts["serverset"]++ + return appendDiscoveryServerset(pb, common.LabelWithIndex(labelCounts["serverset"]-1, label), sdc) + case *prom_linode.SDConfig: + labelCounts["linode"]++ + return appendDiscoveryLinode(pb, common.LabelWithIndex(labelCounts["linode"]-1, label), sdc) + case *prom_zk.NerveSDConfig: + labelCounts["nerve"]++ + return appendDiscoveryNerve(pb, common.LabelWithIndex(labelCounts["nerve"]-1, label), sdc) + case *prom_openstack.SDConfig: + labelCounts["openstack"]++ + return appendDiscoveryOpenstack(pb, common.LabelWithIndex(labelCounts["openstack"]-1, label), sdc) + case *prom_docker.DockerSwarmSDConfig: + labelCounts["dockerswarm"]++ + return appendDiscoveryDockerswarm(pb, common.LabelWithIndex(labelCounts["dockerswarm"]-1, label), sdc) + default: + return discovery.Exports{} + } +} + +func ValidateServiceDiscoveryConfig(serviceDiscoveryConfig prom_discover.Config) diag.Diagnostics { + switch sdc := serviceDiscoveryConfig.(type) { + case prom_discover.StaticConfig: + return ValidateScrapeTargets(sdc) + case *prom_azure.SDConfig: + return ValidateDiscoveryAzure(sdc) + case *prom_consul.SDConfig: + return ValidateDiscoveryConsul(sdc) + case *prom_digitalocean.SDConfig: + return ValidateDiscoveryDigitalOcean(sdc) + case *prom_dns.SDConfig: + return ValidateDiscoveryDns(sdc) + case *prom_docker.DockerSDConfig: + return ValidateDiscoveryDocker(sdc) + case *prom_aws.EC2SDConfig: + return ValidateDiscoveryEC2(sdc) + case *prom_file.SDConfig: + return ValidateDiscoveryFile(sdc) + case *prom_gce.SDConfig: + return ValidateDiscoveryGCE(sdc) + case *prom_kubernetes.SDConfig: + return ValidateDiscoveryKubernetes(sdc) + case *prom_aws.LightsailSDConfig: + return ValidateDiscoveryLightsail(sdc) + case *prom_xds.SDConfig: + return ValidateDiscoveryKuma(sdc) + case *prom_linode.SDConfig: + return ValidateDiscoveryLinode(sdc) + case *prom_triton.SDConfig: + return ValidateDiscoveryTriton(sdc) + case *prom_scaleway.SDConfig: + return ValidateDiscoveryScaleway(sdc) + case *prom_marathon.SDConfig: + return ValidateDiscoveryMarathon(sdc) + case *prom_ionos.SDConfig: + return ValidateDiscoveryIonos(sdc) + case *prom_zk.ServersetSDConfig: + return ValidateDiscoveryServerset(sdc) + case *prom_zk.NerveSDConfig: + return ValidateDiscoveryNerve(sdc) + case *prom_openstack.SDConfig: + return ValidateDiscoveryOpenstack(sdc) + case *prom_docker.DockerSwarmSDConfig: + return ValidateDiscoveryDockerswarm(sdc) + default: + var diags diag.Diagnostics + diags.Add(diag.SeverityLevelError, fmt.Sprintf("unsupported service discovery %s was provided", serviceDiscoveryConfig.Name())) + return diags + } +} diff --git a/converter/internal/prometheusconvert/triton.go b/converter/internal/prometheusconvert/component/triton.go similarity index 56% rename from converter/internal/prometheusconvert/triton.go rename to converter/internal/prometheusconvert/component/triton.go index 20875e868e40..4f1bf2e2994f 100644 --- a/converter/internal/prometheusconvert/triton.go +++ b/converter/internal/prometheusconvert/component/triton.go @@ -1,4 +1,4 @@ -package prometheusconvert +package component import ( "time" @@ -7,22 +7,23 @@ import ( "github.com/grafana/agent/component/discovery/triton" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" prom_triton "github.com/prometheus/prometheus/discovery/triton" ) -func appendDiscoveryTriton(pb *prometheusBlocks, label string, sdConfig *prom_triton.SDConfig) discovery.Exports { - discoveryTritonArgs := ToDiscoveryTriton(sdConfig) +func appendDiscoveryTriton(pb *build.PrometheusBlocks, label string, sdConfig *prom_triton.SDConfig) discovery.Exports { + discoveryTritonArgs := toDiscoveryTriton(sdConfig) name := []string{"discovery", "triton"} block := common.NewBlockWithOverride(name, label, discoveryTritonArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.triton." + label + ".targets") + pb.DiscoveryBlocks = append(pb.DiscoveryBlocks, build.NewPrometheusBlock(block, name, label, "", "")) + return common.NewDiscoveryExports("discovery.triton." + label + ".targets") } -func validateDiscoveryTriton(sdConfig *prom_triton.SDConfig) diag.Diagnostics { +func ValidateDiscoveryTriton(sdConfig *prom_triton.SDConfig) diag.Diagnostics { return nil } -func ToDiscoveryTriton(sdConfig *prom_triton.SDConfig) *triton.Arguments { +func toDiscoveryTriton(sdConfig *prom_triton.SDConfig) *triton.Arguments { if sdConfig == nil { return nil } @@ -36,6 +37,6 @@ func ToDiscoveryTriton(sdConfig *prom_triton.SDConfig) *triton.Arguments { Port: sdConfig.Port, RefreshInterval: time.Duration(sdConfig.RefreshInterval), Version: sdConfig.Version, - TLSConfig: *ToTLSConfig(&sdConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&sdConfig.TLSConfig), } } diff --git a/converter/internal/prometheusconvert/kuma.go b/converter/internal/prometheusconvert/kuma.go deleted file mode 100644 index 869a067a7261..000000000000 --- a/converter/internal/prometheusconvert/kuma.go +++ /dev/null @@ -1,37 +0,0 @@ -package prometheusconvert - -import ( - "time" - - "github.com/grafana/agent/component/discovery" - "github.com/grafana/agent/component/discovery/kuma" - "github.com/grafana/agent/converter/diag" - "github.com/grafana/agent/converter/internal/common" - prom_kuma "github.com/prometheus/prometheus/discovery/xds" -) - -func appendDiscoveryKuma(pb *prometheusBlocks, label string, sdConfig *prom_kuma.SDConfig) discovery.Exports { - discoveryKumaArgs := ToDiscoveryKuma(sdConfig) - name := []string{"discovery", "kuma"} - block := common.NewBlockWithOverride(name, label, discoveryKumaArgs) - pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) - return NewDiscoveryExports("discovery.kuma." + label + ".targets") -} - -func validateDiscoveryKuma(sdConfig *prom_kuma.SDConfig) diag.Diagnostics { - return ValidateHttpClientConfig(&sdConfig.HTTPClientConfig) -} - -func ToDiscoveryKuma(sdConfig *prom_kuma.SDConfig) *kuma.Arguments { - if sdConfig == nil { - return nil - } - - return &kuma.Arguments{ - Server: sdConfig.Server, - RefreshInterval: time.Duration(sdConfig.RefreshInterval), - FetchTimeout: time.Duration(sdConfig.FetchTimeout), - - HTTPClientConfig: *ToHttpClientConfig(&sdConfig.HTTPClientConfig), - } -} diff --git a/converter/internal/prometheusconvert/linode.go b/converter/internal/prometheusconvert/linode.go deleted file mode 100644 index 22e6ba8be90f..000000000000 --- a/converter/internal/prometheusconvert/linode.go +++ /dev/null @@ -1,36 +0,0 @@ -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), - } -} diff --git a/converter/internal/prometheusconvert/prometheusconvert.go b/converter/internal/prometheusconvert/prometheusconvert.go index 7d9522879da7..ef58f34d5168 100644 --- a/converter/internal/prometheusconvert/prometheusconvert.go +++ b/converter/internal/prometheusconvert/prometheusconvert.go @@ -9,30 +9,13 @@ import ( "github.com/grafana/agent/component/prometheus/remotewrite" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/river/token/builder" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" + "github.com/grafana/agent/converter/internal/prometheusconvert/component" prom_config "github.com/prometheus/prometheus/config" prom_discover "github.com/prometheus/prometheus/discovery" - prom_aws "github.com/prometheus/prometheus/discovery/aws" - prom_azure "github.com/prometheus/prometheus/discovery/azure" - prom_consul "github.com/prometheus/prometheus/discovery/consul" - prom_digitalocean "github.com/prometheus/prometheus/discovery/digitalocean" - prom_dns "github.com/prometheus/prometheus/discovery/dns" - prom_file "github.com/prometheus/prometheus/discovery/file" - prom_gce "github.com/prometheus/prometheus/discovery/gce" - prom_ionos "github.com/prometheus/prometheus/discovery/ionos" - prom_kubernetes "github.com/prometheus/prometheus/discovery/kubernetes" - prom_linode "github.com/prometheus/prometheus/discovery/linode" - prom_marathon "github.com/prometheus/prometheus/discovery/marathon" - prom_docker "github.com/prometheus/prometheus/discovery/moby" - prom_moby "github.com/prometheus/prometheus/discovery/moby" - prom_openstack "github.com/prometheus/prometheus/discovery/openstack" - prom_scaleway "github.com/prometheus/prometheus/discovery/scaleway" - prom_triton "github.com/prometheus/prometheus/discovery/triton" - prom_xds "github.com/prometheus/prometheus/discovery/xds" - prom_nerve "github.com/prometheus/prometheus/discovery/zookeeper" - prom_zk "github.com/prometheus/prometheus/discovery/zookeeper" "github.com/prometheus/prometheus/storage" + "github.com/grafana/river/token/builder" _ "github.com/prometheus/prometheus/discovery/install" // Register Prometheus SDs ) @@ -79,7 +62,7 @@ func AppendAll(f *builder.File, promConfig *prom_config.Config) diag.Diagnostics // pipeline. Additional options can be provided overriding the job name, extra // scrape targets, and predefined remote write exports. func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToCompLabelsFunc func(string) string, extraScrapeTargets []discovery.Target, remoteWriteExports *remotewrite.Exports) diag.Diagnostics { - pb := NewPrometheusBlocks() + pb := build.NewPrometheusBlocks() if remoteWriteExports == nil { labelPrefix := "" @@ -89,7 +72,7 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC labelPrefix = common.SanitizeIdentifierPanics(labelPrefix) } } - remoteWriteExports = appendPrometheusRemoteWrite(pb, promConfig.GlobalConfig, promConfig.RemoteWriteConfigs, labelPrefix) + remoteWriteExports = component.AppendPrometheusRemoteWrite(pb, promConfig.GlobalConfig, promConfig.RemoteWriteConfigs, labelPrefix) } remoteWriteForwardTo := []storage.Appendable{remoteWriteExports.Receiver} @@ -101,7 +84,7 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC } label = common.SanitizeIdentifierPanics(label) - promMetricsRelabelExports := appendPrometheusRelabel(pb, scrapeConfig.MetricRelabelConfigs, remoteWriteForwardTo, label) + promMetricsRelabelExports := component.AppendPrometheusRelabel(pb, scrapeConfig.MetricRelabelConfigs, remoteWriteForwardTo, label) if promMetricsRelabelExports != nil { scrapeForwardTo = []storage.Appendable{promMetricsRelabelExports.Receiver} } @@ -109,16 +92,16 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC scrapeTargets := AppendServiceDiscoveryConfigs(pb, scrapeConfig.ServiceDiscoveryConfigs, label) scrapeTargets = append(scrapeTargets, extraScrapeTargets...) - promDiscoveryRelabelExports := appendDiscoveryRelabel(pb, scrapeConfig.RelabelConfigs, scrapeTargets, label) + promDiscoveryRelabelExports := component.AppendDiscoveryRelabel(pb, scrapeConfig.RelabelConfigs, scrapeTargets, label) if promDiscoveryRelabelExports != nil { scrapeTargets = promDiscoveryRelabelExports.Output } - appendPrometheusScrape(pb, scrapeConfig, scrapeForwardTo, scrapeTargets, label) + component.AppendPrometheusScrape(pb, scrapeConfig, scrapeForwardTo, scrapeTargets, label) } diags := validate(promConfig) - diags.AddAll(pb.getScrapeInfo()) + diags.AddAll(pb.GetScrapeInfo()) pb.AppendToFile(f) @@ -128,76 +111,11 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC // AppendServiceDiscoveryConfigs will loop through the service discovery // configs and append them to the file. This returns the scrape targets // and discovery targets as a result. -func AppendServiceDiscoveryConfigs(pb *prometheusBlocks, serviceDiscoveryConfig prom_discover.Configs, label string) []discovery.Target { +func AppendServiceDiscoveryConfigs(pb *build.PrometheusBlocks, serviceDiscoveryConfig prom_discover.Configs, label string) []discovery.Target { var targets []discovery.Target labelCounts := make(map[string]int) for _, serviceDiscoveryConfig := range serviceDiscoveryConfig { - var exports discovery.Exports - switch sdc := serviceDiscoveryConfig.(type) { - case prom_discover.StaticConfig: - targets = append(targets, getScrapeTargets(sdc)...) - case *prom_azure.SDConfig: - labelCounts["azure"]++ - exports = appendDiscoveryAzure(pb, common.LabelWithIndex(labelCounts["azure"]-1, label), sdc) - case *prom_consul.SDConfig: - labelCounts["consul"]++ - exports = appendDiscoveryConsul(pb, common.LabelWithIndex(labelCounts["consul"]-1, label), sdc) - case *prom_digitalocean.SDConfig: - labelCounts["digitalocean"]++ - exports = appendDiscoveryDigitalOcean(pb, common.LabelWithIndex(labelCounts["digitalocean"]-1, label), sdc) - case *prom_dns.SDConfig: - labelCounts["dns"]++ - exports = appendDiscoveryDns(pb, common.LabelWithIndex(labelCounts["dns"]-1, label), sdc) - case *prom_docker.DockerSDConfig: - labelCounts["docker"]++ - exports = appendDiscoveryDocker(pb, common.LabelWithIndex(labelCounts["docker"]-1, label), sdc) - case *prom_aws.EC2SDConfig: - labelCounts["ec2"]++ - exports = appendDiscoveryEC2(pb, common.LabelWithIndex(labelCounts["ec2"]-1, label), sdc) - case *prom_file.SDConfig: - labelCounts["file"]++ - exports = appendDiscoveryFile(pb, common.LabelWithIndex(labelCounts["file"]-1, label), sdc) - case *prom_gce.SDConfig: - labelCounts["gce"]++ - exports = appendDiscoveryGCE(pb, common.LabelWithIndex(labelCounts["gce"]-1, label), sdc) - case *prom_kubernetes.SDConfig: - labelCounts["kubernetes"]++ - exports = appendDiscoveryKubernetes(pb, common.LabelWithIndex(labelCounts["kubernetes"]-1, label), sdc) - case *prom_aws.LightsailSDConfig: - labelCounts["lightsail"]++ - exports = appendDiscoveryLightsail(pb, common.LabelWithIndex(labelCounts["lightsail"]-1, label), sdc) - case *prom_marathon.SDConfig: - labelCounts["marathon"]++ - exports = appendDiscoveryMarathon(pb, common.LabelWithIndex(labelCounts["marathon"]-1, label), sdc) - case *prom_ionos.SDConfig: - labelCounts["ionos"]++ - exports = appendDiscoveryIonos(pb, common.LabelWithIndex(labelCounts["ionos"]-1, label), sdc) - case *prom_triton.SDConfig: - labelCounts["triton"]++ - exports = appendDiscoveryTriton(pb, common.LabelWithIndex(labelCounts["triton"]-1, label), sdc) - case *prom_xds.SDConfig: - labelCounts["kuma"]++ - exports = appendDiscoveryKuma(pb, common.LabelWithIndex(labelCounts["kuma"]-1, label), sdc) - case *prom_scaleway.SDConfig: - labelCounts["scaleway"]++ - exports = appendDiscoveryScaleway(pb, common.LabelWithIndex(labelCounts["scaleway"]-1, label), sdc) - case *prom_zk.ServersetSDConfig: - labelCounts["serverset"]++ - exports = appendDiscoveryServerset(pb, common.LabelWithIndex(labelCounts["serverset"]-1, label), sdc) - case *prom_linode.SDConfig: - labelCounts["linode"]++ - exports = appendDiscoveryLinode(pb, common.LabelWithIndex(labelCounts["linode"]-1, label), sdc) - case *prom_nerve.NerveSDConfig: - labelCounts["nerve"]++ - exports = appendDiscoveryNerve(pb, common.LabelWithIndex(labelCounts["nerve"]-1, label), sdc) - case *prom_openstack.SDConfig: - labelCounts["openstack"]++ - exports = appendDiscoveryOpenstack(pb, common.LabelWithIndex(labelCounts["openstack"]-1, label), sdc) - case *prom_moby.DockerSwarmSDConfig: - labelCounts["dockerswarm"]++ - exports = appendDiscoveryDockerswarm(pb, common.LabelWithIndex(labelCounts["dockerswarm"]-1, label), sdc) - } - + exports := component.AppendServiceDiscoveryConfig(pb, serviceDiscoveryConfig, label, labelCounts) targets = append(targets, exports.Targets...) } diff --git a/converter/internal/prometheusconvert/validate.go b/converter/internal/prometheusconvert/validate.go index 6b5216ef0211..fefc991e0df0 100644 --- a/converter/internal/prometheusconvert/validate.go +++ b/converter/internal/prometheusconvert/validate.go @@ -1,33 +1,14 @@ package prometheusconvert import ( - "fmt" "reflect" "github.com/grafana/agent/converter/diag" + "github.com/grafana/agent/converter/internal/prometheusconvert/component" prom_config "github.com/prometheus/prometheus/config" prom_discover "github.com/prometheus/prometheus/discovery" - prom_aws "github.com/prometheus/prometheus/discovery/aws" - prom_azure "github.com/prometheus/prometheus/discovery/azure" - prom_consul "github.com/prometheus/prometheus/discovery/consul" - prom_digitalocean "github.com/prometheus/prometheus/discovery/digitalocean" - prom_dns "github.com/prometheus/prometheus/discovery/dns" - prom_file "github.com/prometheus/prometheus/discovery/file" - prom_gce "github.com/prometheus/prometheus/discovery/gce" _ "github.com/prometheus/prometheus/discovery/install" // Register Prometheus SDs - prom_ionos "github.com/prometheus/prometheus/discovery/ionos" - prom_kubernetes "github.com/prometheus/prometheus/discovery/kubernetes" - prom_linode "github.com/prometheus/prometheus/discovery/linode" - prom_marathon "github.com/prometheus/prometheus/discovery/marathon" - prom_docker "github.com/prometheus/prometheus/discovery/moby" - prom_moby "github.com/prometheus/prometheus/discovery/moby" - prom_openstack "github.com/prometheus/prometheus/discovery/openstack" - prom_scaleway "github.com/prometheus/prometheus/discovery/scaleway" - prom_triton "github.com/prometheus/prometheus/discovery/triton" - prom_kuma "github.com/prometheus/prometheus/discovery/xds" - prom_nerve "github.com/prometheus/prometheus/discovery/zookeeper" - prom_zk "github.com/prometheus/prometheus/discovery/zookeeper" ) func validate(promConfig *prom_config.Config) diag.Diagnostics { @@ -78,7 +59,7 @@ func validateScrapeConfigs(scrapeConfigs []*prom_config.ScrapeConfig) diag.Diagn var diags diag.Diagnostics for _, scrapeConfig := range scrapeConfigs { - diags.AddAll(validatePrometheusScrape(scrapeConfig)) + diags.AddAll(component.ValidatePrometheusScrape(scrapeConfig)) diags.AddAll(ValidateServiceDiscoveryConfigs(scrapeConfig.ServiceDiscoveryConfigs)) } return diags @@ -88,52 +69,7 @@ func ValidateServiceDiscoveryConfigs(serviceDiscoveryConfigs prom_discover.Confi var diags diag.Diagnostics for _, serviceDiscoveryConfig := range serviceDiscoveryConfigs { - switch sdc := serviceDiscoveryConfig.(type) { - case prom_discover.StaticConfig: - diags.AddAll(validateScrapeTargets(sdc)) - case *prom_azure.SDConfig: - diags.AddAll(validateDiscoveryAzure(sdc)) - case *prom_consul.SDConfig: - diags.AddAll(validateDiscoveryConsul(sdc)) - case *prom_digitalocean.SDConfig: - diags.AddAll(validateDiscoveryDigitalOcean(sdc)) - case *prom_dns.SDConfig: - diags.AddAll(validateDiscoveryDns(sdc)) - case *prom_docker.DockerSDConfig: - diags.AddAll(validateDiscoveryDocker(sdc)) - case *prom_aws.EC2SDConfig: - diags.AddAll(validateDiscoveryEC2(sdc)) - case *prom_file.SDConfig: - diags.AddAll(validateDiscoveryFile(sdc)) - case *prom_gce.SDConfig: - diags.AddAll(validateDiscoveryGCE(sdc)) - case *prom_kubernetes.SDConfig: - diags.AddAll(validateDiscoveryKubernetes(sdc)) - case *prom_aws.LightsailSDConfig: - diags.AddAll(validateDiscoveryLightsail(sdc)) - case *prom_kuma.SDConfig: - diags.AddAll(validateDiscoveryKuma(sdc)) - case *prom_linode.SDConfig: - diags.AddAll(validateDiscoveryLinode(sdc)) - case *prom_triton.SDConfig: - diags.AddAll(validateDiscoveryTriton(sdc)) - case *prom_scaleway.SDConfig: - diags.AddAll(validateDiscoveryScaleway(sdc)) - case *prom_marathon.SDConfig: - diags.AddAll(validateDiscoveryMarathon(sdc)) - case *prom_ionos.SDConfig: - diags.AddAll(validateDiscoveryIonos(sdc)) - case *prom_zk.ServersetSDConfig: - diags.AddAll(validateDiscoveryServerset(sdc)) - case *prom_nerve.NerveSDConfig: - diags.AddAll(validateDiscoveryNerve(sdc)) - case *prom_openstack.SDConfig: - diags.AddAll(validateDiscoveryOpenstack(sdc)) - case *prom_moby.DockerSwarmSDConfig: - diags.AddAll(validateDiscoveryDockerswarm(sdc)) - default: - diags.Add(diag.SeverityLevelError, fmt.Sprintf("unsupported service discovery %s was provided", serviceDiscoveryConfig.Name())) - } + diags.AddAll(component.ValidateServiceDiscoveryConfig(serviceDiscoveryConfig)) } return diags @@ -161,7 +97,7 @@ func validateRemoteWriteConfigs(remoteWriteConfigs []*prom_config.RemoteWriteCon var diags diag.Diagnostics for _, remoteWriteConfig := range remoteWriteConfigs { - diags.AddAll(validateRemoteWriteConfig(remoteWriteConfig)) + diags.AddAll(component.ValidateRemoteWriteConfig(remoteWriteConfig)) } return diags diff --git a/converter/internal/promtailconvert/internal/build/consul_agent.go b/converter/internal/promtailconvert/internal/build/consul_agent.go index 079353e4b086..97976f1d2bb0 100644 --- a/converter/internal/promtailconvert/internal/build/consul_agent.go +++ b/converter/internal/promtailconvert/internal/build/consul_agent.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery/consulagent" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" promtail_consulagent "github.com/grafana/loki/clients/pkg/promtail/discovery/consulagent" "github.com/grafana/river/rivertypes" ) @@ -52,6 +51,6 @@ func toDiscoveryAgentConsul(sdConfig *promtail_consulagent.SDConfig, diags *diag Password: rivertypes.Secret(sdConfig.Password), Services: sdConfig.Services, ServiceTags: sdConfig.ServiceTags, - TLSConfig: *prometheusconvert.ToTLSConfig(&sdConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&sdConfig.TLSConfig), } } diff --git a/converter/internal/promtailconvert/internal/build/kafka.go b/converter/internal/promtailconvert/internal/build/kafka.go index 740a6b2d9cd6..c92740bdbf95 100644 --- a/converter/internal/promtailconvert/internal/build/kafka.go +++ b/converter/internal/promtailconvert/internal/build/kafka.go @@ -4,7 +4,6 @@ import ( "github.com/grafana/agent/component/common/relabel" "github.com/grafana/agent/component/loki/source/kafka" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" "github.com/grafana/river/rivertypes" ) @@ -48,13 +47,13 @@ func (s *ScrapeConfigBuilder) AppendKafka() { func convertKafkaAuthConfig(kafkaCfg *scrapeconfig.KafkaTargetConfig) kafka.KafkaAuthentication { return kafka.KafkaAuthentication{ Type: string(kafkaCfg.Authentication.Type), - TLSConfig: *prometheusconvert.ToTLSConfig(&kafkaCfg.Authentication.TLSConfig), + TLSConfig: *common.ToTLSConfig(&kafkaCfg.Authentication.TLSConfig), SASLConfig: kafka.KafkaSASLConfig{ Mechanism: string(kafkaCfg.Authentication.SASLConfig.Mechanism), User: kafkaCfg.Authentication.SASLConfig.User, Password: kafkaCfg.Authentication.SASLConfig.Password.String(), UseTLS: kafkaCfg.Authentication.SASLConfig.UseTLS, - TLSConfig: *prometheusconvert.ToTLSConfig(&kafkaCfg.Authentication.SASLConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&kafkaCfg.Authentication.SASLConfig.TLSConfig), }, } } diff --git a/converter/internal/promtailconvert/internal/build/loki_write.go b/converter/internal/promtailconvert/internal/build/loki_write.go index d7016d3bbc8c..562f15b0afd5 100644 --- a/converter/internal/promtailconvert/internal/build/loki_write.go +++ b/converter/internal/promtailconvert/internal/build/loki_write.go @@ -8,7 +8,6 @@ import ( lokiwrite "github.com/grafana/agent/component/loki/write" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/loki/clients/pkg/promtail/client" lokiflag "github.com/grafana/loki/pkg/util/flagext" "github.com/grafana/river/token/builder" @@ -45,7 +44,7 @@ func toLokiWriteArguments(config *client.Config, diags *diag.Diagnostics) *lokiw URL: config.URL.String(), BatchWait: config.BatchWait, BatchSize: batchSize, - HTTPClientConfig: prometheusconvert.ToHttpClientConfig(&config.Client), + HTTPClientConfig: common.ToHttpClientConfig(&config.Client), Headers: config.Headers, MinBackoff: config.BackoffConfig.MinBackoff, MaxBackoff: config.BackoffConfig.MaxBackoff, diff --git a/converter/internal/promtailconvert/internal/build/scrape_builder.go b/converter/internal/promtailconvert/internal/build/scrape_builder.go index 975da539e446..fc26d29cc832 100644 --- a/converter/internal/promtailconvert/internal/build/scrape_builder.go +++ b/converter/internal/promtailconvert/internal/build/scrape_builder.go @@ -15,7 +15,7 @@ import ( lokisourcefile "github.com/grafana/agent/component/loki/source/file" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" + "github.com/grafana/agent/converter/internal/prometheusconvert/component" "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" "github.com/grafana/loki/clients/pkg/promtail/targets/file" "github.com/grafana/river/scanner" @@ -102,7 +102,7 @@ func (s *ScrapeConfigBuilder) getOrNewLokiRelabel() string { if s.lokiRelabelReceiverExpr == "" { args := lokirelabel.Arguments{ ForwardTo: s.getOrNewProcessStageReceivers(), - RelabelConfigs: prometheusconvert.ToFlowRelabelConfigs(s.cfg.RelabelConfigs), + RelabelConfigs: component.ToFlowRelabelConfigs(s.cfg.RelabelConfigs), } compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) s.f.Body().AppendBlock(common.NewBlockWithOverride([]string{"loki", "relabel"}, compLabel, args)) @@ -148,7 +148,7 @@ func (s *ScrapeConfigBuilder) appendDiscoveryRelabel() { return } - relabelConfigs := prometheusconvert.ToFlowRelabelConfigs(s.cfg.RelabelConfigs) + relabelConfigs := component.ToFlowRelabelConfigs(s.cfg.RelabelConfigs) args := relabel.Arguments{ RelabelConfigs: relabelConfigs, } diff --git a/converter/internal/promtailconvert/internal/build/service_discovery.go b/converter/internal/promtailconvert/internal/build/service_discovery.go index a1900279f98b..37489bc66c59 100644 --- a/converter/internal/promtailconvert/internal/build/service_discovery.go +++ b/converter/internal/promtailconvert/internal/build/service_discovery.go @@ -5,6 +5,7 @@ import ( "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" "github.com/grafana/agent/converter/internal/prometheusconvert" + "github.com/grafana/agent/converter/internal/prometheusconvert/build" "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" prom_discover "github.com/prometheus/prometheus/discovery" @@ -16,7 +17,7 @@ func (s *ScrapeConfigBuilder) AppendSDs() { return } - pb := prometheusconvert.NewPrometheusBlocks() + pb := build.NewPrometheusBlocks() targets := prometheusconvert.AppendServiceDiscoveryConfigs(pb, sdConfigs, common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName)) pb.AppendToFile(s.f) diff --git a/converter/internal/promtailconvert/internal/build/syslog.go b/converter/internal/promtailconvert/internal/build/syslog.go index 10275a26f0fe..47b4c52d5bbe 100644 --- a/converter/internal/promtailconvert/internal/build/syslog.go +++ b/converter/internal/promtailconvert/internal/build/syslog.go @@ -4,7 +4,6 @@ import ( "github.com/grafana/agent/component/common/relabel" "github.com/grafana/agent/component/loki/source/syslog" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" ) func (s *ScrapeConfigBuilder) AppendSyslogConfig() { @@ -20,7 +19,7 @@ func (s *ScrapeConfigBuilder) AppendSyslogConfig() { UseIncomingTimestamp: s.cfg.SyslogConfig.UseIncomingTimestamp, UseRFC5424Message: s.cfg.SyslogConfig.UseRFC5424Message, MaxMessageLength: s.cfg.SyslogConfig.MaxMessageLength, - TLSConfig: *prometheusconvert.ToTLSConfig(&s.cfg.SyslogConfig.TLSConfig), + TLSConfig: *common.ToTLSConfig(&s.cfg.SyslogConfig.TLSConfig), } args := syslog.Arguments{ diff --git a/converter/internal/staticconvert/internal/build/apache_exporter.go b/converter/internal/staticconvert/internal/build/apache_exporter.go index 75932d7169ca..ec064c10422e 100644 --- a/converter/internal/staticconvert/internal/build/apache_exporter.go +++ b/converter/internal/staticconvert/internal/build/apache_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/apache" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/apache_http" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendApacheExporter(config *apache_http.C args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.apache.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.apache.%s.targets", compLabel)) } func toApacheExporter(config *apache_http.Config) *apache.Arguments { diff --git a/converter/internal/staticconvert/internal/build/azure_exporter.go b/converter/internal/staticconvert/internal/build/azure_exporter.go index d563a52906a7..2f55f5ff1b4e 100644 --- a/converter/internal/staticconvert/internal/build/azure_exporter.go +++ b/converter/internal/staticconvert/internal/build/azure_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/azure" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/azure_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendAzureExporter(config *azure_exporter args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.azure.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.azure.%s.targets", compLabel)) } func toAzureExporter(config *azure_exporter.Config) *azure.Arguments { diff --git a/converter/internal/staticconvert/internal/build/blackbox_exporter.go b/converter/internal/staticconvert/internal/build/blackbox_exporter.go index e841d85f295c..5916ece64a28 100644 --- a/converter/internal/staticconvert/internal/build/blackbox_exporter.go +++ b/converter/internal/staticconvert/internal/build/blackbox_exporter.go @@ -7,7 +7,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/blackbox" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/blackbox_exporter" "github.com/grafana/river/rivertypes" ) @@ -21,7 +20,7 @@ func (b *IntegrationsV1ConfigBuilder) appendBlackboxExporter(config *blackbox_ex args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.blackbox.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.blackbox.%s.targets", compLabel)) } func toBlackboxExporter(config *blackbox_exporter.Config) *blackbox.Arguments { diff --git a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go index bbb1877633c4..5e21550142c9 100644 --- a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go +++ b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go @@ -7,7 +7,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/cadvisor" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" cadvisor_integration "github.com/grafana/agent/pkg/integrations/cadvisor" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendCadvisorExporter(config *cadvisor_in args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cadvisor.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cadvisor.%s.targets", compLabel)) } func toCadvisorExporter(config *cadvisor_integration.Config) *cadvisor.Arguments { diff --git a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go index 969530a80559..c84a7fd00395 100644 --- a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go +++ b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/cloudwatch" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/cloudwatch_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendCloudwatchExporter(config *cloudwatc args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cloudwatch.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.cloudwatch.%s.targets", compLabel)) } func toCloudwatchExporter(config *cloudwatch_exporter.Config) *cloudwatch.Arguments { diff --git a/converter/internal/staticconvert/internal/build/consul_exporter.go b/converter/internal/staticconvert/internal/build/consul_exporter.go index 954f08dfa92c..32a4c6736e5f 100644 --- a/converter/internal/staticconvert/internal/build/consul_exporter.go +++ b/converter/internal/staticconvert/internal/build/consul_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/consul" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/consul_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendConsulExporter(config *consul_export args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.consul.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.consul.%s.targets", compLabel)) } func toConsulExporter(config *consul_exporter.Config) *consul.Arguments { diff --git a/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go b/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go index f70b7e30349e..230e59e22827 100644 --- a/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go +++ b/converter/internal/staticconvert/internal/build/dnsmasq_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/dnsmasq" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/dnsmasq_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendDnsmasqExporter(config *dnsmasq_expo args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.dnsmasq.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.dnsmasq.%s.targets", compLabel)) } func toDnsmasqExporter(config *dnsmasq_exporter.Config) *dnsmasq.Arguments { diff --git a/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go b/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go index 087a9cbdfe1a..82d17e05b6f0 100644 --- a/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go +++ b/converter/internal/staticconvert/internal/build/elasticsearch_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/elasticsearch" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/elasticsearch_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendElasticsearchExporter(config *elasti args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.elasticsearch.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.elasticsearch.%s.targets", compLabel)) } func toElasticsearchExporter(config *elasticsearch_exporter.Config) *elasticsearch.Arguments { diff --git a/converter/internal/staticconvert/internal/build/gcp_exporter.go b/converter/internal/staticconvert/internal/build/gcp_exporter.go index d68db99e0cb8..24d194921c93 100644 --- a/converter/internal/staticconvert/internal/build/gcp_exporter.go +++ b/converter/internal/staticconvert/internal/build/gcp_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/gcp" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/gcp_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendGcpExporter(config *gcp_exporter.Con args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.gcp.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.gcp.%s.targets", compLabel)) } func toGcpExporter(config *gcp_exporter.Config) *gcp.Arguments { diff --git a/converter/internal/staticconvert/internal/build/github_exporter.go b/converter/internal/staticconvert/internal/build/github_exporter.go index 12d742c079be..9e4e3cd79e9a 100644 --- a/converter/internal/staticconvert/internal/build/github_exporter.go +++ b/converter/internal/staticconvert/internal/build/github_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/github" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/github_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendGithubExporter(config *github_export args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.github.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.github.%s.targets", compLabel)) } func toGithubExporter(config *github_exporter.Config) *github.Arguments { diff --git a/converter/internal/staticconvert/internal/build/kafka_exporter.go b/converter/internal/staticconvert/internal/build/kafka_exporter.go index 809bff5c8dc5..fbcfcc0b05ab 100644 --- a/converter/internal/staticconvert/internal/build/kafka_exporter.go +++ b/converter/internal/staticconvert/internal/build/kafka_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/kafka" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/kafka_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendKafkaExporter(config *kafka_exporter args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.kafka.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.kafka.%s.targets", compLabel)) } func toKafkaExporter(config *kafka_exporter.Config) *kafka.Arguments { diff --git a/converter/internal/staticconvert/internal/build/memcached_exporter.go b/converter/internal/staticconvert/internal/build/memcached_exporter.go index f970636adc34..c01622bbb3c2 100644 --- a/converter/internal/staticconvert/internal/build/memcached_exporter.go +++ b/converter/internal/staticconvert/internal/build/memcached_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/memcached" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/memcached_exporter" ) @@ -19,13 +18,13 @@ func (b *IntegrationsV1ConfigBuilder) appendMemcachedExporter(config *memcached_ args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.memcached.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.memcached.%s.targets", compLabel)) } func toMemcachedExporter(config *memcached_exporter.Config) *memcached.Arguments { return &memcached.Arguments{ Address: config.MemcachedAddress, Timeout: config.Timeout, - TLSConfig: prometheusconvert.ToTLSConfig(config.TLSConfig), + TLSConfig: common.ToTLSConfig(config.TLSConfig), } } diff --git a/converter/internal/staticconvert/internal/build/mongodb_exporter.go b/converter/internal/staticconvert/internal/build/mongodb_exporter.go index 6f3da9135307..efae1b043898 100644 --- a/converter/internal/staticconvert/internal/build/mongodb_exporter.go +++ b/converter/internal/staticconvert/internal/build/mongodb_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mongodb" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/mongodb_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendMongodbExporter(config *mongodb_expo args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mongodb.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mongodb.%s.targets", compLabel)) } func toMongodbExporter(config *mongodb_exporter.Config) *mongodb.Arguments { diff --git a/converter/internal/staticconvert/internal/build/mssql_exporter.go b/converter/internal/staticconvert/internal/build/mssql_exporter.go index a4b2de88e788..5d1dd142d366 100644 --- a/converter/internal/staticconvert/internal/build/mssql_exporter.go +++ b/converter/internal/staticconvert/internal/build/mssql_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mssql" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" mssql_exporter "github.com/grafana/agent/pkg/integrations/mssql" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendMssqlExporter(config *mssql_exporter args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mssql.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mssql.%s.targets", compLabel)) } func toMssqlExporter(config *mssql_exporter.Config) *mssql.Arguments { diff --git a/converter/internal/staticconvert/internal/build/mysqld_exporter.go b/converter/internal/staticconvert/internal/build/mysqld_exporter.go index f407222bc4fb..0f821fa10f68 100644 --- a/converter/internal/staticconvert/internal/build/mysqld_exporter.go +++ b/converter/internal/staticconvert/internal/build/mysqld_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/mysql" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/mysqld_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendMysqldExporter(config *mysqld_export args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mysql.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mysql.%s.targets", compLabel)) } func toMysqldExporter(config *mysqld_exporter.Config) *mysql.Arguments { diff --git a/converter/internal/staticconvert/internal/build/node_exporter.go b/converter/internal/staticconvert/internal/build/node_exporter.go index f0b76e0a273e..13462edd40ff 100644 --- a/converter/internal/staticconvert/internal/build/node_exporter.go +++ b/converter/internal/staticconvert/internal/build/node_exporter.go @@ -4,7 +4,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/unix" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/node_exporter" ) @@ -16,7 +15,7 @@ func (b *IntegrationsV1ConfigBuilder) appendNodeExporter(config *node_exporter.C args, )) - return prometheusconvert.NewDiscoveryExports("prometheus.exporter.unix.default.targets") + return common.NewDiscoveryExports("prometheus.exporter.unix.default.targets") } func toNodeExporter(config *node_exporter.Config) *unix.Arguments { diff --git a/converter/internal/staticconvert/internal/build/oracledb_exporter.go b/converter/internal/staticconvert/internal/build/oracledb_exporter.go index 3ab4af44a171..d8edb0bf0a40 100644 --- a/converter/internal/staticconvert/internal/build/oracledb_exporter.go +++ b/converter/internal/staticconvert/internal/build/oracledb_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/oracledb" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/oracledb_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendOracledbExporter(config *oracledb_ex args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.oracledb.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.oracledb.%s.targets", compLabel)) } func toOracledbExporter(config *oracledb_exporter.Config) *oracledb.Arguments { diff --git a/converter/internal/staticconvert/internal/build/postgres_exporter.go b/converter/internal/staticconvert/internal/build/postgres_exporter.go index 5c62d559734f..c87343933f6f 100644 --- a/converter/internal/staticconvert/internal/build/postgres_exporter.go +++ b/converter/internal/staticconvert/internal/build/postgres_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/postgres" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/postgres_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendPostgresExporter(config *postgres_ex args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.postgres.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.postgres.%s.targets", compLabel)) } func toPostgresExporter(config *postgres_exporter.Config) *postgres.Arguments { diff --git a/converter/internal/staticconvert/internal/build/process_exporter.go b/converter/internal/staticconvert/internal/build/process_exporter.go index 34f5af3862bf..104d85fcfac4 100644 --- a/converter/internal/staticconvert/internal/build/process_exporter.go +++ b/converter/internal/staticconvert/internal/build/process_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/process" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/process_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendProcessExporter(config *process_expo args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.process.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.process.%s.targets", compLabel)) } func toProcessExporter(config *process_exporter.Config) *process.Arguments { diff --git a/converter/internal/staticconvert/internal/build/redis_exporter.go b/converter/internal/staticconvert/internal/build/redis_exporter.go index 9de8db64ebc4..3c03b4171418 100644 --- a/converter/internal/staticconvert/internal/build/redis_exporter.go +++ b/converter/internal/staticconvert/internal/build/redis_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/redis" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/redis_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendRedisExporter(config *redis_exporter args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.redis.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.redis.%s.targets", compLabel)) } func toRedisExporter(config *redis_exporter.Config) *redis.Arguments { diff --git a/converter/internal/staticconvert/internal/build/snmp_exporter.go b/converter/internal/staticconvert/internal/build/snmp_exporter.go index 0cc1252a38e8..a0df3bb3c109 100644 --- a/converter/internal/staticconvert/internal/build/snmp_exporter.go +++ b/converter/internal/staticconvert/internal/build/snmp_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/snmp" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/snmp_exporter" "github.com/grafana/river/rivertypes" snmp_config "github.com/prometheus/snmp_exporter/config" @@ -21,7 +20,7 @@ func (b *IntegrationsV1ConfigBuilder) appendSnmpExporter(config *snmp_exporter.C args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snmp.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snmp.%s.targets", compLabel)) } func toSnmpExporter(config *snmp_exporter.Config) *snmp.Arguments { diff --git a/converter/internal/staticconvert/internal/build/snowflake_exporter.go b/converter/internal/staticconvert/internal/build/snowflake_exporter.go index 0865be7bd4bb..6ca50c1f01f8 100644 --- a/converter/internal/staticconvert/internal/build/snowflake_exporter.go +++ b/converter/internal/staticconvert/internal/build/snowflake_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/snowflake" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/snowflake_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendSnowflakeExporter(config *snowflake_ args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snowflake.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.snowflake.%s.targets", compLabel)) } func toSnowflakeExporter(config *snowflake_exporter.Config) *snowflake.Arguments { diff --git a/converter/internal/staticconvert/internal/build/squid_exporter.go b/converter/internal/staticconvert/internal/build/squid_exporter.go index 567edd780f25..48a5682ff699 100644 --- a/converter/internal/staticconvert/internal/build/squid_exporter.go +++ b/converter/internal/staticconvert/internal/build/squid_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/squid" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/squid_exporter" "github.com/grafana/river/rivertypes" ) @@ -20,7 +19,7 @@ func (b *IntegrationsV1ConfigBuilder) appendSquidExporter(config *squid_exporter args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.squid.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.squid.%s.targets", compLabel)) } func toSquidExporter(config *squid_exporter.Config) *squid.Arguments { diff --git a/converter/internal/staticconvert/internal/build/statsd_exporter.go b/converter/internal/staticconvert/internal/build/statsd_exporter.go index 11735f81f1d7..784aca4d54df 100644 --- a/converter/internal/staticconvert/internal/build/statsd_exporter.go +++ b/converter/internal/staticconvert/internal/build/statsd_exporter.go @@ -7,7 +7,6 @@ import ( "github.com/grafana/agent/component/prometheus/exporter/statsd" "github.com/grafana/agent/converter/diag" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/statsd_exporter" ) @@ -24,7 +23,7 @@ func (b *IntegrationsV1ConfigBuilder) appendStatsdExporter(config *statsd_export b.diags.Add(diag.SeverityLevelError, "mapping_config is not supported in statsd_exporter integrations config") } - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.statsd.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.statsd.%s.targets", compLabel)) } func toStatsdExporter(config *statsd_exporter.Config) *statsd.Arguments { diff --git a/converter/internal/staticconvert/internal/build/windows_exporter.go b/converter/internal/staticconvert/internal/build/windows_exporter.go index 7fca4644c12e..335dfd25ad47 100644 --- a/converter/internal/staticconvert/internal/build/windows_exporter.go +++ b/converter/internal/staticconvert/internal/build/windows_exporter.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/agent/component/discovery" "github.com/grafana/agent/component/prometheus/exporter/windows" "github.com/grafana/agent/converter/internal/common" - "github.com/grafana/agent/converter/internal/prometheusconvert" "github.com/grafana/agent/pkg/integrations/windows_exporter" ) @@ -19,7 +18,7 @@ func (b *IntegrationsV1ConfigBuilder) appendWindowsExporter(config *windows_expo args, )) - return prometheusconvert.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.windows.%s.targets", compLabel)) + return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.windows.%s.targets", compLabel)) } func toWindowsExporter(config *windows_exporter.Config) *windows.Arguments {