Skip to content

Commit

Permalink
feat(api): Add git-based server version to the UI and config endpoint (
Browse files Browse the repository at this point in the history
…#3866)

Co-authored-by: Shirshanka Das <[email protected]>
  • Loading branch information
Dexter Lee and shirshanka authored Jan 11, 2022
1 parent adce0de commit 2b54475
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 43 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ out
**/*.class
# Have to copy gradle/wrapper/gradle-wrapper.jar, can't exclude ALL jars
**/build/**/*.jar
.git
# Content in .git is used to get the git version
# Just ignore the heavy parts that are not used
.git/logs
.git/COMMIT_*
.git/index
.gradle
3 changes: 3 additions & 0 deletions .github/workflows/docker-datahub-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -69,6 +71,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-upgrade/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
3 changes: 3 additions & 0 deletions .github/workflows/docker-elasticsearch-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -70,6 +72,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/elasticsearch-setup/Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docker-feast-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-frontend-react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -72,6 +74,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-frontend/Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-gms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -72,6 +74,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-gms/Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-ingestion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -77,6 +79,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-ingestion/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-kafka-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -69,6 +71,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/kafka-setup/Dockerfile
platforms: linux/amd64,linux/arm64
context: ./docker/kafka-setup
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-mae-consumer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -68,6 +70,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-mae-consumer/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
3 changes: 3 additions & 0 deletions .github/workflows/docker-mce-consumer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -68,6 +70,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/datahub-mce-consumer/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
3 changes: 3 additions & 0 deletions .github/workflows/docker-mysql-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -66,6 +68,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/mysql-setup/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
3 changes: 3 additions & 0 deletions .github/workflows/docker-postgres-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
Expand All @@ -66,6 +68,7 @@ jobs:
- name: Build and Push image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/postgres-setup/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
push: ${{ needs.setup.outputs.publish == 'true' }}
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ buildscript {
}
}

plugins {
id 'com.gorylenko.gradle-git-properties' version '2.4.0-rc2'
}

