diff --git a/config/base/env/config b/config/base/env/config index 91ec5e64e..bebca8364 100644 --- a/config/base/env/config +++ b/config/base/env/config @@ -45,3 +45,4 @@ LOGGING_PLUGIN_CA_CERT= LOGGING_PLUGIN_QUERY_LIMIT=1700 LOGGING_PLUGIN_TLS_VERIFICATION_DISABLE= LOGGING_PLUGIN_FORWARDER_DELAY_DURATION=10 +LOGGING_PLUGIN_QUERY_PARAMS='direction=forward' \ No newline at end of file diff --git a/docs/logging-support.md b/docs/logging-support.md index cd79641ef..710e78eaf 100644 --- a/docs/logging-support.md +++ b/docs/logging-support.md @@ -29,3 +29,4 @@ These are the common configuration options for all third party logging APIs. - `LOGGING_PLUGIN_TLS_VERIFICATION_DISABLE`: Set to `true` to disable TLS verification for the third party logging API. (optional) - `LOGGING_PLUGIN_FORWARDER_DELAY_DURATION`: This is the max duration in minutes taken by third party logging system to forward and store the logs after completion of taskrun and pipelinerun. This is used to search between start time of runs and completion plus buffer duration. - `LOGGING_PLUGIN_QUERY_LIMIT`: Sets the query limit for Third Party Logging API if logging backend has a limit on number of log lines returned. +- `LOGGING_PLUGIN_QUERY_PARAMS`: Sets the query params for Third Party Logging API, these can be direction/sort order.Specify them in this format: "foo=bar&direction=backward" diff --git a/pkg/api/server/config/config.go b/pkg/api/server/config/config.go index 652eebf88..c9bc4bf32 100644 --- a/pkg/api/server/config/config.go +++ b/pkg/api/server/config/config.go @@ -61,6 +61,7 @@ type Config struct { LOGGING_PLUGIN_QUERY_LIMIT uint `mapstructure:"LOGGING_PLUGIN_QUERY_LIMIT"` LOGGING_PLUGIN_TLS_VERIFICATION_DISABLE bool `mapstructure:"LOGGING_PLUGIN_TLS_VERIFICATION_DISABLE"` LOGGING_PLUGIN_FORWARDER_DELAY_DURATION uint `mapstructure:"LOGGING_PLUGIN_FORWARDER_DELAY_DURATION"` + LOGGING_PLUGIN_QUERY_PARAMS string `mapstructure:"LOGGING_PLUGIN_QUERY_PARAMS"` } func Get() *Config { diff --git a/pkg/api/server/v1alpha2/plugin_logs.go b/pkg/api/server/v1alpha2/plugin_logs.go index bf4f0fee4..c2fc1cac3 100644 --- a/pkg/api/server/v1alpha2/plugin_logs.go +++ b/pkg/api/server/v1alpha2/plugin_logs.go @@ -142,6 +142,9 @@ func (s *LogPluginServer) getLokiLogs(writer *logs.BufferedLog, parent string, r } parameters := url.Values{} + for k, v := range s.queryParams { + parameters.Add(k, v) + } parameters.Add("query", `{ `+s.staticLabels+s.config.LOGGING_PLUGIN_NAMESPACE_KEY+`="`+parent+`" }|json uid="`+uidKey+`", message="message" |uid="`+rec.Name+`"| line_format "{{.message}}"`) parameters.Add("end", endTime) parameters.Add("start", startTime) @@ -149,6 +152,7 @@ func (s *LogPluginServer) getLokiLogs(writer *logs.BufferedLog, parent string, r URL.RawQuery = parameters.Encode() s.logger.Debugf("loki request url:%s", URL.String()) + req, err := http.NewRequest("GET", URL.String(), nil) if err != nil { s.logger.Errorf("new request to loki failed, err: %s:", err.Error()) diff --git a/pkg/api/server/v1alpha2/plugin_logs_test.go b/pkg/api/server/v1alpha2/plugin_logs_test.go index 87f77096d..64f53833e 100644 --- a/pkg/api/server/v1alpha2/plugin_logs_test.go +++ b/pkg/api/server/v1alpha2/plugin_logs_test.go @@ -66,6 +66,7 @@ func TestLogPluginServer_GetLog(t *testing.T) { LOGGING_PLUGIN_STATIC_LABELS: "namespace=\"foo\"", LOGGING_PLUGIN_NAMESPACE_KEY: "namespace", LOGGING_PLUGIN_QUERY_LIMIT: 1500, + LOGGING_PLUGIN_QUERY_PARAMS: "direction=forward", }, logger.Get("info"), test.NewDB(t)) if err != nil { t.Fatalf("failed to create server: %v", err) diff --git a/pkg/api/server/v1alpha2/server.go b/pkg/api/server/v1alpha2/server.go index 0239f49ea..ed2a4d05b 100644 --- a/pkg/api/server/v1alpha2/server.go +++ b/pkg/api/server/v1alpha2/server.go @@ -85,6 +85,8 @@ type LogPluginServer struct { queryLimit uint + queryParams map[string]string + // TODO: In future add support for non Oauth support tokenSource oauth2.TokenSource } @@ -212,5 +214,16 @@ func (s *Server) createLogPluginServer() error { s.LogPluginServer.tokenSource = transport.NewCachedFileTokenSource(s.config.LOGGING_PLUGIN_TOKEN_PATH) s.LogPluginServer.queryLimit = s.config.LOGGING_PLUGIN_QUERY_LIMIT + s.LogPluginServer.queryParams = map[string]string{} + if s.config.LOGGING_PLUGIN_QUERY_PARAMS != "" { + for _, v := range strings.Split(s.config.LOGGING_PLUGIN_QUERY_PARAMS, "&") { + queryParam := strings.Split(v, "=") + if len(queryParam) != 2 { + return fmt.Errorf("incorrect format for LOGGING_PLUGIN_QUERY_PARAMS: %s", v) + } + s.LogPluginServer.queryParams[queryParam[0]] = queryParam[1] + } + } + return nil }