Skip to content

Commit 2674614

Browse files
authored
docs: Updates (#7277)
* Minimal permissions for SLS in Preset * Fix cube_dbt code examples * Add a note on unsafe string escaping * Clarify building custom Docker images * Garbage collection in Cube Store * Fix case dimension
1 parent a0d23cb commit 2674614

File tree

9 files changed

+154
-56
lines changed

9 files changed

+154
-56
lines changed

docs/docs-new/pages/guides/dbt.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ This is particularly useful if you keep your data marts under
176176
from cube_dbt import Dbt
177177

178178
manifest_url = 'https://cube-dbt-integration.s3.amazonaws.com/manifest.json'
179-
dbt = Dbt.from_url(manifest_url).filter(paths=['models/marts/'])
179+
dbt = Dbt.from_url(manifest_url).filter(paths=['marts/'])
180180
```
181181

182182
You can also load only models with certain tags. This is useful if you'd
@@ -211,7 +211,7 @@ from cube import TemplateContext
211211
from cube_dbt import Dbt
212212

213213
manifest_url = 'https://cube-dbt-integration.s3.amazonaws.com/manifest.json'
214-
dbt = Dbt.from_url(manifest_url).filter(paths=['models/marts/'])
214+
dbt = Dbt.from_url(manifest_url).filter(paths=['marts/'])
215215

216216
template = TemplateContext()
217217

docs/docs-new/pages/product/caching/running-in-production.mdx

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,24 @@ using Cube Cloud.
216216

217217
## Storage
218218

219-
<WarningBox>
219+
Cube Store cluster uses both persistent and scratch storage.
220220

221-
Cube Store can only use one type of remote storage at runtime.
222-
223-
</WarningBox>
221+
### Persistent storage
224222

225223
Cube Store makes use of a separate storage layer for storing metadata as well as
226-
for persisting pre-aggregations as Parquet files. Cube Store [can be configured
227-
to use either AWS S3 or Google Cloud Storage][ref-config-env]. If desired, local
228-
path on the server can also be used in case all Cube Store cluster nodes are
224+
for persisting pre-aggregations as Parquet files.
225+
226+
Cube Store [can be configured][ref-config-env] to use either AWS S3 or
227+
Google Cloud Storage (GCS) as persistent storage. If desired, local path on
228+
the server can also be used in case all Cube Store cluster nodes are
229229
co-located on a single machine.
230230

231+
<InfoBox>
232+
233+
Cube Store can only use one type of remote storage at runtime.
234+
235+
</InfoBox>
236+
231237
<WarningBox>
232238

233239
Cube Store requires strong consistency guarantees from underlying distributed
@@ -242,6 +248,7 @@ A simplified example using AWS S3 might look like:
242248

243249
```yaml
244250
version: "2.2"
251+
245252
services:
246253
cubestore_router:
247254
image: cubejs/cubestore:latest
@@ -253,6 +260,7 @@ services:
253260
- CUBESTORE_S3_REGION=<BUCKET_REGION_IN_S3>
254261
- CUBESTORE_AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
255262
- CUBESTORE_AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
263+
256264
cubestore_worker_1:
257265
image: cubejs/cubestore:latest
258266
environment:
@@ -268,12 +276,16 @@ services:
268276
- cubestore_router
269277
```
270278

271-
### Local Storage
279+
Note that you can’t use the same bucket as an export bucket and persistent
280+
storage for Cube Store. It's recommended to use two separate buckets.
281+
282+
### Scratch storage
272283

273-
Separately from remote storage, Cube Store requires local scratch space to warm
274-
up partitions by downloading Parquet files before querying them. By default,
275-
this directory should be mounted to `.cubestore/data` dir inside contained and
276-
can be configured by [CUBESTORE_DATA_DIR][ref-config-env] environment variable.
284+
Separately from persistent storage, Cube Store requires local scratch space
285+
to warm up partitions by downloading Parquet files before querying them.
286+
287+
By default, this folder should be mounted to `.cubestore/data` inside the
288+
container and can be configured by `CUBESTORE_DATA_DIR` environment variable.
277289
It is advised to use local SSDs for this scratch space to maximize querying
278290
performance.
279291

@@ -293,6 +305,16 @@ default.
293305

294306
</WarningBox>
295307

308+
### Garbage collection
309+
310+
Cleanup isn’t done in export buckets; however, it's done in the persistent
311+
storage of Cube Store. The default time-to-live (TTL) for orphaned
312+
pre-aggregation tables is one day.
313+
314+
Refresh worker should be able to finish pre-aggregation refresh before
315+
garbage collection starts. It means that all pre-aggregation partitions
316+
should be built before any tables are removed.
317+
296318
## Security
297319

298320
Cube Store currently does not have any in-built authentication mechanisms. For

docs/docs-new/pages/product/configuration.mdx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,36 @@ Docker container.
120120
You can edit the configuration file by going into <Btn>Development Mode</Btn>
121121
and navigating to the <Btn>Data Model</Btn> page.
122122

123-
## Runtime and dependencies
123+
## Runtimes and dependencies
124124

125-
As of v0.34, Cube uses Node.js v16.20 to execute JavaScript-based
126-
configuration and Python v3.9 for Python-based configuration.
125+
As of v0.34, Cube uses Python v3.9 and Node.js v16.20 as runtime environments
126+
for the code of configuration and [dynamic data models][ref-dynamic-data-models].
127127

128-
If you have dependencies in `requirements.txt` file, make sure to install
129-
them by running `pip install -r requirements.txt` inside the container.
128+
It's recommended to use `requirements.txt` and `package.json` files to
129+
specify dependencies for your Python and JavaScript code, respectively.
130130

131-
If you have dependencies in `package.json` file, make sure to install them
132-
by running `yarn` and mount the `node_modules` folder under `/cube/conf`
133-
in the Docker container.
131+
### Cube Core
132+
133+
If you have specified Python packages in the `requirements.txt` file,
134+
make sure to install them by running `pip install -r requirements.txt`
135+
inside the Docker container.
136+
137+
If you have specified npm packages in the `package.json` file, make sure
138+
to install them by running `npm install` inside the Docker container.
139+
Alternatively, you can run `npm install` on your local machine and mount
140+
the `node_modules` folder under `/cube/conf` in the Docker container;
141+
however, if your dependencies contain native extensions, they might not work
142+
when provided this way.
143+
144+
To automate the installation of dependencies, build and use a [custom
145+
Docker image][ref-custom-docker-image].
146+
147+
### Cube Cloud
148+
149+
Cube Cloud automatically installs dependencies from `requirements.txt` and
150+
`package.json` files.
134151

135-
## Development Mode
152+
## Development mode
136153

137154
Cube can be run in an insecure, development mode by setting the
138155
`CUBEJS_DEV_MODE` environment variable to `true`. Putting Cube in development
@@ -163,5 +180,7 @@ mode does the following:
163180
[link-env-vars]: /reference/configuration/environment-variables
164181
[link-scheduled-refresh]:
165182
/reference/data-model/pre-aggregations#scheduled_refresh
183+
[ref-dynamic-data-models]: /product/data-modeling/dynamic
184+
[ref-custom-docker-image]: /product/deployment/core#extend-the-docker-image
166185

167186
[link-docker-env-vars]: https://docs.docker.com/compose/environment-variables/set-environment-variables/

docs/docs-new/pages/product/data-modeling/dynamic/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
"jinja": "Dynamic data models with Jinja and Python",
33
"javascript": "Dynamic data models with JavaScript",
44
"code-reusability-export-and-import": "Export and import",
5-
"schema-execution-environment": "Execution Environment (JS models)"
5+
"schema-execution-environment": "Execution environment (JavaScript models)"
66
}

docs/docs-new/pages/product/data-modeling/dynamic/jinja.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,34 @@ cubes:
112112
FROM app_data.payments
113113
```
114114

115+
### Escaping unsafe strings
116+
117+
[Auto-escaping][jinja-docs-autoescaping] of unsafe string values in Jinja
118+
templates is enabled by default. It means that any strings coming from Python
119+
might get wrapped in quotes, potentially breaking YAML syntax.
120+
121+
You can work around that by using the [`safe` Jinja
122+
filter][jinja-docs-filters-safe] with such string values:
123+
124+
```yaml
125+
cubes:
126+
- name: my_cube
127+
description: {{ get_unsafe_string() | safe }}
128+
```
129+
130+
Alternatively, you can wrap unsafe strings into instances of the following
131+
class in your Python code, effectively marking them as safe. This is
132+
particularly useful for library code, e.g., similar to the
133+
[`cube_dbt`][ref-cube-dbt] package.
134+
135+
```python
136+
class SafeString(str):
137+
is_safe: bool
138+
139+
def __init__(self, v: str):
140+
self.is_safe = True
141+
```
142+
115143
## Python
116144

117145
You can declare and invoke Python functions from within a Jinja template. This
@@ -201,3 +229,6 @@ cubes:
201229
[jinja-docs-for-loop]: https://jinja.palletsprojects.com/en/3.1.x/templates/#for
202230
[jinja-docs-macros]:
203231
https://jinja.palletsprojects.com/en/3.1.x/templates/#macros
232+
[jinja-docs-autoescaping]: https://jinja.palletsprojects.com/en/3.1.x/api/#autoescaping
233+
[jinja-docs-filters-safe]: https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.safe
234+
[ref-cube-dbt]: /reference/python/cube_dbt

docs/docs-new/pages/product/deployment/core.mdx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ services:
280280
281281
## Extend the Docker image
282282
283-
If you need to use npm packages with native extensions inside [the `cube.js`
284-
configuration file][ref-config-js], you'll need to build your own Docker image.
285-
You can do this by first creating a `Dockerfile` and a corresponding
286-
`.dockerignore`:
283+
If you need to use dependencies (i.e., Python or npm packages) with native
284+
extensions inside [configuration files][ref-config-files] or [dynamic data
285+
models][ref-dynamic-data-models], build a custom Docker image.
286+
287+
You can do this by creating a `Dockerfile` and a corresponding
288+
`.dockerignore` file:
287289

288290
```bash{promptUser: user}
289291
touch Dockerfile
@@ -296,23 +298,26 @@ Add this to the `Dockerfile`:
296298
FROM cubejs/cube:latest
297299

298300
COPY . .
301+
RUN apt update && apt install -y pip
302+
RUN pip install -r requirements.txt
299303
RUN npm install
300304
```
301305

302306
And this to the `.dockerignore`:
303307

304308
```gitignore
305-
node_modules
306-
npm-debug.log
307309
schema
310+
cube.py
308311
cube.js
309312
.env
313+
node_modules
314+
npm-debug.log
310315
```
311316

312317
Then start the build process by running the following command:
313318

314319
```bash{promptUser: user}
315-
docker build -t <YOUR-USERNAME>/cubejs-custom-build .
320+
docker build -t <YOUR-USERNAME>/cube-custom-image .
316321
```
317322

318323
Finally, update your `docker-compose.yml` to use your newly-built image:
@@ -322,31 +327,41 @@ version: "2.2"
322327

323328
services:
324329
cube_api:
325-
image: <YOUR-USERNAME>/cubejs-custom-build
330+
image: <YOUR-USERNAME>/cube-custom-image
326331
ports:
327332
- 4000:4000
328333
environment:
329-
- CUBEJS_DB_TYPE=bigquery
330-
- CUBEJS_DB_BQ_PROJECT_ID=cubejs-bq-cluster
331-
- CUBEJS_DB_BQ_CREDENTIALS=<BQ-KEY>
332-
- CUBEJS_DB_EXPORT_BUCKET=cubestore
333-
- CUBEJS_CUBESTORE_HOST=cubestore_router
334334
- CUBEJS_API_SECRET=secret
335+
# Other environment variables
335336
volumes:
336337
- .:/cube/conf
337-
# Prevent dev dependencies leaking
338-
- .empty:/cube/conf/node_modules/@cubejs-backend/
339338
depends_on:
340339
- cubestore_router
341340
- cube_refresh_worker
341+
# Other container dependencies
342+
```
343+
344+
Note that you shoudn't mount the whole current folder (`.:/cube/conf`)
345+
if you have dependencies in `package.json`. Doing so would effectively
346+
hide the `node_modules` folder inside the container, where dependency files
347+
installed with `npm install` reside, and result in errors like this:
348+
`Error: Cannot find module 'my_dependency'`. In that case, mount individual files:
349+
350+
```yaml
351+
# ...
352+
volumes:
353+
- ./schema:/cube/conf/schema
354+
- ./cube.js:/cube/conf/cube.js
355+
# Other necessary files
342356
```
343357

344358
[medium-letsencrypt-nginx]:
345359
https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
346360
[link-cubejs-docker]: https://hub.docker.com/r/cubejs/cube
347361
[link-docker-app]: https://www.docker.com/products/docker-app
348362
[link-nginx]: https://www.nginx.com/
349-
[ref-config-js]: /reference/configuration/config
363+
[ref-config-files]: /product/configuration#cubepy-and-cubejs-files
364+
[ref-dynamic-data-models]: /product/data-modeling/dynamic
350365
[ref-config-queryrewrite]: /reference/configuration/config#queryrewrite
351366
[ref-config-sched-ref-ctx]:
352367
/reference/configuration/config#scheduledrefreshcontexts

docs/docs-new/pages/product/workspace/semantic-layer-sync.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,13 @@ module.exports = {
311311
### Preset
312312

313313
Data model is synchronized via [Preset API][preset-api] which uses API keys for
314-
authentication. You can generate a new API key in your [user
314+
authentication.
315+
316+
You can generate a new API key in your [user
315317
settings][preset-user-settings] in Preset to obtain an `api_token` and an
316318
`api_secret`. You can also copy a `workspace_url` at any page of your Preset
317-
workspace.
319+
workspace. Note that your use should have the [workspace
320+
role][preset-user-roles] of `Workspace Admin`.
318321

319322
Example confguration for Preset:
320323

@@ -538,6 +541,7 @@ and clicking <Btn>Show History</Btn> next to a relevant sync.
538541
[ref-dev-mode]: /product/workspace/dev-mode
539542
[preset-api]: https://api-docs.preset.io
540543
[preset-user-settings]: https://manage.app.preset.io/app/user
544+
[preset-user-roles]: https://docs.preset.io/docs/role-based-access-security-rbac#change-user-access-to-a-workspace
541545
[superset-api]: https://superset.apache.org/docs/api/
542546
[metabase-api]:
543547
https://www.metabase.com/learn/administration/metabase-api#authenticate-your-requests-with-a-session-token

0 commit comments

Comments
 (0)