Skip to content

Commit 8a6d80d

Browse files
authored
docs: Query History export (#9362)
* docs: Query History export * Last touch
1 parent 1d15182 commit 8a6d80d

File tree

7 files changed

+291
-15
lines changed

7 files changed

+291
-15
lines changed

docs/pages/guides/recipes.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ These recipes will show you the best practices of using Cube.
7777

7878
- [Building UI with drilldowns](/guides/recipes/data-exploration/drilldowns)
7979
- [Retrieving numeric values on the front-end](/guides/recipes/data-exploration/cast-numerics)
80+
- [Analyzing data from Query History export](/guides/recipes/data-exploration/query-history-export)
8081

8182
### Upgrading Cube
8283

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
"drilldowns": "Building UI with drilldowns",
3-
"cast-numerics": "Retrieving numeric values on the front-end"
3+
"cast-numerics": "Retrieving numeric values on the front-end",
4+
"query-history-export": "Analyzing data from Query History export"
45
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Analyzing data from Query History export
2+
3+
You can use [Query History export][ref-query-history-export] to bring [Query
4+
History][ref-query-history] data to an external monitoring solution for further
5+
analysis.
6+
7+
In this recipe, we will show you how to export Query History data to Amazon S3, and then
8+
analyze it using Cube by reading the data from S3 using DuckDB.
9+
10+
## Configuration
11+
12+
[Vector configuration][ref-vector-configuration] for exporting Query History to Amazon S3
13+
and also outputting it to the console of the Vector agent in your Cube Cloud deployment.
14+
15+
In the example below, we are using the `aws_s3` sink to export the `cube-query-history-export-demo`
16+
bucket in Amazon S3, but you can use any other storage solution that Vector supports.
17+
18+
```toml
19+
[sinks.aws_s3]
20+
type = "aws_s3"
21+
inputs = [
22+
"query-history"
23+
]
24+
bucket = "cube-query-history-export-demo"
25+
region = "us-east-2"
26+
compression = "gzip"
27+
28+
[sinks.aws_s3.auth]
29+
access_key_id = "$CUBE_CLOUD_MONITORING_AWS_ACCESS_KEY_ID"
30+
secret_access_key = "$CUBE_CLOUD_MONITORING_AWS_SECRET_ACCESS_KEY"
31+
32+
[sinks.aws_s3.encoding]
33+
codec = "json"
34+
35+
[sinks.aws_s3.healthcheck]
36+
enabled = false
37+
38+
39+
[sinks.my_console]
40+
type = "console"
41+
inputs = [
42+
"query-history"
43+
]
44+
target = "stdout"
45+
encoding = { codec = "json" }
46+
```
47+
48+
You'd also need to set the following environment variables in the <Btn>Settings → Environment
49+
variables</Btn> page of your Cube Cloud deployment:
50+
51+
```bash
52+
CUBE_CLOUD_MONITORING_AWS_ACCESS_KEY_ID=your-access-key-id
53+
CUBE_CLOUD_MONITORING_AWS_SECRET_ACCESS_KEY=your-secret-access-key
54+
55+
CUBEJS_DB_DUCKDB_S3_ACCESS_KEY_ID=your-access-key-id
56+
CUBEJS_DB_DUCKDB_S3_SECRET_ACCESS_KEY=your-secret-access-key
57+
CUBEJS_DB_DUCKDB_S3_REGION=us-east-2
58+
```
59+
60+
## Data modeling
61+
62+
Example data model for analyzing data from Query History export that is brought to a
63+
bucket in Amazon S3. The data is accessed directly from S3 using DuckDB.
64+
65+
With this data model, you can run queries that aggregate data by dimensions such as
66+
`status`, `environment_name`, `api_type`, etc. and also calculate metrics like
67+
`count`, `total_duration`, or `avg_duration`:
68+
69+
```yaml
70+
cubes:
71+
- name: requests
72+
sql: >
73+
SELECT
74+
*,
75+
api_response_duration_ms / 1000 AS api_response_duration,
76+
EPOCH_MS(start_time_unix_ms) AS start_time,
77+
EPOCH_MS(end_time_unix_ms) AS end_time
78+
FROM read_json_auto('s3://cube-query-history-export-demo/**/*.log.gz')
79+
80+
dimensions:
81+
- name: trace_id
82+
sql: trace_id
83+
type: string
84+
primary_key: true
85+
86+
- name: deployment_id
87+
sql: deployment_id
88+
type: number
89+
90+
- name: environment_name
91+
sql: environment_name
92+
type: string
93+
94+
- name: api_type
95+
sql: api_type
96+
type: string
97+
98+
- name: api_query
99+
sql: api_query
100+
type: string
101+
102+
- name: security_context
103+
sql: security_context
104+
type: string
105+
106+
- name: cache_type
107+
sql: cache_type
108+
type: string
109+
110+
- name: start_time
111+
sql: start_time
112+
type: time
113+
114+
- name: end_time
115+
sql: end_time
116+
type: time
117+
118+
- name: duration
119+
sql: api_response_duration
120+
type: number
121+
122+
- name: status
123+
sql: status
124+
type: string
125+
126+
- name: error_message
127+
sql: error_message
128+
type: string
129+
130+
- name: user_name
131+
sql: "SUBSTRING(security_context::JSON ->> 'user', 3, LENGTH(security_context::JSON ->> 'user') - 4)"
132+
type: string
133+
134+
segments:
135+
- name: production_environment
136+
sql: "{environment_name} IS NULL"
137+
138+
- name: errors
139+
sql: "{status} <> 'success'"
140+
141+
measures:
142+
- name: count
143+
type: count
144+
145+
- name: count_non_production
146+
description: >
147+
Counts all non-production environments.
148+
See for details: https://cube.dev/docs/product/workspace/environments
149+
type: count
150+
filters:
151+
- sql: "{environment_name} IS NOT NULL"
152+
153+
- name: total_duration
154+
type: sum
155+
sql: "{duration}"
156+
157+
- name: avg_duration
158+
type: number
159+
sql: "{total_duration} / {count}"
160+
161+
- name: median_duration
162+
type: number
163+
sql: "MEDIAN({duration})"
164+
165+
- name: min_duration
166+
type: min
167+
sql: "{duration}"
168+
169+
- name: max_duration
170+
type: max
171+
sql: "{duration}"
172+
173+
pre_aggregations:
174+
- name: count_and_durations_by_status_and_start_date
175+
measures:
176+
- count
177+
- min_duration
178+
- max_duration
179+
- total_duration
180+
dimensions:
181+
- status
182+
time_dimension: start_time
183+
granularity: hour
184+
refresh_key:
185+
sql: SELECT MAX(end_time) FROM {requests.sql()}
186+
every: 10 minutes
187+
188+
```
189+
190+
## Result
191+
192+
Example query in Playground:
193+
194+
<Screenshot src="https://ucarecdn.com/327373f0-217b-4a91-8ac7-fd2d97c79513/" />
195+
196+
197+
[ref-query-history-export]: /product/workspace/monitoring#query-history-export
198+
[ref-query-history]: /product/workspace/query-history
199+
[ref-vector-configuration]: /product/workspace/monitoring#configuration

docs/pages/product/caching/using-pre-aggregations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ simple queries using a familiar SQL syntax. You can connect using the MySQL CLI
614614
client, for example:
615615

616616
```bash
617-
mysql -h <CUBESTORE_IP> --user=cubestore -pcubestore
617+
mysql -h <CUBESTORE_IP> --user=cubestore -pcubestore --protocol=TCP
618618
```
619619

620620
<WarningBox>

docs/pages/product/deployment/cloud/pricing.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ You can upgrade to a chosen tier in the
191191

192192
[Monitoring Integrations][ref-monitoring-integrations] feature has the following tiers:
193193

194-
| Tier | CCUs per hour | Exported data |
195-
| ---- | :-----------: | -------------- |
196-
| XS | 1 | Up to 10 GB/mo |
197-
| S | 2 | Up to 25 GB/mo |
198-
| M | 4 | Up to 50 GB/mo |
194+
| Tier | CCUs per hour | Exported data | Dependent features |
195+
| ---- | :-----------: | -------------- | --- |
196+
| XS | 1 | Up to 10 GB/mo ||
197+
| S | 2 | Up to 25 GB/mo ||
198+
| M | 4 | Up to 50 GB/mo | [Query History export][ref-query-history-export] |
199199

200200
You can [upgrade][ref-monitoring-integrations-config] to a chosen tier in the
201201
<Btn>Settings</Btn> of your deployment.
@@ -366,4 +366,5 @@ product tier level. Payments are non-refundable.
366366
[ref-customer-managed-keys]: /product/workspace/encryption-keys
367367
[ref-semantic-catalog]: /product/workspace/semantic-catalog
368368
[ref-ai-api]: /product/apis-integrations/ai-api
369-
[ref-ai-assistant]: /product/workspace/ai-assistant
369+
[ref-ai-assistant]: /product/workspace/ai-assistant
370+
[ref-query-history-export]: /product/workspace/monitoring#query-history-export

docs/pages/product/workspace/monitoring.mdx

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Cube Cloud deployment should export their logs:
107107
| `refresh-scheduler` | Logs of the refresh worker |
108108
| `warmup-job` | Logs of the [pre-aggregation warm-up][ref-preagg-warmup] |
109109
| `cubestore` | Logs of Cube Store |
110+
| `query-history` | [Query History export](#query-history-export) |
110111

111112
Example configuration for exporting logs to
112113
[Datadog][vector-docs-sinks-datadog]:
@@ -274,6 +275,61 @@ You can also customize the user name and password for `prometheus_exporter` by
274275
setting `CUBE_CLOUD_MONITORING_METRICS_USER` and
275276
`CUBE_CLOUD_MONITORING_METRICS_PASSWORD` environment variables, respectively.
276277

278+
## Query History export
279+
280+
With Query History export, you can bring [Query History][ref-query-history] data to an
281+
external monitoring solution for further analysis, for example:
282+
* Detect queries that do not hit pre-aggregations.
283+
* Set up alerts for queries that exceed a certain duration.
284+
* Attribute usage to specific users and implement chargebacks.
285+
286+
<SuccessBox>
287+
288+
Query History export requires the [M tier](/product/deployment/cloud/pricing#monitoring-integrations-tiers)
289+
of Monitoring Integrations.
290+
291+
</SuccessBox>
292+
293+
To configure Query History export, add the `query-history` input to the `inputs`
294+
option of the sink configuration. Example configuration for exporting Query History data
295+
to the standard output of the Vector agent:
296+
297+
```toml
298+
[sinks.my_console]
299+
type = "console"
300+
inputs = [
301+
"query-history"
302+
]
303+
target = "stdout"
304+
encoding = { codec = "json" }
305+
```
306+
307+
Exported data includes the following fields:
308+
309+
| Field | Description |
310+
| --- | --- |
311+
| `trace_id` | Unique identifier of the API request. |
312+
| `account_name` | Name of the Cube Cloud account. |
313+
| `deployment_id` | Identifier of the [deployment][ref-deployments]. |
314+
| `environment_name` | Name of the [environment][ref-environments], `NULL` for production. |
315+
| `api_type` | Type of [data API][ref-apis] used (`rest`, `sql`, etc.), `NULL` for errors. |
316+
| `api_query` | Query executed by the API, represented as string. |
317+
| `security_context` | [Security context][ref-security-context] of the request, represented as a string. |
318+
| `status` | Status of the request: `success` or `error`. |
319+
| `error_message` | Error message, if any. |
320+
| `start_time_unix_ms` | Start time of the execution, Unix timestamp in milliseconds. |
321+
| `end_time_unix_ms` | End time of the execution, Unix timestamp in milliseconds. |
322+
| `api_response_duration_ms` | Duration of the execution in milliseconds. |
323+
| `cache_type` | [Cache type][ref-cache-type]: `no_cache`, `pre_aggregations_in_cube_store`, etc. |
324+
325+
<ReferenceBox>
326+
327+
See [this recipe][ref-query-history-export-recipe] for an example of analyzing data from
328+
Query History export.
329+
330+
</ReferenceBox>
331+
332+
277333
[ref-autosuspend]: /product/deployment/cloud/auto-suspension#effects-on-experience
278334
[self-sinks-for-metrics]: #configuration-sinks-for-metrics
279335
[ref-dedicated-infra]: /product/deployment/cloud/infrastructure#dedicated-infrastructure
@@ -302,4 +358,11 @@ setting `CUBE_CLOUD_MONITORING_METRICS_USER` and
302358
[mimir]: https://grafana.com/oss/mimir/
303359
[grafana-cloud]: https://grafana.com/products/cloud/
304360
[ref-prod-env]: /product/workspace/environments#production-environment
305-
[ref-preagg-warmup]: /product/deployment/cloud/warm-up#pre-aggregation-warm-up
361+
[ref-preagg-warmup]: /product/deployment/cloud/warm-up#pre-aggregation-warm-up
362+
[ref-query-history]: /product/workspace/query-history
363+
[ref-deployments]: /product/deployment/cloud/deployments
364+
[ref-environments]: /product/workspace/environments
365+
[ref-apis]: /product/apis-integrations
366+
[ref-security-context]: /product/auth/context
367+
[ref-cache-type]: /product/caching#cache-type
368+
[ref-query-history-export-recipe]: /guides/recipes/data-exploration/query-history-export

docs/pages/product/workspace/query-history.mdx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ redirect_from:
55

66
# Query History
77

8-
The Query History screen in Cube Cloud is a one-stop shop for all performance
9-
and diagnostic information about queries issued for a deployment. It is kept
10-
up-to-date in real time and provides a quick way to check whether queries are
11-
being accelerated with [pre-aggregations][ref-caching-gs-preaggs], how long they
12-
took to execute, and if they failed.
8+
The Query History feature in Cube Cloud is a one-stop shop for all performance
9+
and diagnostic information about queries issued for a deployment.
10+
11+
It provides a real-time and historic view of requests to [data APIs][ref-apis] of your
12+
Cube Cloud deployment, so you can check whether queries were accelerated with
13+
[pre-aggregations][ref-caching-gs-preaggs], how long they took to execute, and if they
14+
failed.
1315

1416
<SuccessBox>
1517

@@ -19,6 +21,13 @@ You can also choose a [Query History tier](/product/deployment/cloud/pricing#que
1921

2022
</SuccessBox>
2123

24+
You can set the [time range](#setting-the-time-range), [explore queries](#exploring-queries)
25+
and filter them, drill down on specific queries to [see more details](#inspecting-api-queries).
26+
27+
You can also use [Query History export][ref-query-history-export] to bring Query History
28+
data to an external monitoring solution for further analysis.
29+
30+
<br/>
2231
<video width="100%" controls>
2332
<source
2433
src="https://ucarecdn.com/ceba0bdc-298b-44e6-8491-2b0e39985465/video.mp4"
@@ -220,4 +229,6 @@ while the query is in the query execution queue:
220229
[ref-query-format]: /product/apis-integrations/rest-api/query-format
221230
[ref-cache-types]: /product/caching#cache-type
222231
[ref-security-context]: /product/auth/context
223-
[ref-multitenancy]: /product/configuration/advanced/multitenancy
232+
[ref-multitenancy]: /product/configuration/advanced/multitenancy
233+
[ref-apis]: /product/apis-integrations
234+
[ref-query-history-export]: /product/workspace/monitoring#query-history-export

0 commit comments

Comments
 (0)