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

Fixed reader to support both authentication and tenant-id #5719

Merged
merged 2 commits into from
May 18, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ to include only the most relevant.
* [5543](https://github.com/grafana/loki/pull/5543) **cyriltovena**: update loki go version to 1.17.8
* [5450](https://github.com/grafana/loki/pull/5450) **BenoitKnecht**: pkg/ruler/base: Add external_labels option
* [5484](https://github.com/grafana/loki/pull/5450) **sandeepsukhani**: Add support for per user index query readiness with limits overrides
* [5719](https://github.com/grafana/loki/pull/5719) **kovaxur**: Loki can use both basic-auth and tenant-id
* [5661](https://github.com/grafana/loki/pull/5450) **masslessparticle**: Invalidate caches on deletes
* [5358](https://github.com/grafana/loki/pull/5358) **DylanGuedes**: Add `RingMode` support to `IndexGateway`
* [5435](https://github.com/grafana/loki/pull/5435) **slim-bean**: set match_max_concurrent true by default
Expand Down
6 changes: 3 additions & 3 deletions cmd/loki-canary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func main() {
port := flag.Int("port", 3500, "Port which loki-canary should expose metrics")
addr := flag.String("addr", "", "The Loki server URL:Port, e.g. loki:3100")
tls := flag.Bool("tls", false, "Does the loki connection use TLS?")
user := flag.String("user", "", "Loki username. Must not be set with tenant-id flag.")
pass := flag.String("pass", "", "Loki password. Must not be set with tenant-id flag.")
tenantID := flag.String("tenant-id", "", "Tenant id to be set in X-Scope-OrgID header. Must not be set with user/pass flags.")
user := flag.String("user", "", "Loki username.")
pass := flag.String("pass", "", "Loki password.")
tenantID := flag.String("tenant-id", "", "Tenant ID to be set in X-Scope-OrgID header.")
queryTimeout := flag.Duration("query-timeout", 10*time.Second, "How long to wait for a query response from Loki")

interval := flag.Duration("interval", 1000*time.Millisecond, "Duration between log entries")
Expand Down
2 changes: 2 additions & 0 deletions docs/sources/operations/loki-canary.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ All options:
-streamvalue string
The unique stream value for this instance of Loki Canary to use in the log selector
(default "stdout")
-tenant-id string
Tenant ID to be set in X-Scope-OrgID header.
-tls
Does the Loki connection use TLS?
-user string
Expand Down
13 changes: 8 additions & 5 deletions pkg/canary/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func NewReader(writer io.Writer,
) *Reader {
h := http.Header{}
if user != "" {
h = http.Header{"Authorization": {"Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+pass))}}
} else if tenantID != "" {
h = http.Header{"X-Scope-OrgID": {tenantID}}
h.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(user+":"+pass)))
}
if tenantID != "" {
h.Set("X-Scope-OrgID", tenantID)
}

next := time.Now()
Expand Down Expand Up @@ -182,7 +183,8 @@ func (r *Reader) QueryCountOverTime(queryRange string) (float64, error) {

if r.user != "" {
req.SetBasicAuth(r.user, r.pass)
} else if r.tenantID != "" {
}
if r.tenantID != "" {
req.Header.Set("X-Scope-OrgID", r.tenantID)
}
req.Header.Set("User-Agent", userAgent)
Expand Down Expand Up @@ -272,7 +274,8 @@ func (r *Reader) Query(start time.Time, end time.Time) ([]time.Time, error) {

if r.user != "" {
req.SetBasicAuth(r.user, r.pass)
} else if r.tenantID != "" {
}
if r.tenantID != "" {
req.Header.Set("X-Scope-OrgID", r.tenantID)
}
req.Header.Set("User-Agent", userAgent)
Expand Down