forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promtail config conversion - part 2 (grafana#4500)
* wip * fixes * static SD * file discovery * consul * consul, DO, docker swarm * other unsupported * GCE * format-yaml * ec2 * azure * todos * server validation * loki push api * goimports * fix issue in prometheus/discovery/relabel * fix lint * fix another test case * use random port * move loki.write to own file
- Loading branch information
Showing
63 changed files
with
1,216 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/weaveworks/common/server" | ||
) | ||
|
||
func DefaultWeaveWorksServerCfg() server.Config { | ||
cfg := server.Config{} | ||
// NOTE: due to a bug in promtail, the default server values for loki_push_api are not applied currently, so | ||
// we need to comment out the following line. | ||
//cfg.RegisterFlags(flag.NewFlagSet("", flag.PanicOnError)) | ||
return cfg | ||
} | ||
|
||
func ValidateWeaveWorksServerCfg(cfg server.Config) diag.Diagnostics { | ||
var ( | ||
diags diag.Diagnostics | ||
defaultCfg = DefaultWeaveWorksServerCfg() | ||
) | ||
|
||
if cfg.HTTPListenNetwork != defaultCfg.HTTPListenNetwork { | ||
diags.Add(diag.SeverityLevelError, "http_listen_network is not supported in server config") | ||
} | ||
if cfg.GRPCListenNetwork != defaultCfg.GRPCListenNetwork { | ||
diags.Add(diag.SeverityLevelError, "grpc_listen_network is not supported in server config") | ||
} | ||
if cfg.CipherSuites != defaultCfg.CipherSuites { | ||
diags.Add(diag.SeverityLevelError, "tls_cipher_suites is not supported in server config") | ||
} | ||
if cfg.MinVersion != defaultCfg.MinVersion { | ||
diags.Add(diag.SeverityLevelError, "tls_min_version is not supported in server config") | ||
} | ||
if cfg.HTTPTLSConfig != defaultCfg.HTTPTLSConfig { | ||
diags.Add(diag.SeverityLevelError, "http_tls_config is not supported in server config") | ||
} | ||
if cfg.GRPCTLSConfig != defaultCfg.GRPCTLSConfig { | ||
diags.Add(diag.SeverityLevelError, "grpc_tls_config is not supported in server config") | ||
} | ||
if cfg.RegisterInstrumentation { | ||
diags.Add(diag.SeverityLevelError, "register_instrumentation is not supported in server config") | ||
} | ||
if cfg.ServerGracefulShutdownTimeout != defaultCfg.ServerGracefulShutdownTimeout { | ||
diags.Add(diag.SeverityLevelError, "graceful_shutdown_timeout is not supported in server config") | ||
} | ||
if cfg.GRPCServerTime != defaultCfg.GRPCServerTime { | ||
diags.Add(diag.SeverityLevelError, "grpc_server_keepalive_time is not supported in server config") | ||
} | ||
if cfg.GRPCServerTimeout != defaultCfg.GRPCServerTimeout { | ||
diags.Add(diag.SeverityLevelError, "grpc_server_keepalive_timeout is not supported in server config") | ||
} | ||
if cfg.GRPCServerMinTimeBetweenPings != defaultCfg.GRPCServerMinTimeBetweenPings { | ||
diags.Add(diag.SeverityLevelError, "grpc_server_min_time_between_pings is not supported in server config") | ||
} | ||
if cfg.GRPCServerPingWithoutStreamAllowed != defaultCfg.GRPCServerPingWithoutStreamAllowed { | ||
diags.Add(diag.SeverityLevelError, "grpc_server_ping_without_stream_allowed is not supported in server config") | ||
} | ||
if cfg.LogFormat != defaultCfg.LogFormat { | ||
diags.Add(diag.SeverityLevelError, "log_format is not supported in server config") | ||
} | ||
if cfg.LogLevel.String() != defaultCfg.LogLevel.String() { | ||
diags.Add(diag.SeverityLevelError, "log_level is not supported in server config") | ||
} | ||
if cfg.LogSourceIPs != defaultCfg.LogSourceIPs { | ||
diags.Add(diag.SeverityLevelError, "log_source_ips_enabled is not supported in server config") | ||
} | ||
if cfg.LogSourceIPsHeader != defaultCfg.LogSourceIPsHeader { | ||
diags.Add(diag.SeverityLevelError, "log_source_ips_header is not supported in server config") | ||
} | ||
if cfg.LogSourceIPsRegex != defaultCfg.LogSourceIPsRegex { | ||
diags.Add(diag.SeverityLevelError, "log_source_ips_regex is not supported in server config") | ||
} | ||
if cfg.LogRequestAtInfoLevel != defaultCfg.LogRequestAtInfoLevel { | ||
diags.Add(diag.SeverityLevelError, "log_request_at_info_level_enabled is not supported in server config") | ||
} | ||
if cfg.PathPrefix != defaultCfg.PathPrefix { | ||
diags.Add(diag.SeverityLevelError, "http_path_prefix is not supported in server config") | ||
} | ||
|
||
return diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
converter/internal/promtailconvert/internal/build/azure_sd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/converter/internal/prometheusconvert" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendAzureSDs() { | ||
if len(s.cfg.ServiceDiscoveryConfig.AzureSDConfigs) == 0 { | ||
return | ||
} | ||
for i, sd := range s.cfg.ServiceDiscoveryConfig.AzureSDConfigs { | ||
s.diags.AddAll(prometheusconvert.ValidateDiscoveryAzure(sd)) | ||
compName := fmt.Sprintf("%s_%d", s.cfg.JobName, i) | ||
|
||
args := prometheusconvert.ToDiscoveryAzure(sd) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverride( | ||
[]string{"discovery", "azure"}, | ||
compName, | ||
args, | ||
)) | ||
s.allTargetsExps = append(s.allTargetsExps, "discovery.azure."+compName+".targets") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
converter/internal/promtailconvert/internal/build/consul_agent.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package build | ||
|
||
import "github.com/grafana/agent/converter/diag" | ||
|
||
func (s *ScrapeConfigBuilder) AppendConsulAgentSDs() { | ||
// TODO: implement this | ||
if s.cfg.ServiceDiscoveryConfig.ConsulAgentSDConfigs != nil { | ||
s.diags.Add( | ||
diag.SeverityLevelError, | ||
"consul_agent SDs are not currently supported in Grafana Agent Flow - see https://github.com/grafana/agent/issues/2261", | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
converter/internal/promtailconvert/internal/build/consul_sd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/converter/internal/prometheusconvert" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendConsulSDs() { | ||
if len(s.cfg.ServiceDiscoveryConfig.ConsulSDConfigs) == 0 { | ||
return | ||
} | ||
|
||
for i, sd := range s.cfg.ServiceDiscoveryConfig.ConsulSDConfigs { | ||
args := prometheusconvert.ToDiscoveryConsul(sd) | ||
compLabel := fmt.Sprintf("consul_sd_%d", i) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverride( | ||
[]string{"discovery", "consul"}, | ||
compLabel, | ||
args, | ||
)) | ||
s.allTargetsExps = append(s.allTargetsExps, "discovery.consul."+compLabel+".targets") | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
converter/internal/promtailconvert/internal/build/digitalocean_sd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/converter/internal/prometheusconvert" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendDigitalOceanSDs() { | ||
if len(s.cfg.ServiceDiscoveryConfig.DigitalOceanSDConfigs) == 0 { | ||
return | ||
} | ||
for i, sd := range s.cfg.ServiceDiscoveryConfig.DigitalOceanSDConfigs { | ||
s.diags.AddAll(prometheusconvert.ValidateDiscoveryDigitalOcean(sd)) | ||
compName := fmt.Sprintf("%s_%d", s.cfg.JobName, i) | ||
|
||
args := prometheusconvert.ToDiscoveryDigitalOcean(sd) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverride( | ||
[]string{"discovery", "digitalocean"}, | ||
compName, | ||
args, | ||
)) | ||
s.allTargetsExps = append(s.allTargetsExps, "discovery.digitalocean."+compName+".targets") | ||
} | ||
} |
Oops, something went wrong.