Skip to content

Commit

Permalink
Merge branch 'master' into master+looker-ingestion-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
siddiquebagwan authored Sep 26, 2023
2 parents 3e63527 + 53eaac5 commit f8952b8
Show file tree
Hide file tree
Showing 340 changed files with 6,432 additions and 2,305 deletions.
26 changes: 14 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
ext.openTelemetryVersion = '1.18.0'
ext.neo4jVersion = '4.4.9'
ext.testContainersVersion = '1.17.4'
ext.elasticsearchVersion = '7.10.2'
ext.elasticsearchVersion = '2.9.0' // ES 7.10, Opensearch 1.x, 2.x
ext.jacksonVersion = '2.15.2'
ext.jettyVersion = '9.4.46.v20220331'
ext.playVersion = '2.8.18'
Expand Down Expand Up @@ -90,15 +90,15 @@ project.ext.externalDependency = [
'ebean': 'io.ebean:ebean:' + ebeanVersion,
'ebeanAgent': 'io.ebean:ebean-agent:' + ebeanVersion,
'ebeanDdl': 'io.ebean:ebean-ddl-generator:' + ebeanVersion,
'elasticSearchRest': 'org.elasticsearch.client:elasticsearch-rest-high-level-client:' + elasticsearchVersion,
'elasticSearchTransport': 'org.elasticsearch.client:transport:' + elasticsearchVersion,
'elasticSearchRest': 'org.opensearch.client:opensearch-rest-high-level-client:' + elasticsearchVersion,
'elasticSearchJava': 'org.opensearch.client:opensearch-java:2.6.0',
'findbugsAnnotations': 'com.google.code.findbugs:annotations:3.0.1',
'graphqlJava': 'com.graphql-java:graphql-java:19.5',
'graphqlJavaScalars': 'com.graphql-java:graphql-java-extended-scalars:19.1',
'gson': 'com.google.code.gson:gson:2.8.9',
'guice': 'com.google.inject:guice:4.2.3',
'guava': 'com.google.guava:guava:32.1.2-jre',
'h2': 'com.h2database:h2:2.1.214',
'h2': 'com.h2database:h2:2.2.224',
'hadoopCommon':'org.apache.hadoop:hadoop-common:2.7.2',
'hadoopMapreduceClient':'org.apache.hadoop:hadoop-mapreduce-client-core:2.7.2',
"hadoopClient": "org.apache.hadoop:hadoop-client:$hadoop3Version",
Expand Down Expand Up @@ -202,13 +202,15 @@ project.ext.externalDependency = [
'springActuator': "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion",
'swaggerAnnotations': 'io.swagger.core.v3:swagger-annotations:2.1.12',
'swaggerCli': 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.41',
'testng': 'org.testng:testng:7.3.0',
'testngJava8': 'org.testng:testng:7.5.1',
'testng': 'org.testng:testng:7.8.0',
'testContainers': 'org.testcontainers:testcontainers:' + testContainersVersion,
'testContainersJunit': 'org.testcontainers:junit-jupiter:' + testContainersVersion,
'testContainersPostgresql':'org.testcontainers:postgresql:' + testContainersVersion,
'testContainersElasticsearch': 'org.testcontainers:elasticsearch:' + testContainersVersion,
'testContainersCassandra': 'org.testcontainers:cassandra:' + testContainersVersion,
'testContainersKafka': 'org.testcontainers:kafka:' + testContainersVersion,
'testContainersOpenSearch': 'org.opensearch:opensearch-testcontainers:2.0.0',
'typesafeConfig':'com.typesafe:config:1.4.1',
'wiremock':'com.github.tomakehurst:wiremock:2.10.0',
'zookeeper': 'org.apache.zookeeper:zookeeper:3.4.14',
Expand Down Expand Up @@ -257,7 +259,6 @@ subprojects {

plugins.withType(JavaPlugin) {
dependencies {
testImplementation externalDependency.testng
constraints {
implementation('io.netty:netty-all:4.1.86.Final')
implementation('org.apache.commons:commons-compress:1.21')
Expand All @@ -268,12 +269,6 @@ subprojects {
}
}

tasks.withType(Test) {
if (!name.startsWith('integ')) {
useTestNG()
}
}

checkstyle {
configDirectory = file("${project.rootDir}/gradle/checkstyle")
sourceSets = [ getProject().sourceSets.main, getProject().sourceSets.test ]
Expand All @@ -292,6 +287,13 @@ subprojects {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
// https://docs.gradle.org/current/userguide/performance.html
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1

if (project.configurations.getByName("testImplementation").getDependencies()
.any{ it.getName() == "testng" }) {
useTestNG()
}
}

afterEvaluate {
Expand Down
25 changes: 19 additions & 6 deletions datahub-frontend/app/auth/AuthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.entity.client.RestliEntityClient;
import com.linkedin.entity.client.SystemEntityClient;
import com.linkedin.entity.client.SystemRestliEntityClient;
import com.linkedin.metadata.restli.DefaultRestliClientFactory;
import com.linkedin.parseq.retry.backoff.ExponentialBackoff;
import com.linkedin.util.Configuration;
import config.ConfigurationProvider;
import controllers.SsoCallbackController;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
Expand All @@ -34,6 +37,7 @@
import org.pac4j.play.store.PlayCookieSessionStore;
import org.pac4j.play.store.PlaySessionStore;
import org.pac4j.play.store.ShiroAesDataEncrypter;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import play.Environment;
import play.cache.SyncCacheApi;
import utils.ConfigUtil;
Expand Down Expand Up @@ -104,7 +108,7 @@ protected void configure() {
bind(SsoCallbackController.class).toConstructor(SsoCallbackController.class.getConstructor(
SsoManager.class,
Authentication.class,
EntityClient.class,
SystemEntityClient.class,
AuthServiceClient.class,
com.typesafe.config.Config.class));
} catch (NoSuchMethodException | SecurityException e) {
Expand Down Expand Up @@ -161,10 +165,19 @@ protected Authentication provideSystemAuthentication() {

@Provides
@Singleton
protected EntityClient provideEntityClient() {
return new RestliEntityClient(buildRestliClient(),
protected ConfigurationProvider provideConfigurationProvider() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigurationProvider.class);
return context.getBean(ConfigurationProvider.class);
}

@Provides
@Singleton
protected SystemEntityClient provideEntityClient(final Authentication systemAuthentication,
final ConfigurationProvider configurationProvider) {
return new SystemRestliEntityClient(buildRestliClient(),
new ExponentialBackoff(_configs.getInt(ENTITY_CLIENT_RETRY_INTERVAL)),
_configs.getInt(ENTITY_CLIENT_NUM_RETRIES));
_configs.getInt(ENTITY_CLIENT_NUM_RETRIES), systemAuthentication,
configurationProvider.getCache().getClient().getEntityClient());
}

@Provides
Expand Down
7 changes: 4 additions & 3 deletions datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.SetMode;
import com.linkedin.entity.Entity;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.entity.client.SystemEntityClient;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.identity.CorpGroupInfo;
import com.linkedin.identity.CorpUserEditableInfo;
Expand Down Expand Up @@ -78,13 +78,14 @@
public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebContext> {

private final SsoManager _ssoManager;
private final EntityClient _entityClient;
private final SystemEntityClient _entityClient;
private final Authentication _systemAuthentication;
private final AuthServiceClient _authClient;
private final CookieConfigs _cookieConfigs;

public OidcCallbackLogic(final SsoManager ssoManager, final Authentication systemAuthentication,
final EntityClient entityClient, final AuthServiceClient authClient, final CookieConfigs cookieConfigs) {
final SystemEntityClient entityClient, final AuthServiceClient authClient,
final CookieConfigs cookieConfigs) {
_ssoManager = ssoManager;
_systemAuthentication = systemAuthentication;
_entityClient = entityClient;
Expand Down
27 changes: 27 additions & 0 deletions datahub-frontend/app/config/ConfigurationProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package config;

import com.linkedin.metadata.config.cache.CacheConfiguration;
import com.linkedin.metadata.spring.YamlPropertySourceFactory;
import lombok.Data;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.PropertySource;


/**
* Minimal sharing between metadata-service and frontend
* Initially for use of client caching configuration.
* Does not use the factories module to avoid transitive dependencies.
*/
@EnableConfigurationProperties
@PropertySource(value = "application.yml", factory = YamlPropertySourceFactory.class)
@ConfigurationProperties
@Data
public class ConfigurationProvider {

/**
* Configuration for caching
*/
private CacheConfiguration cache;
}
6 changes: 3 additions & 3 deletions datahub-frontend/app/controllers/SsoCallbackController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import auth.CookieConfigs;
import client.AuthServiceClient;
import com.datahub.authentication.Authentication;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.entity.client.SystemEntityClient;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -40,7 +40,7 @@ public class SsoCallbackController extends CallbackController {
public SsoCallbackController(
@Nonnull SsoManager ssoManager,
@Nonnull Authentication systemAuthentication,
@Nonnull EntityClient entityClient,
@Nonnull SystemEntityClient entityClient,
@Nonnull AuthServiceClient authClient,
@Nonnull com.typesafe.config.Config configs) {
_ssoManager = ssoManager;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class SsoCallbackLogic implements CallbackLogic<Result, PlayWebContext> {
private final OidcCallbackLogic _oidcCallbackLogic;

SsoCallbackLogic(final SsoManager ssoManager, final Authentication systemAuthentication,
final EntityClient entityClient, final AuthServiceClient authClient, final CookieConfigs cookieConfigs) {
final SystemEntityClient entityClient, final AuthServiceClient authClient, final CookieConfigs cookieConfigs) {
_oidcCallbackLogic = new OidcCallbackLogic(ssoManager, systemAuthentication, entityClient, authClient, cookieConfigs);
}

Expand Down
8 changes: 5 additions & 3 deletions datahub-frontend/play.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ dependencies {
implementation project(':datahub-web-react')

constraints {
play(externalDependency.springCore)
play(externalDependency.springBeans)
play(externalDependency.springContext)
play(externalDependency.jacksonDataBind)
play('com.nimbusds:oauth2-oidc-sdk:8.36.2')
play('com.nimbusds:nimbus-jose-jwt:8.18')
Expand All @@ -35,7 +32,12 @@ dependencies {

implementation project(":metadata-service:restli-client")
implementation project(":metadata-service:auth-config")
implementation project(":metadata-service:configuration")

implementation externalDependency.springCore
implementation externalDependency.springBeans
implementation externalDependency.springContext
implementation externalDependency.springBootAutoconfigure
implementation externalDependency.jettyJaas
implementation externalDependency.graphqlJava
implementation externalDependency.antlr4Runtime
Expand Down
1 change: 1 addition & 0 deletions datahub-graphql-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
annotationProcessor externalDependency.lombok

testImplementation externalDependency.mockito
testImplementation externalDependency.testng
}

graphqlCodegen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
import com.linkedin.datahub.graphql.types.test.TestType;
import com.linkedin.datahub.graphql.types.view.DataHubViewType;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.entity.client.SystemEntityClient;
import com.linkedin.metadata.config.DataHubConfiguration;
import com.linkedin.metadata.config.IngestionConfiguration;
import com.linkedin.metadata.config.TestsConfiguration;
Expand Down Expand Up @@ -364,6 +365,7 @@
public class GmsGraphQLEngine {

private final EntityClient entityClient;
private final SystemEntityClient systemEntityClient;
private final GraphClient graphClient;
private final UsageClient usageClient;
private final SiblingGraphService siblingGraphService;
Expand Down Expand Up @@ -476,6 +478,7 @@ public GmsGraphQLEngine(final GmsGraphQLEngineArgs args) {
this.graphQLPlugins.forEach(plugin -> plugin.init(args));

this.entityClient = args.entityClient;
this.systemEntityClient = args.systemEntityClient;
this.graphClient = args.graphClient;
this.usageClient = args.usageClient;
this.siblingGraphService = args.siblingGraphService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.linkedin.datahub.graphql.analytics.service.AnalyticsService;
import com.linkedin.datahub.graphql.featureflags.FeatureFlags;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.entity.client.SystemEntityClient;
import com.linkedin.metadata.config.DataHubConfiguration;
import com.linkedin.metadata.config.IngestionConfiguration;
import com.linkedin.metadata.config.TestsConfiguration;
Expand Down Expand Up @@ -38,6 +39,7 @@
@Data
public class GmsGraphQLEngineArgs {
EntityClient entityClient;
SystemEntityClient systemEntityClient;
GraphClient graphClient;
UsageClient usageClient;
AnalyticsService analyticsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@
import javax.annotation.Nonnull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.filter.Filter;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Cardinality;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.client.RequestOptions;
import org.opensearch.client.RestHighLevelClient;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.search.aggregations.AggregationBuilder;
import org.opensearch.search.aggregations.AggregationBuilders;
import org.opensearch.search.aggregations.Aggregations;
import org.opensearch.search.aggregations.BucketOrder;
import org.opensearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.opensearch.search.aggregations.bucket.filter.Filter;
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.opensearch.search.aggregations.bucket.histogram.Histogram;
import org.opensearch.search.aggregations.bucket.terms.Terms;
import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.opensearch.search.aggregations.metrics.Cardinality;
import org.opensearch.search.builder.SearchSourceBuilder;


@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.linkedin.datahub.graphql.resolvers.dataset;

import com.datahub.authorization.ResourceSpec;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.linkedin.common.urn.Urn;
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils;
import com.linkedin.datahub.graphql.generated.CorpUser;
import com.linkedin.datahub.graphql.generated.DatasetStatsSummary;
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.metadata.authorization.PoliciesConfig;
import com.linkedin.usage.UsageClient;
import com.linkedin.usage.UsageTimeRange;
import com.linkedin.usage.UserUsageCounts;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -55,8 +59,15 @@ public CompletableFuture<DatasetStatsSummary> get(DataFetchingEnvironment enviro

try {

if (!isAuthorized(resourceUrn, context)) {
log.debug("User {} is not authorized to view profile information for dataset {}",
context.getActorUrn(),
resourceUrn.toString());
return null;
}

com.linkedin.usage.UsageQueryResult
usageQueryResult = usageClient.getUsageStats(resourceUrn.toString(), UsageTimeRange.MONTH, context.getAuthentication());
usageQueryResult = usageClient.getUsageStats(resourceUrn.toString(), UsageTimeRange.MONTH);

final DatasetStatsSummary result = new DatasetStatsSummary();
result.setQueryCountLast30Days(usageQueryResult.getAggregations().getTotalSqlQueries());
Expand Down Expand Up @@ -90,4 +101,10 @@ private CorpUser createPartialUser(final Urn userUrn) {
result.setUrn(userUrn.toString());
return result;
}

private boolean isAuthorized(final Urn resourceUrn, final QueryContext context) {
return AuthorizationUtils.isAuthorized(context,
Optional.of(new ResourceSpec(resourceUrn.getEntityType(), resourceUrn.toString())),
PoliciesConfig.VIEW_DATASET_USAGE_PRIVILEGE);
}
}
Loading

0 comments on commit f8952b8

Please sign in to comment.