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 conversions part 3 (grafana#4638)
* Add windows events and kafka * Add azure event hubs * Add gelf * Add heroku
- Loading branch information
Showing
22 changed files
with
600 additions
and
12 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
42 changes: 42 additions & 0 deletions
42
converter/internal/promtailconvert/internal/build/azure_event_hub.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,42 @@ | ||
package build | ||
|
||
import ( | ||
"github.com/grafana/agent/component/common/relabel" | ||
"github.com/grafana/agent/component/loki/source/azure_event_hubs" | ||
"github.com/grafana/agent/converter/internal/common" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendAzureEventHubs() { | ||
if s.cfg.AzureEventHubsConfig == nil { | ||
return | ||
} | ||
aCfg := s.cfg.AzureEventHubsConfig | ||
args := azure_event_hubs.Arguments{ | ||
FullyQualifiedNamespace: aCfg.FullyQualifiedNamespace, | ||
EventHubs: aCfg.EventHubs, | ||
Authentication: azure_event_hubs.AzureEventHubsAuthentication{ | ||
ConnectionString: aCfg.ConnectionString, | ||
}, | ||
GroupID: aCfg.GroupID, | ||
UseIncomingTimestamp: aCfg.UseIncomingTimestamp, | ||
DisallowCustomMessages: aCfg.DisallowCustomMessages, | ||
RelabelRules: relabel.Rules{}, | ||
Labels: convertPromLabels(aCfg.Labels), | ||
ForwardTo: s.getOrNewProcessStageReceivers(), | ||
} | ||
override := func(val interface{}) interface{} { | ||
switch val.(type) { | ||
case relabel.Rules: | ||
return common.CustomTokenizer{Expr: s.getOrNewDiscoveryRelabelRules()} | ||
default: | ||
return val | ||
} | ||
} | ||
compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "azure_event_hubs"}, | ||
compLabel, | ||
args, | ||
override, | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package build | ||
|
||
import ( | ||
"github.com/grafana/agent/component/common/relabel" | ||
"github.com/grafana/agent/component/loki/source/gelf" | ||
"github.com/grafana/agent/converter/internal/common" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendGelfConfig() { | ||
if s.cfg.GelfConfig == nil { | ||
return | ||
} | ||
gCfg := s.cfg.GelfConfig | ||
args := gelf.Arguments{ | ||
ListenAddress: gCfg.ListenAddress, | ||
UseIncomingTimestamp: gCfg.UseIncomingTimestamp, | ||
RelabelRules: relabel.Rules{}, | ||
Receivers: s.getOrNewProcessStageReceivers(), | ||
} | ||
override := func(val interface{}) interface{} { | ||
switch val.(type) { | ||
case relabel.Rules: | ||
return common.CustomTokenizer{Expr: s.getOrNewDiscoveryRelabelRules()} | ||
default: | ||
return val | ||
} | ||
} | ||
compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "gelf"}, | ||
compLabel, | ||
args, | ||
override, | ||
)) | ||
} |
36 changes: 36 additions & 0 deletions
36
converter/internal/promtailconvert/internal/build/herokudrain.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,36 @@ | ||
package build | ||
|
||
import ( | ||
"github.com/grafana/agent/component/common/relabel" | ||
"github.com/grafana/agent/component/loki/source/heroku" | ||
"github.com/grafana/agent/converter/internal/common" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendHerokuDrainConfig() { | ||
if s.cfg.HerokuDrainConfig == nil { | ||
return | ||
} | ||
hCfg := s.cfg.HerokuDrainConfig | ||
args := heroku.Arguments{ | ||
Server: common.WeaveWorksServerToFlowServer(hCfg.Server), | ||
Labels: convertPromLabels(hCfg.Labels), | ||
UseIncomingTimestamp: hCfg.UseIncomingTimestamp, | ||
ForwardTo: s.getOrNewProcessStageReceivers(), | ||
RelabelRules: relabel.Rules{}, | ||
} | ||
override := func(val interface{}) interface{} { | ||
switch val.(type) { | ||
case relabel.Rules: | ||
return common.CustomTokenizer{Expr: s.getOrNewDiscoveryRelabelRules()} | ||
default: | ||
return val | ||
} | ||
} | ||
compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "heroku"}, | ||
compLabel, | ||
args, | ||
override, | ||
)) | ||
} |
60 changes: 60 additions & 0 deletions
60
converter/internal/promtailconvert/internal/build/kafka.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,60 @@ | ||
package build | ||
|
||
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/agent/pkg/river/rivertypes" | ||
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendKafka() { | ||
if s.cfg.KafkaConfig == nil { | ||
return | ||
} | ||
kafkaCfg := s.cfg.KafkaConfig | ||
args := kafka.Arguments{ | ||
Brokers: kafkaCfg.Brokers, | ||
Topics: kafkaCfg.Topics, | ||
GroupID: kafkaCfg.GroupID, | ||
Assignor: kafkaCfg.Assignor, | ||
Version: kafkaCfg.Version, | ||
Authentication: convertKafkaAuthConfig(kafkaCfg), | ||
UseIncomingTimestamp: kafkaCfg.UseIncomingTimestamp, | ||
Labels: convertPromLabels(kafkaCfg.Labels), | ||
ForwardTo: s.getOrNewProcessStageReceivers(), | ||
RelabelRules: relabel.Rules{}, | ||
} | ||
override := func(val interface{}) interface{} { | ||
switch value := val.(type) { | ||
case relabel.Rules: | ||
return common.CustomTokenizer{Expr: s.getOrNewDiscoveryRelabelRules()} | ||
case rivertypes.Secret: | ||
return string(value) | ||
default: | ||
return val | ||
} | ||
} | ||
compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "kafka"}, | ||
compLabel, | ||
args, | ||
override, | ||
)) | ||
} | ||
|
||
func convertKafkaAuthConfig(kafkaCfg *scrapeconfig.KafkaTargetConfig) kafka.KafkaAuthentication { | ||
return kafka.KafkaAuthentication{ | ||
Type: string(kafkaCfg.Authentication.Type), | ||
TLSConfig: *prometheusconvert.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), | ||
}, | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
converter/internal/promtailconvert/internal/build/windows_events.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,46 @@ | ||
package build | ||
|
||
import ( | ||
"github.com/grafana/agent/component/common/loki" | ||
"github.com/grafana/agent/component/loki/source/windowsevent" | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/grafana/agent/converter/internal/common" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendWindowsEventsConfig() { | ||
if s.cfg.WindowsConfig == nil { | ||
return | ||
} | ||
winCfg := s.cfg.WindowsConfig | ||
if len(winCfg.Labels) != 0 { | ||
// TODO: Add support for labels - see https://github.com/grafana/agent/issues/4634 for more details | ||
s.diags.Add(diag.SeverityLevelError, "windows_events.labels are currently not supported") | ||
} | ||
args := windowsevent.Arguments{ | ||
Locale: int(winCfg.Locale), | ||
EventLogName: winCfg.EventlogName, | ||
XPathQuery: winCfg.Query, | ||
BookmarkPath: winCfg.BookmarkPath, | ||
PollInterval: winCfg.PollInterval, | ||
ExcludeEventData: winCfg.ExcludeEventData, | ||
ExcludeUserdata: winCfg.ExcludeUserData, | ||
UseIncomingTimestamp: winCfg.UseIncomingTimestamp, | ||
ForwardTo: make([]loki.LogsReceiver, 0), | ||
} | ||
|
||
override := func(val interface{}) interface{} { | ||
switch val.(type) { | ||
case []loki.LogsReceiver: | ||
return common.CustomTokenizer{Expr: s.getOrNewLokiRelabel()} | ||
default: | ||
return val | ||
} | ||
} | ||
compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName) | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "windowsevent"}, | ||
compLabel, | ||
args, | ||
override, | ||
)) | ||
} |
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
37 changes: 37 additions & 0 deletions
37
converter/internal/promtailconvert/testdata/azure_event_hubs.river
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
discovery.relabel "fun" { | ||
targets = [] | ||
|
||
rule { | ||
source_labels = ["__trail__"] | ||
target_label = "__path__" | ||
} | ||
} | ||
|
||
loki.source.azure_event_hubs "fun" { | ||
fully_qualified_namespace = "robin.servicebus.windows.net" | ||
event_hubs = ["hub0", "hub1"] | ||
|
||
authentication { | ||
mechanism = "" | ||
connection_string = "Endpoint=sb://<NamespaceName>.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<KeyValue>" | ||
} | ||
group_id = "my_consumer_group" | ||
use_incoming_timestamp = true | ||
disallow_custom_messages = true | ||
relabel_rules = discovery.relabel.fun.rules | ||
labels = { | ||
job = "fun", | ||
quality = "excellent", | ||
} | ||
assignor = "" | ||
forward_to = [loki.write.default.receiver] | ||
} | ||
|
||
loki.write "default" { | ||
endpoint { | ||
url = "http://localhost/loki/api/v1/push" | ||
follow_redirects = false | ||
enable_http2 = false | ||
} | ||
external_labels = {} | ||
} |
22 changes: 22 additions & 0 deletions
22
converter/internal/promtailconvert/testdata/azure_event_hubs.yaml
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,22 @@ | ||
clients: | ||
- url: http://localhost/loki/api/v1/push | ||
scrape_configs: | ||
- job_name: fun | ||
relabel_configs: | ||
- source_labels: | ||
- __trail__ | ||
target_label: __path__ | ||
azure_event_hubs: | ||
labels: | ||
job: fun | ||
quality: excellent | ||
use_incoming_timestamp: true | ||
event_hubs: | ||
- hub0 | ||
- hub1 | ||
connection_string: Endpoint=sb://<NamespaceName>.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<KeyValue> | ||
fully_qualified_namespace: robin.servicebus.windows.net | ||
group_id: my_consumer_group | ||
disallow_custom_messages: true | ||
tracing: {enabled: false} | ||
server: {register_instrumentation: false} |
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,24 @@ | ||
discovery.relabel "fun" { | ||
targets = [] | ||
|
||
rule { | ||
source_labels = ["__trail__"] | ||
target_label = "__path__" | ||
} | ||
} | ||
|
||
loki.source.gelf "fun" { | ||
listen_address = "localhost:12201" | ||
use_incoming_timestamp = true | ||
relabel_rules = discovery.relabel.fun.rules | ||
forward_to = [loki.write.default.receiver] | ||
} | ||
|
||
loki.write "default" { | ||
endpoint { | ||
url = "http://localhost/loki/api/v1/push" | ||
follow_redirects = false | ||
enable_http2 = false | ||
} | ||
external_labels = {} | ||
} |
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,16 @@ | ||
clients: | ||
- url: http://localhost/loki/api/v1/push | ||
scrape_configs: | ||
- job_name: fun | ||
relabel_configs: | ||
- source_labels: | ||
- __trail__ | ||
target_label: __path__ | ||
gelf: | ||
listen_address: localhost:12201 | ||
labels: | ||
job: fun | ||
quality: excellent | ||
use_incoming_timestamp: true | ||
tracing: {enabled: false} | ||
server: {register_instrumentation: false} |
Oops, something went wrong.