From ad5d8097da60081cff8d0aa3c401ddfaa69960be Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 9 Oct 2024 12:56:49 +0200 Subject: [PATCH] app/vlogscli: add -accountID and -projectID command-line flags for querying the given tenants --- app/vlogscli/main.go | 4 ++++ docs/VictoriaLogs/CHANGELOG.md | 1 + docs/VictoriaLogs/querying/vlogscli.md | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/app/vlogscli/main.go b/app/vlogscli/main.go index ef4a3145a..36acb1720 100644 --- a/app/vlogscli/main.go +++ b/app/vlogscli/main.go @@ -32,6 +32,8 @@ var ( "The url is automatically detected from -datasource.url by replacing /query with /tail at the end if -tail.url is empty") historyFile = flag.String("historyFile", "vlogscli-history", "Path to file with command history") header = flagutil.NewArrayString("header", "Optional header to pass in request -datasource.url in the form 'HeaderName: value'") + accountID = flag.Int("accountID", 0, "Account ID to query; see https://docs.victoriametrics.com/victorialogs/#multitenancy") + projectID = flag.Int("projectID", 0, "Project ID to query; see https://docs.victoriametrics.com/victorialogs/#multitenancy") ) const ( @@ -346,6 +348,8 @@ func getQueryResponse(ctx context.Context, output io.Writer, qStr string, output for _, h := range headers { req.Header.Set(h.Name, h.Value) } + req.Header.Set("AccountID", strconv.Itoa(*accountID)) + req.Header.Set("ProjectID", strconv.Itoa(*projectID)) // Execute HTTP request at qURL startTime := time.Now() diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index d09d15be3..758fb49f4 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -19,6 +19,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta * FEATURE: [vlogscli](https://docs.victoriametrics.com/victorialogs/querying/vlogscli/): add ability to live tail query results - see [these docs](https://docs.victoriametrics.com/victorialogs/querying/vlogscli/#live-tailing). * FEATURE: [vlogscli](https://docs.victoriametrics.com/victorialogs/querying/vlogscli/): add compact output mode for query results. It can be enabled by typing `\c` and then pressing `enter`. See [these docs](https://docs.victoriametrics.com/victorialogs/querying/vlogscli/#output-modes). +* FEATURE: [vlogscli](https://docs.victoriametrics.com/victorialogs/querying/vlogscli/): add `-accountID` and `-projectID` command-line flags for setting `AccountID` and `ProjectID` values when querying the specific [tenants](https://docs.victoriametrics.com/victorialogs/#multitenancy). Released at 2024-10-08 diff --git a/docs/VictoriaLogs/querying/vlogscli.md b/docs/VictoriaLogs/querying/vlogscli.md index a2186c546..36c36fc59 100644 --- a/docs/VictoriaLogs/querying/vlogscli.md +++ b/docs/VictoriaLogs/querying/vlogscli.md @@ -26,6 +26,8 @@ tar xzf vlogscli-linux-amd64-v0.34.0-victorialogs.tar.gz docker run --rm -it docker.io/victoriametrics/vlogscli:v0.34.0-victorialogs ``` +## Configuration + By default `vlogscli` sends queries to [`http://localhost:8429/select/logsql/query`](https://docs.victoriametrics.com/victorialogs/querying/#querying-logs). The url to query can be changed via `-datasource.url` command-line flag. For example, the following command instructs `vlogsql` sending queries to `https://victoria-logs.some-domain.com/select/logsql/query`: @@ -42,6 +44,14 @@ which queries `(AccountID=123, ProjectID=456)` [tenant](https://docs.victoriamet ./vlogsql -header='AccountID: 123' -header='ProjectID: 456' ``` +`AccountID` and `ProjectID` values can be also set via `-accountID` and `-projectID` command-line flags: + +```sh +./vlogsql -accountID=123 -projectID=456 +``` + +## Querying + After the start `vlogsql` provides a prompt for writing [LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/) queries. The query can be multi-line. It is sent to VictoriaLogs as soon as it contains `;` at the end or if a blank line follows the query. For example: