Skip to content

Commit

Permalink
Filtering by customer_id any time that execute a query in CubeJs (#30931
Browse files Browse the repository at this point in the history
)

### Proposed Changes
* Setting the Cube.js in the Docker Container


https://github.com/dotCMS/core/pull/30931/files#diff-106fd8c9a322da82fa432a4a4e9447566d08b515d01153f78854b0ffe892d2faR134

* Setting the JWK URL right


https://github.com/dotCMS/core/pull/30931/files#diff-106fd8c9a322da82fa432a4a4e9447566d08b515d01153f78854b0ffe892d2faR125

* Setting the CUBEJS_JWT_ISSUER right the value in the token for the
'iss' attribute is 'http://localhost:61111/realms/dotcms'


https://github.com/dotCMS/core/pull/30931/files#diff-106fd8c9a322da82fa432a4a4e9447566d08b515d01153f78854b0ffe892d2faR127

* Include filter by cluster and customer but just if the Query is using
the request scope it means if it not a Experiment Query



https://github.com/dotCMS/core/pull/30931/files#diff-3b5963eeaa042b27689c692068c4ae553d2ccedabb046e78543c28784c18e777R24-R36

* Include cluster_id and customer_id in the CubeJS Schema


https://github.com/dotCMS/core/pull/30931/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR182-R183
  • Loading branch information
freddyDOTCMS authored Dec 12, 2024
1 parent cce9540 commit b8de85e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docker/docker-compose-examples/analytics/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ services:
- CUBEJS_DB_NAME=${CH_DB:-clickhouse_test_db}
- CUBEJS_DB_USER=${CH_USER:-clickhouse_test_user}
- CUBEJS_DB_PASS=${CH_PWD:-clickhouse_password}
- CUBEJS_JWK_URL=${JWKS_URL:-http://keycloak:61111/realms/dotcms/protocol/openid-connect/certs}
- CUBEJS_JWK_URL=${JWKS_URL:-http://host.docker.internal:61111/realms/dotcms/protocol/openid-connect/certs}
- CUBEJS_JWT_AUDIENCE=api-dotcms-analytics-audience
- CUBEJS_JWT_ISSUER=${AUTH_SERVER_URL:-http://keycloak:61111/realms/dotcms}
- CUBEJS_JWT_ISSUER=${AUTH_SERVER_URL:-http://localhost:61111/realms/dotcms}
- CUBEJS_JWT_ALGS=RS256
- CUBEJS_JWT_CLAIMS_NAMESPACE=https://dotcms.com/analytics
- CUBEJS_LOG_LEVEL=debug
volumes:
- cube_metastore:/cube/conf/.cubestore
- ./setup/config/dev/cube/schema:/cube/conf/schema
- ./setup/config/dev/cube/cube.js:/cube/conf/cube.js

ch_server:
container_name: ch_server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


// cube.js configuration file
module.exports = {
/*
Expand All @@ -7,21 +9,31 @@ module.exports = {
`pre_aggregations_${securityContext.customerId}`,
*/

queryRewrite: (query, { securityContext }) => {

queryRewrite: (query, { securityContext }) => {

if (!securityContext) {
throw new Error('No valid token');
}

const tokenData = securityContext["https://dotcms.com/analytics"];

const isRequestQuery = (query.measures + query.dimensions).includes("request.");

if (isRequestQuery) {
query.filters.push({
member: 'Events.clusterId',
member: 'request.clusterId',
operator: 'equals',
values: [tokenData.clusterId],
});

query.filters.push({
member: 'request.customerId',
operator: 'equals',
values: [tokenData.customerId],
});
}


return query;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ cube('request', {
MAX(CASE WHEN event_type = 'URL_MAP' THEN object_content_type_var_name ELSE NULL END) as url_map_content_type_var_name,
MAX(object_detail_page_url) as url_map_detail_page_url,
MAX(url) AS url,
MAX(cluster_id) AS cluster_id,
MAX(customer_id) AS customer_id,
CASE
WHEN MAX(CASE WHEN event_type = 'FILE_REQUEST' THEN 1 ELSE 0 END) = 1 THEN 'FILE'
WHEN MAX(CASE WHEN event_type = 'PAGE_REQUEST' THEN 1 ELSE 0 END) = 1 THEN 'PAGE'
Expand All @@ -189,6 +191,8 @@ cube('request', {
GROUP BY request_id`,
dimensions: {
requestId: { sql: 'request_id', type: `string` },
clusterId: { sql: 'cluster_id', type: `string` },
customerId: { sql: 'customer_id', type: `string` },
sessionId: { sql: 'sessionid', type: `string` },
isSessionNew: { sql: 'isSessionNew', type: `boolean` },
createdAt: { sql: 'createdAt', type: `time`, },
Expand Down

0 comments on commit b8de85e

Please sign in to comment.