core icon indicating copy to clipboard operation
core copied to clipboard

Include the customer_id as filter automatically in each request

Open freddyARD opened this issue 2 years ago • 3 comments

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

freddyARD avatar Oct 18 '24 21:10 freddyARD

PRs:

  • https://github.com/dotCMS/core/pull/30931

github-actions[bot] avatar Dec 12 '24 13:12 github-actions[bot]

Steps to QA:

  1. Remove the Analitycs Container from the Docker server to be sure that we are going to start with a empty environment
  2. Start dotCMS and the Analytics infrastructure.
  3. Go to "http://localhost:61111/" in the browser, and click the "Administration Console" link
image
  1. Log in in the Keyclock server

User: admin Password: keycloak

  1. Go to the Client Menu and click in the "Create" button
  2. Click in the "Select file" button to import a new user
image

Use this file to import: analytics-customer-customer2.json

  1. Drill into the recent created Client and click on the Credentials tab and copy the value from Secret field to be used as Client Secret in the App configuration. Image

  2. 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/
  1. Visit some pages to generate some events
  2. 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"]
      }
  }'
  1. Verify that some results are retrieved:
{
    "entity": [
        {
            "request.count": "XX"
        }
    ],
    "errors": [],
    "i18nMessagesMap": {},
    "messages": [],
    "pagination": null,
    "permissions": []
}
  1. 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/
  1. Hit the Endpoint again and you must get 0

freddyARD avatar Dec 17 '24 16:12 freddyARD

Tested using dotcms/dotcms:trunk_9bd0ce7

customer2 configuration: image

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: image After running same curl command got this:

{
    "entity": [
        {
            "request.count": "0"
        }
    ],
    "errors": [],
    "i18nMessagesMap": {},
    "messages": [],
    "pagination": null,
    "permissions": []
}

victoralfaro-dotcms avatar Dec 19 '24 19:12 victoralfaro-dotcms