feat(query): add source to query request via user agent header
parent
ec35815553
commit
6fe69549d4
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue