diff --git a/CHANGELOG.md b/CHANGELOG.md index 18af038aa5..6fcef89234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ 1. [16014](https://github.com/influxdata/influxdb/pull/16014): While creating check, also display notification rules that would match check based on tag rules 1. [16389](https://github.com/influxdata/influxdb/pull/16389): Increase default bucket retention period to 30 days 1. [16418](https://github.com/influxdata/influxdb/pull/16418): Add Developer Documentation +1. [16260](https://github.com/influxdata/influxdb/pull/16260): Capture User-Agent header as query source for logging purposes ### Bug Fixes diff --git a/http/query_handler.go b/http/query_handler.go index a6f0341008..d6ac096bbf 100644 --- a/http/query_handler.go +++ b/http/query_handler.go @@ -155,6 +155,7 @@ func (h *FluxHandler) handleQuery(w http.ResponseWriter, r *http.Request) { h.HandleHTTPError(ctx, err, w) return } + req.Request.Source = r.Header.Get("User-Agent") orgID = req.Request.OrganizationID requestBytes = n @@ -349,6 +350,7 @@ var _ query.ProxyQueryService = (*FluxService)(nil) type FluxService struct { Addr string Token string + Name string InsecureSkipVerify bool } @@ -383,6 +385,11 @@ func (s *FluxService) Query(ctx context.Context, w io.Writer, r *query.ProxyRequ hreq.Header.Set("Content-Type", "application/json") hreq.Header.Set("Accept", "text/csv") + if r.Request.Source != "" { + hreq.Header.Add("User-Agent", r.Request.Source) + } else if s.Name != "" { + hreq.Header.Add("User-Agent", s.Name) + } hreq = hreq.WithContext(ctx) hc := NewClient(u.Scheme, s.InsecureSkipVerify) @@ -412,6 +419,7 @@ var _ query.QueryService = (*FluxQueryService)(nil) type FluxQueryService struct { Addr string Token string + Name string InsecureSkipVerify bool } @@ -450,6 +458,11 @@ func (s *FluxQueryService) Query(ctx context.Context, r *query.Request) (flux.Re hreq.Header.Set("Content-Type", "application/json") hreq.Header.Set("Accept", "text/csv") + if r.Source != "" { + hreq.Header.Add("User-Agent", r.Source) + } else if s.Name != "" { + hreq.Header.Add("User-Agent", s.Name) + } hreq = hreq.WithContext(ctx) hc := NewClient(u.Scheme, s.InsecureSkipVerify) diff --git a/query/request.go b/query/request.go index cf6a48084f..ab6b50c84b 100644 --- a/query/request.go +++ b/query/request.go @@ -20,6 +20,9 @@ type Request struct { // Compiler converts the query to a specification to run against the data. Compiler flux.Compiler `json:"compiler"` + // Source represents the ultimate source of the request. + Source string `json:"source"` + // compilerMappings maps compiler types to creation methods compilerMappings flux.CompilerMappings } diff --git a/query/service_test.go b/query/service_test.go index 65022269fc..e740c2c0ed 100644 --- a/query/service_test.go +++ b/query/service_test.go @@ -57,12 +57,13 @@ func TestRequest_JSON(t *testing.T) { }{ { name: "simple", - data: `{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"compiler_type":"compilerA"}`, + data: `{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"source":"source","compiler_type":"compilerA"}`, want: query.Request{ OrganizationID: platformtesting.MustIDBase16("aaaaaaaaaaaaaaaa"), Compiler: &compilerA{ A: "my custom compiler", }, + Source: "source", }, }, } @@ -94,13 +95,14 @@ func TestProxyRequest_JSON(t *testing.T) { }{ { name: "simple", - data: `{"request":{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"compiler_type":"compilerA"},"dialect":{"b":42},"dialect_type":"dialectB"}`, + data: `{"request":{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"source":"source","compiler_type":"compilerA"},"dialect":{"b":42},"dialect_type":"dialectB"}`, want: query.ProxyRequest{ Request: query.Request{ OrganizationID: platformtesting.MustIDBase16("aaaaaaaaaaaaaaaa"), Compiler: &compilerA{ A: "my custom compiler", }, + Source: "source", }, Dialect: &dialectB{ B: 42,