Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add X-Grafana-User header in case the actor is specified in config #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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