8000 support match config by KayzzzZ · Pull Request #2170 · alibaba/loongcollector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

support match config #2170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions test/engine/setup/subscriber/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ flushers:
Project: {{.Project}}
Logstore: {{.Logstore}}`

const SLSFlusherConfigWithMatchTemplate = `
flushers:
- Type: flusher_sls
Aliuid: "{{.Aliuid}}"
TelemetryType: "{{.TelemetryType}}"
Region: {{.Region}}
Endpoint: {{.Endpoint}}
Project: {{.Project}}
Logstore: "{{.Logstore}}"
Match:
Type: {{.MatchType}}
Key: {{.MatchKey}}
Value: {{.MatchValue}}
`

type SLSSubscriber struct {
client *sls.Client
TelemetryType string
Expand All @@ -36,6 +51,9 @@ type SLSSubscriber struct {
QueryEndpoint string
Project string
Logstore string
MatchType string
MatchKey string
MatchValue string
}

func (s *SLSSubscriber) Name() string {
Expand Down Expand Up @@ -70,6 +88,9 @@ func (s *SLSSubscriber) GetData(query string, startTime int32) ([]*protocol.LogG

func (s *SLSSubscriber) FlusherConfig() string {
tpl := template.Must(template.New("slsFlusherConfig").Parse(SLSFlusherConfigTemplate))
if s.MatchType != "" && s.MatchKey != "" && s.MatchValue != "" {
tpl = template.Must(template.New("slsFlusherConfig").Parse(SLSFlusherConfigWithMatchTemplate))
}
var builder strings.Builder
_ = tpl.Execute(&builder, map[string]interface{}{
"Aliuid": s.Aliuid,
Expand All @@ -78,6 +99,9 @@ func (s *SLSSubscriber) FlusherConfig() string {
"Project": s.Project,
"Logstore": s.Logstore,
"TelemetryType": s.TelemetryType,
"MatchType": s.MatchType,
"MatchKey": s.MatchKey,
"MatchValue": s.MatchValue,
})
config := builder.String()
return config
Expand Down Expand Up @@ -210,6 +234,8 @@ func (s *SLSSubscriber) getCompleteQuery(query string) string {
switch s.TelemetryType {
case "logs":
return query
case "arms_metrics":
fallthrough
case "metrics":
return fmt.Sprintf("* | select promql_query_range('%s') from metrics limit 10000", query)
case "traces":
Expand Down Expand Up @@ -288,6 +314,15 @@ func init() {
} else {
l.Logstore = config.TestConfig.GetLogstore(l.TelemetryType)
}
if v, ok := spec["match_type"]; ok {
l.MatchType = v.(string)
}
if v, ok := spec["match_key"]; ok {
l.MatchKey = v.(string)
}
if v, ok := spec["match_value"]; ok {
l.MatchValue = v.(string)
}
l.client = createSLSClient(config.TestConfig.AccessKeyID, config.TestConfig.AccessKeySecret, l.QueryEndpoint)
return l, nil
})
Expand Down
Loading
0