Skip to content

Commit

Permalink
Add X-Grafana-User header in case the actor is specified in config
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Aug 29, 2023
1 parent a15daa8 commit 3d78fb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Config struct {
UserAgent string
Timeout time.Duration
TenantID string
Actor string
Cardinalities map[string]int
Labels LabelPool
ProtobufRatio float64
Expand Down Expand Up @@ -204,6 +205,9 @@ func (c *Client) sendQuery(q *Query) (httpext.Response, error) {

r.Header.Set("User-Agent", c.cfg.UserAgent)
r.Header.Set("Accept", ContentTypeJSON)
if c.cfg.Actor != "" {
r.Header.Set("X-Grafana-User", c.cfg.Actor)
}
if c.cfg.TenantID != "" {
r.Header.Set("X-Scope-OrgID", c.cfg.TenantID)
} else {
Expand Down
7 changes: 6 additions & 1 deletion loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func (r *Loki) config(c goja.ConstructorCall) *goja.Object {
}

r.logger.Debug(fmt.Sprintf(
"url=%s timeout=%s protobufRatio=%f cardinalities=%v randSeed=%d",
"url=%s timeout=%s protobufRatio=%f cardinalities=%v randSeed=%d, userAgent=%s, timeout=%s, tenant=%s, actor=%s",
&config.URL, config.Timeout, config.ProtobufRatio, config.Cardinalities, config.RandSeed,
config.UserAgent, config.Timeout, config.TenantID, config.Actor,
))

if config.TenantID == "" {
Expand Down Expand Up @@ -225,6 +226,10 @@ func (r *Loki) parseConfigObject(c *goja.Object, config *Config) error {
config.TenantID = v.String()
}

if v := c.Get("actor"); !isNully(v) {
config.Actor = v.String()
}

if v := c.Get("cardinalities"); !isNully(v) {
if err := rt.ExportTo(v, &config.Cardinalities); err != nil {
return fmt.Errorf("cardinatities should be a map of string to integers: %w", err)
Expand Down

0 comments on commit 3d78fb5

Please sign in to comment.