Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datahub-gms) usage stats queryRange API's Authorization error for Dataset Owners #8819

Conversation

siladitya2
Copy link
Contributor

@siladitya2 siladitya2 commented Sep 11, 2023

This PR include a fix to solve the below exception while accessing the usageStats's queryRange API:

2023-09-11 12:57:23,798 [qtp2141817446-3348] ERROR c.l.m.filter.RestliLoggingFilter:38 - Rest.li error: 
com.linkedin.restli.server.RestLiServiceException: User is unauthorized to query usage.
	at com.linkedin.metadata.resources.usage.UsageStats.queryRange(UsageStats.java:385)
	at jdk.internal.reflect.GeneratedMethodAccessor401.invoke(Unknown Source)

How the bug can be reproduced:

  1. Enable REST_API_AUTHORIZATION_ENABLED
  2. Ingest a policy either with resourceOwners true with a resourceOwnersTypes or having a resources filter, please find a sample policy:
   {
      "urn":"urn:li:dataHubPolicy:test-asset-owners-metadata-policy",
      "info":{
         "actors":{
            "resourceOwners":true,
            "resourceOwnersTypes":[
              "urn:li:ownershipType:0e4793b8-bfee-439d-a107-fc02b2672485"
            ],
            "allUsers":false,
            "allGroups":false,
            "users":[

            ],
            "groups":[

            ]
         },
         "privileges":[
            "VIEW_DATASET_USAGE",
            "VIEW_DATASET_PROFILE",
            "EDIT_LINEAGE",
            "GET_TIMELINE_PRIVILEGE",
            "GET_ENTITY_PRIVILEGE",
            "GET_TIMESERIES_ASPECT_PRIVILEGE",
            "GET_COUNTS_PRIVILEGE",
            "EDIT_ENTITY"
         ],
         "displayName":"Test Owners - Test Metadata Policy",
         "description":"Test description.",
         "state":"ACTIVE",
         "type":"METADATA",
         "editable":true,
         "resources":{
          "filter":{
             "criteria":[
                {
                   "field":"RESOURCE_TYPE",
                   "condition":"EQUALS",
                   "values":[
                      "dataset"
                   ]
                }
             ]
          }
       }
      }
   }
  1. the privileges should contain VIEW_DATASET_USAGE
  2. Add a Owner to a Dataset
  3. When the Owner of the dataset perform below graphql query:
 query Dataset($urn: String!, $resource: String, $range: TimeRange) {
  dataset(urn: $urn) {
    usageStats(resource: $resource, range: $range) {
      aggregations {
        uniqueUserCount
        totalSqlQueries
      }
    }
  }
}

Result:
The above query failed with below exception in the logs:

 com.linkedin.restli.server.RestLiServiceException: User is unauthorized to query usage.
	at com.linkedin.metadata.resources.usage.UsageStats.queryRange(UsageStats.java:385)

This Fix should resolve the issue reported here #8781

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

@siladitya2 siladitya2 changed the title fix(datahub-gms) usage stats queryRange API's Authorization error fix(datahub-gms) usage stats queryRange API's Authorization error for Dataset Owners Sep 13, 2023
@jjoyce0510 jjoyce0510 merged commit 9fdfa49 into datahub-project:master Sep 20, 2023
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devops PR or Issue related to DataHub backend & deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants