-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,394 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/grafana/agent/component/common/loki" | ||
"github.com/grafana/agent/pkg/river" | ||
"github.com/grafana/agent/pkg/river/token" | ||
"github.com/grafana/agent/pkg/river/token/builder" | ||
) | ||
|
||
// ConvertLogsReceiver allows us to override how the loki.LogsReceiver is tokenized. | ||
// See ConvertAppendable as another example with more details in comments. | ||
type ConvertLogsReceiver struct { | ||
loki.LogsReceiver | ||
|
||
Expr string | ||
} | ||
|
||
var _ loki.LogsReceiver = (*ConvertLogsReceiver)(nil) | ||
var _ builder.Tokenizer = ConvertLogsReceiver{} | ||
var _ river.Capsule = ConvertLogsReceiver{} | ||
|
||
func (f ConvertLogsReceiver) RiverCapsule() {} | ||
func (f ConvertLogsReceiver) RiverTokenize() []builder.Token { | ||
return []builder.Token{{ | ||
Tok: token.STRING, | ||
Lit: f.Expr, | ||
}} | ||
} |
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,19 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/grafana/agent/pkg/river/token" | ||
"github.com/grafana/agent/pkg/river/token/builder" | ||
) | ||
|
||
type CustomTokenizer struct { | ||
Expr string | ||
} | ||
|
||
var _ builder.Tokenizer = CustomTokenizer{} | ||
|
||
func (f CustomTokenizer) RiverTokenize() []builder.Token { | ||
return []builder.Token{{ | ||
Tok: token.STRING, | ||
Lit: f.Expr, | ||
}} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
converter/internal/promtailconvert/internal/build/cloudflare.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 ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/grafana/agent/component/common/loki" | ||
"github.com/grafana/agent/component/loki/source/cloudflare" | ||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/pkg/river/rivertypes" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendCloudFlareConfig() { | ||
if s.cfg.CloudflareConfig == nil { | ||
return | ||
} | ||
|
||
args := cloudflare.Arguments{ | ||
APIToken: rivertypes.Secret(s.cfg.CloudflareConfig.APIToken), | ||
ZoneID: s.cfg.CloudflareConfig.ZoneID, | ||
Labels: convertPromLabels(s.cfg.CloudflareConfig.Labels), | ||
Workers: s.cfg.CloudflareConfig.Workers, | ||
PullRange: time.Duration(s.cfg.CloudflareConfig.PullRange), | ||
FieldsType: s.cfg.CloudflareConfig.FieldsType, | ||
} | ||
override := func(val interface{}) interface{} { | ||
switch conv := val.(type) { | ||
case []loki.LogsReceiver: | ||
return common.CustomTokenizer{Expr: fmt.Sprintf("[%s]", s.getOrNewLokiRelabel())} | ||
case rivertypes.Secret: | ||
return string(conv) | ||
default: | ||
return val | ||
} | ||
} | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "cloudfare"}, | ||
s.cfg.JobName, | ||
args, | ||
override, | ||
)) | ||
} |
12 changes: 12 additions & 0 deletions
12
converter/internal/promtailconvert/internal/build/global_context.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,12 @@ | ||
package build | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/grafana/agent/component/common/loki" | ||
) | ||
|
||
type GlobalContext struct { | ||
WriteReceivers []loki.LogsReceiver | ||
TargetSyncPeriod time.Duration | ||
} |
47 changes: 47 additions & 0 deletions
47
converter/internal/promtailconvert/internal/build/journal.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,47 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
flowrelabel "github.com/grafana/agent/component/common/relabel" | ||
"github.com/grafana/agent/component/loki/source/journal" | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/grafana/agent/converter/internal/common" | ||
) | ||
|
||
func (s *ScrapeConfigBuilder) AppendJournalConfig() { | ||
jc := s.cfg.JournalConfig | ||
if jc == nil { | ||
return | ||
} | ||
maxAge, err := time.ParseDuration(jc.MaxAge) | ||
if err != nil { | ||
s.diags.Add( | ||
diag.SeverityLevelError, | ||
fmt.Sprintf("failed to parse max_age duration for journal config: %s, will use default", err), | ||
) | ||
maxAge = time.Hour * 7 // use default value | ||
} | ||
args := journal.Arguments{ | ||
FormatAsJson: jc.JSON, | ||
MaxAge: maxAge, | ||
Path: jc.Path, | ||
Receivers: s.getOrNewProcessStageReceivers(), | ||
Labels: convertPromLabels(jc.Labels), | ||
RelabelRules: flowrelabel.Rules{}, | ||
} | ||
relabelRulesExpr := s.getOrNewDiscoveryRelabelRules() | ||
hook := func(val interface{}) interface{} { | ||
if _, ok := val.(flowrelabel.Rules); ok { | ||
return common.CustomTokenizer{Expr: relabelRulesExpr} | ||
} | ||
return val | ||
} | ||
s.f.Body().AppendBlock(common.NewBlockWithOverrideFn( | ||
[]string{"loki", "source", "journal"}, | ||
s.cfg.JobName, | ||
args, | ||
hook, | ||
)) | ||
} |
Oops, something went wrong.