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

feat: Add writer addr to loki canary #14291

Closed
wants to merge 3 commits into from
Closed
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
42 changes: 30 additions & 12 deletions cmd/loki-canary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type canary struct {
}

func main() {

lName := flag.String("labelname", "name", "The label name for this instance of loki-canary to use in the log selector")
lVal := flag.String("labelvalue", "loki-canary", "The unique label value for this instance of loki-canary to use in the log selector")
sName := flag.String("streamname", "stream", "The stream name for this instance of loki-canary to use in the log selector")
sValue := flag.String("streamvalue", "stdout", "The unique stream value for this instance of loki-canary to use in the log selector")
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")
addr := flag.String("addr", "", "The read target of Loki server URL:Port, e.g. loki:3100")
writeAddr := flag.String("write-addr", "", "The write target of Loki server URL:Port, e.g. loki:3100, if not set it will use the same value as addr")
push := flag.Bool("push", false, "Push the logs directly to given Loki address")
useTLS := flag.Bool("tls", false, "Does the loki connection use TLS?")
certFile := flag.String("cert-file", "", "Client PEM encoded X.509 certificate for optional use with TLS connection to Loki")
Expand Down Expand Up @@ -98,14 +98,7 @@ func main() {
os.Exit(0)
}

if *addr == "" {
*addr = os.Getenv("LOKI_ADDRESS")
}

if *addr == "" {
_, _ = fmt.Fprintf(os.Stderr, "Must specify a Loki address with -addr or set the environment variable LOKI_ADDRESS\n")
os.Exit(1)
}
rAddr, wAddr := getLokiAddr(*addr, *writeAddr)

if *outOfOrderPercentage < 0 || *outOfOrderPercentage > 100 {
_, _ = fmt.Fprintf(os.Stderr, "Out of order percentage must be between 0 and 100\n")
Expand Down Expand Up @@ -163,7 +156,7 @@ func main() {
MaxRetries: *writeMaxRetries,
}
push, err := writer.NewPush(
*addr,
wAddr,
*tenantID,
*writeTimeout,
config.DefaultHTTPClientConfig,
Expand All @@ -188,7 +181,7 @@ func main() {

c.writer = writer.NewWriter(entryWriter, sentChan, *interval, *outOfOrderMin, *outOfOrderMax, *outOfOrderPercentage, *size, logger)
var err error
c.reader, err = reader.NewReader(os.Stderr, receivedChan, *useTLS, tlsConfig, *caFile, *certFile, *keyFile, *addr, *user, *pass, *tenantID, *queryTimeout, *lName, *lVal, *sName, *sValue, *interval, *queryAppend)
c.reader, err = reader.NewReader(os.Stderr, receivedChan, *useTLS, tlsConfig, *caFile, *certFile, *keyFile, rAddr, *user, *pass, *tenantID, *queryTimeout, *lName, *lVal, *sName, *sValue, *interval, *queryAppend)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Unable to create reader for Loki querier, check config: %s", err)
os.Exit(1)
Expand Down Expand Up @@ -240,3 +233,28 @@ func (c *canary) stop() {
c.reader = nil
c.comparator = nil
}

func getLokiAddr(readAddrInput, writeAddrInput string) (string, string) {
var readAddr, writeAddr string

if readAddrInput == "" {
readAddr = os.Getenv("LOKI_ADDRESS")
if readAddr == "" {
_, _ = fmt.Fprintf(os.Stderr, "Must specify a Loki address with -addr or set the environment variable LOKI_ADDRESS\n")
os.Exit(1)
}
} else {
readAddr = readAddrInput
}

if writeAddrInput == "" {
writeAddr = os.Getenv("LOKI_WRITE_ADDRESS")
if writeAddr == "" {
writeAddr = readAddr
}
} else {
writeAddr = writeAddrInput
}

return readAddr, writeAddr
}
12 changes: 7 additions & 5 deletions docs/sources/operations/loki-canary/_index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: Loki Canary
menuTitle:
menuTitle:
description: Describes how to use Loki Canary to audit the log-capturing performance of a Grafana Loki cluster to ensure Loki is ingesting logs without data loss.
weight:
weight:
---
# Loki Canary

Loki Canary is a standalone app that audits the log-capturing performance of a Grafana Loki cluster.
Loki Canary is a standalone app that audits the log-capturing performance of a Grafana Loki cluster.
This component emits and periodically queries for logs, making sure that Loki is ingesting logs without any data loss.
When something is wrong with Loki, the Canary often provides the first indication.
When something is wrong with Loki, the Canary often provides the first indication.

Loki Canary generates artificial log lines.
These log lines are sent to the Loki cluster.
Expand Down Expand Up @@ -311,7 +311,7 @@ All options:

```
-addr string
The Loki server URL:Port, e.g. loki:3100. Loki address can also be set using the environment variable LOKI_ADDRESS.
The read target of Loki server URL:Port, e.g. loki:3100. Loki address can also be set using the environment variable LOKI_ADDRESS.
-buckets int
Number of buckets in the response_latency histogram (default 10)
-ca-file string
Expand Down Expand Up @@ -374,6 +374,8 @@ All options:
Print this builds version information
-wait duration
Duration to wait for log entries on websocket before querying loki for them (default 1m0s)
-write-addr string
The write target of Loki server URL:Port, e.g. loki-writer:3100. Loki write address can also be set using the environment variable LOKI_WRITE_ADDRESS. If not set, the read address will be used. This is useful when using push mode with distributed Loki setup.
-write-max-backoff duration
Maximum backoff time between retries (default 5m0s)
-write-max-retries int
Expand Down
Loading