From 602e424abc7eda963d88ce84bb4eabe97607a86b Mon Sep 17 00:00:00 2001 From: "qianlu.kk" Date: Thu, 27 Mar 2025 17:26:32 +0800 Subject: [PATCH] support match config --- test/engine/setup/subscriber/sls.go | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/engine/setup/subscriber/sls.go b/test/engine/setup/subscriber/sls.go index 131bd2281e..a4e7bb0f17 100644 --- a/test/engine/setup/subscriber/sls.go +++ b/test/engine/setup/subscriber/sls.go @@ -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 @@ -36,6 +51,9 @@ type SLSSubscriber struct { QueryEndpoint string Project string Logstore string + MatchType string + MatchKey string + MatchValue string } func (s *SLSSubscriber) Name() string { @@ -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, @@ -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 @@ -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": @@ -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 })