Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ internal API changes are not present.
Main (unreleased)
-----------------

### Enhancements

- update promtail converter to use `file_match` block for `loki.source.file` instead of going through `local.file_match`. (@kalleep)

v1.12.0-rc.0
-----------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/grafana/alloy/internal/component/common/loki"
"github.com/grafana/alloy/internal/component/discovery"
"github.com/grafana/alloy/internal/component/discovery/relabel"
filematch "github.com/grafana/alloy/internal/component/local/file_match"
"github.com/grafana/alloy/internal/component/loki/process"
"github.com/grafana/alloy/internal/component/loki/process/stages"
lokirelabel "github.com/grafana/alloy/internal/component/loki/relabel"
Expand All @@ -32,12 +31,11 @@ type ScrapeConfigBuilder struct {
cfg *scrapeconfig.Config
globalCtx *GlobalContext

allTargetsExps []string
processStageReceivers []loki.LogsReceiver
allRelabeledTargetsExpr string
allExpandedFileTargetsExpr string
discoveryRelabelRulesExpr string
lokiRelabelReceiverExpr string
allTargetsExps []string
processStageReceivers []loki.LogsReceiver
allRelabeledTargetsExpr string
discoveryRelabelRulesExpr string
lokiRelabelReceiverExpr string
}

func NewScrapeConfigBuilder(
Expand Down Expand Up @@ -70,21 +68,18 @@ func (s *ScrapeConfigBuilder) AppendLokiSourceFile(watchConfig *file.WatchConfig
if len(s.allTargetsExps) == 0 {
return
}
targets := s.getExpandedFileTargetsExpr()
forwardTo := s.getOrNewProcessStageReceivers()

args := lokisourcefile.Arguments{
ForwardTo: forwardTo,
Encoding: s.cfg.Encoding,
DecompressionConfig: convertDecompressionConfig(s.cfg.DecompressionCfg),
FileWatch: convertFileWatchConfig(watchConfig),
FileMatch: lokisourcefile.FileMatch{
Enabled: false,
SyncPeriod: 10 * time.Second,
},
ForwardTo: s.getOrNewProcessStageReceivers(),
Encoding: s.cfg.Encoding,
DecompressionConfig: convertDecompressionConfig(s.cfg.DecompressionCfg),
FileWatch: convertFileWatchConfig(watchConfig),
LegacyPositionsFile: positionsCfg.PositionsFile,
OnPositionsFileError: lokisourcefile.OnPositionsFileErrorRestartBeginning,
FileMatch: convertFileMatchConfig(s.globalCtx.TargetSyncPeriod),
}

targets := s.getAllRelabeledTargetsExpr()
overrideHook := func(val interface{}) interface{} {
if _, ok := val.([]discovery.Target); ok {
return common.CustomTokenizer{Expr: targets}
Expand Down Expand Up @@ -194,31 +189,6 @@ func (s *ScrapeConfigBuilder) getOrNewDiscoveryRelabelRules() string {
return s.discoveryRelabelRulesExpr
}

func (s *ScrapeConfigBuilder) getExpandedFileTargetsExpr() string {
if s.allExpandedFileTargetsExpr != "" {
return s.allExpandedFileTargetsExpr
}
args := filematch.Arguments{
SyncPeriod: s.globalCtx.TargetSyncPeriod,
}
overrideHook := func(val interface{}) interface{} {
if _, ok := val.([]discovery.Target); ok {
return common.CustomTokenizer{Expr: s.getAllRelabeledTargetsExpr()}
}
return val
}

compLabel := common.LabelForParts(s.globalCtx.LabelPrefix, s.cfg.JobName)
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn(
[]string{"local", "file_match"},
compLabel,
args,
overrideHook,
))
s.allExpandedFileTargetsExpr = "local.file_match." + compLabel + ".targets"
return s.allExpandedFileTargetsExpr
}

func (s *ScrapeConfigBuilder) getAllTargetsJoinedExpr() string {
targetsExpr := "[]"
if len(s.allTargetsExps) == 1 {
Expand Down Expand Up @@ -262,6 +232,13 @@ func convertFileWatchConfig(watchConfig *file.WatchConfig) lokisourcefile.FileWa
}
}

func convertFileMatchConfig(sync time.Duration) lokisourcefile.FileMatch {
return lokisourcefile.FileMatch{
Enabled: true,
SyncPeriod: sync,
}
}

func logsReceiversToExpr(r []loki.LogsReceiver) string {
var exprs []string
for _, r := range r {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ discovery.azure "fun" {
}
}

local.file_match "fun" {
path_targets = discovery.azure.fun.targets
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.azure.fun.targets
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ discovery.relabel "fun" {
}
}

local.file_match "fun" {
path_targets = discovery.relabel.fun.output
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.relabel.fun.output
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ discovery.relabel "fun" {
}
}

local.file_match "fun" {
path_targets = discovery.relabel.fun.output
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.relabel.fun.output
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ discovery.digitalocean "fun" {
port = 1234
}

local.file_match "fun" {
path_targets = discovery.digitalocean.fun.targets
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.digitalocean.fun.targets
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ discovery.dockerswarm "fun_2" {
role = "services"
}

local.file_match "fun" {
path_targets = array.concat(
loki.source.file "fun" {
targets = array.concat(
discovery.dockerswarm.fun.targets,
discovery.dockerswarm.fun_2.targets,
)
}
forward_to = []

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
12 changes: 6 additions & 6 deletions internal/converter/internal/promtailconvert/testdata/ec2.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ discovery.ec2 "fun" {
port = 8080
}

local.file_match "fun" {
path_targets = discovery.ec2.fun.targets
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.ec2.fun.targets
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ discovery.file "fun_2" {
refresh_interval = "30m0s"
}

local.file_match "fun" {
path_targets = array.concat(
loki.source.file "fun" {
targets = array.concat(
discovery.file.fun.targets,
discovery.file.fun_2.targets,
)
}
forward_to = []

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
12 changes: 6 additions & 6 deletions internal/converter/internal/promtailconvert/testdata/gce.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ discovery.gce "fun" {
port = 8080
}

local.file_match "fun" {
path_targets = discovery.gce.fun.targets
}

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
targets = discovery.gce.fun.targets
forward_to = []

file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ discovery.file "fun_2" {
refresh_interval = "30m0s"
}

local.file_match "fun" {
path_targets = array.concat(
loki.source.file "fun" {
targets = array.concat(
discovery.file.fun.targets,
discovery.file.fun_2.targets,
)
}
forward_to = []

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/good/positions.yml"
}

Expand All @@ -29,15 +29,15 @@ discovery.file "fun2_2" {
refresh_interval = "30m0s"
}

local.file_match "fun2" {
path_targets = array.concat(
loki.source.file "fun2" {
targets = array.concat(
discovery.file.fun2.targets,
discovery.file.fun2_2.targets,
)
}
forward_to = []

loki.source.file "fun2" {
targets = local.file_match.fun2.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/good/positions.yml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ discovery.kubernetes "fun_5" {
proxy_from_environment = true
}

local.file_match "fun" {
path_targets = array.concat(
loki.source.file "fun" {
targets = array.concat(
discovery.kubernetes.fun.targets,
discovery.kubernetes.fun_2.targets,
discovery.kubernetes.fun_3.targets,
discovery.kubernetes.fun_4.targets,
discovery.kubernetes.fun_5.targets,
)
}
forward_to = []

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ discovery.marathon "fun_2" {
auth_token = "auth_token"
}

local.file_match "fun" {
path_targets = array.concat(
loki.source.file "fun" {
targets = array.concat(
discovery.marathon.fun.targets,
discovery.marathon.fun_2.targets,
)
}
forward_to = []

loki.source.file "fun" {
targets = local.file_match.fun.targets
forward_to = []
file_match {
enabled = true
}
legacy_positions_file = "/var/log/positions.yaml"
}
Loading
Loading