app/vlogscli: add -accountID and -projectID command-line flags for querying the given tenants

This commit is contained in:
Aliaksandr Valialkin 2024-10-09 12:56:49 +02:00
parent e31625e0b2
commit ad5d8097da
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 15 additions and 0 deletions

View file

@ -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()

View file

@ -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

View file

@ -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: