Include the customer_id as filter automatically in each request
Parent Issue
No response
Problem Statement
The Analytics environments are going to be shared for different customers so we need to filter by the current customer_id when we are running a query.
In addition, we need to include the customer_id field in the CubeJS schema.
Steps to Reproduce
- Add or Update some data manually into the Clickhouse Events table to set a different customer*id
- Run a query and check that the data with the new customer*id is retrieve even when the Analytics App is configure for customer1
Acceptance Criteria
When we run a query we must get just data for the current customer
dotCMS Version
latest
Proposed Objective
Core Features
Proposed Priority
Priority 2 - Important
External Links... Slack Conversations, Support Tickets, Figma Designs, etc.
No response
Assumptions & Initiation Needs
No response
Quality Assurance Notes & Workarounds
No response
Sub-Tasks & Estimates
No response
PRs:
- https://github.com/dotCMS/core/pull/30931
Steps to QA:
- Remove the Analitycs Container from the Docker server to be sure that we are going to start with a empty environment
- Start dotCMS and the Analytics infrastructure.
- Go to "http://localhost:61111/" in the browser, and click the "Administration Console" link
- Log in in the Keyclock server
User: admin Password: keycloak
- Go to the Client Menu and click in the "Create" button
- Click in the "Select file" button to import a new user
Use this file to import: analytics-customer-customer2.json
-
Drill into the recent created
Clientand click on theCredentialstab and copy the value fromSecretfield to be used asClient Secretin the App configuration. -
Config the Analytic App using this new user, so the App configuration values are going to be:
ClientIId: analytics-customer-customer2
Client Secret: <key copied from keycloak admin console>
Analytics Config URL http://localhost:8088/c/customer2/cluster2/keys
Analytics Write URL http://localhost:8081/api/v1/event
Analytics Read URL http://localhost:4001/
- Visit some pages to generate some events
- Hit the CA query endpoint and then you must got some results depending on the navigation you did on step 9.
curl --location 'http://localhost:8080/api/v1/analytics/content/_query' \
--header 'Content-Type: application/json' \
-u [email protected]:admin \
--data '{
"query": {
"measures": ["request.count"]
}
}'
- Verify that some results are retrieved:
{
"entity": [
{
"request.count": "XX"
}
],
"errors": [],
"i18nMessagesMap": {},
"messages": [],
"pagination": null,
"permissions": []
}
- Change the Analitycs App and use now the customer1.
ClientIId: analytics-customer-customer1
Client Secret: testsecret
Analytics Config URL http://localhost:8088/c/customer1/cluster1/keys
Analytics Write URL http://localhost:8081/api/v1/event
Analytics Read URL http://localhost:4001/
- Hit the Endpoint again and you must get 0
Tested using dotcms/dotcms:trunk_9bd0ce7
customer2 configuration:
After navigating through http://localhost:8080:
curl --location 'http://localhost:8080/api/v1/analytics/content/_query' \
--header 'Content-Type: application/json' \
-u [email protected]:admin \
--data '{
"query": {
"measures": ["request.count"]
}
}'
Got this:
{
"entity": [
{
"request.count": "36"
}
],
"errors": [],
"i18nMessagesMap": {},
"messages": [],
"pagination": null,
"permissions": []
}
Switched to customer1 configuration:
After running same curl command got this:
{
"entity": [
{
"request.count": "0"
}
],
"errors": [],
"i18nMessagesMap": {},
"messages": [],
"pagination": null,
"permissions": []
}