mirror of https://github.com/grafana/loki
Add query-frontend option to select request headers in query logs (#11499)
**What this PR does / why we need it**: Adding feature present in mimir, specifically https://github.com/grafana/mimir/pull/5030. Adds a config option to the query-frontend to specify a list of request headers to include in query logs. For example, setting -frontend.log-query-request-headers="X-Grafana-Org-Id" and sending a query with X-Grafana-Org-Id:1 results in query log lines that include header_x_grafana_org_id=1. **Which issue(s) this PR fixes**: Fixes #11422pull/11513/head
parent
b581db0415
commit
0ed536cd7a
@ -0,0 +1,23 @@ |
||||
package transport |
||||
|
||||
import ( |
||||
"net/http" |
||||
"testing" |
||||
|
||||
"github.com/stretchr/testify/require" |
||||
) |
||||
|
||||
func TestFormatRequestHeaders(t *testing.T) { |
||||
h := http.Header{} |
||||
h.Add("X-Header-To-Log", "i should be logged!") |
||||
h.Add("X-Header-To-Not-Log", "i shouldn't be logged!") |
||||
|
||||
fields := formatRequestHeaders(&h, []string{"X-Header-To-Log", "X-Header-Not-Present"}) |
||||
|
||||
expected := []interface{}{ |
||||
"header_x_header_to_log", |
||||
"i should be logged!", |
||||
} |
||||
|
||||
require.Equal(t, expected, fields) |
||||
} |
||||
Loading…
Reference in new issue