project.ext.spec = [
'product' : [
'pegasus' : [
Expand Down Expand Up @@ -147,6 +151,15 @@ configure(subprojects.findAll {it.name != 'spark-lineage'}) {
subprojects {

apply plugin: 'maven'
apply plugin: 'com.gorylenko.gradle-git-properties'

gitProperties {
keys = ['git.commit.id','git.commit.id.describe','git.commit.time']
// using any tags (not limited to annotated tags) for "git.commit.id.describe" property
// see http://ajoberstar.org/grgit/grgit-describe.html for more info about the describe method and available parameters
// 'it' is an instance of org.ajoberstar.grgit.Grgit
customProperty 'git.commit.id.describe', { it.describe(tags: true) }
}

plugins.withType(JavaPlugin) {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
import com.linkedin.metadata.models.registry.EntityRegistry;
import com.linkedin.metadata.recommendation.RecommendationsService;
import com.linkedin.metadata.graph.GraphClient;
import com.linkedin.metadata.version.GitVersion;
import com.linkedin.usage.UsageClient;
import graphql.execution.DataFetcherResult;
import graphql.schema.idl.RuntimeWiring;
Expand Down Expand Up @@ -153,6 +154,7 @@ public class GmsGraphQLEngine {
private final RecommendationsService recommendationsService;
private final EntityRegistry entityRegistry;
private final TokenService tokenService;
private final GitVersion gitVersion;

private final DatasetType datasetType;
private final CorpUserType corpUserType;
Expand Down Expand Up @@ -207,6 +209,7 @@ public GmsGraphQLEngine() {
null,
null,
null,
null,
null);
}

Expand All @@ -218,7 +221,8 @@ public GmsGraphQLEngine(
final EntityService entityService,
final RecommendationsService recommendationsService,
final TokenService tokenService,
final EntityRegistry entityRegistry
final EntityRegistry entityRegistry,
final GitVersion gitVersion
) {

this.entityClient = entityClient;
Expand All @@ -230,6 +234,7 @@ public GmsGraphQLEngine(
this.recommendationsService = recommendationsService;
this.tokenService = tokenService;
this.entityRegistry = entityRegistry;
this.gitVersion = gitVersion;

this.datasetType = new DatasetType(entityClient);
this.corpUserType = new CorpUserType(entityClient);
Expand Down Expand Up @@ -398,7 +403,7 @@ private void configureAnalyticsResolvers(final RuntimeWiring.Builder builder) {
private void configureQueryResolvers(final RuntimeWiring.Builder builder) {
builder.type("Query", typeWiring -> typeWiring
.dataFetcher("appConfig",
new AppConfigResolver(analyticsService != null))
new AppConfigResolver(gitVersion, analyticsService != null))
.dataFetcher("me", new AuthenticatedResolver<>(
new MeResolver(this.entityClient)))
.dataFetcher("search", new AuthenticatedResolver<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.linkedin.datahub.graphql.generated.PoliciesConfig;
import com.linkedin.datahub.graphql.generated.Privilege;
import com.linkedin.datahub.graphql.generated.ResourcePrivileges;
import com.linkedin.metadata.version.GitVersion;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.concurrent.CompletableFuture;
Expand All @@ -20,9 +21,11 @@
*/
public class AppConfigResolver implements DataFetcher<CompletableFuture<AppConfig>> {

private final Boolean _isAnalyticsEnabled;
private final GitVersion _gitVersion;
private final boolean _isAnalyticsEnabled;

public AppConfigResolver(final Boolean isAnalyticsEnabled) {
public AppConfigResolver(final GitVersion gitVersion, final boolean isAnalyticsEnabled) {
_gitVersion = gitVersion;
_isAnalyticsEnabled = isAnalyticsEnabled;
}

Expand All @@ -33,6 +36,8 @@ public CompletableFuture<AppConfig> get(final DataFetchingEnvironment environmen

final AppConfig appConfig = new AppConfig();

appConfig.setAppVersion(_gitVersion.getVersion());

final AnalyticsConfig analyticsConfig = new AnalyticsConfig();
analyticsConfig.setEnabled(_isAnalyticsEnabled);

Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/app.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Config loaded at application boot time
This configuration dictates the behavior of the UI, such as which features are enabled or disabled
"""
type AppConfig {
"""
App version
"""
appVersion: String

"""
Configurations related to the Analytics Feature
"""
Expand Down
5 changes: 4 additions & 1 deletion datahub-web-react/src/app/shared/ManageAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isLoggedInVar } from '../auth/checkAuthStatus';
import CustomAvatar from './avatar/CustomAvatar';
import analytics, { EventType } from '../analytics';
import { ANTD_GRAY } from '../entity/shared/constants';
import { useAppConfig } from '../useAppConfig';

const MenuItem = styled(Menu.Item)`
&& {
Expand Down Expand Up @@ -44,14 +45,16 @@ const defaultProps = {
export const ManageAccount = ({ urn: _urn, pictureLink: _pictureLink, name }: Props) => {
const entityRegistry = useEntityRegistry();
const themeConfig = useTheme();
const { config } = useAppConfig();
const handleLogout = () => {
analytics.event({ type: EventType.LogOutEvent });
isLoggedInVar(false);
Cookies.remove(GlobalCfg.CLIENT_AUTH_COOKIE);
};

const version = config?.appVersion;
const menu = (
<Menu>
{version && <MenuItem key="version">{version}</MenuItem>}
{themeConfig.content.menu.items.map((value) => {
return (
<MenuItem key={value.label}>
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/graphql/app.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query appConfig {
appConfig {
appVersion
policiesConfig {
enabled
platformPrivileges {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.linkedin.metadata.version;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import lombok.Value;


@Value
public class GitVersion {
String version;
String commitId;
Optional<String> flag;

public static GitVersion getVersion(@Nonnull String commitId, @Nonnull String commitDescribe) {
String version = commitDescribe.split("-")[0];
return new GitVersion(version, commitId, Optional.empty());
}

public Map<String, Object> toConfig() {
return ImmutableMap.of("version", version, "commit", commitId);
}
}
Loading

0 comments on commit 2b54475

Please sign in to comment.