Skip to content

Commit f386b3f

Browse files
Merge pull request #19 from FundingCircle/GDP-1766_amplitude
GDP-1766: Add Amplitude
2 parents 9af5703 + fbff8c8 commit f386b3f

File tree

8 files changed

+136
-7
lines changed

8 files changed

+136
-7
lines changed

Diff for: .drone.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
kind: pipeline
2+
name: default
3+
4+
anchors:
5+
build_frontend: &build_frontend
6+
image: gradle:jdk11
7+
commands:
8+
- cd "/drone/src/$${ENVIRONMENT}"
9+
- sed -i "s/<AMPLITUDE_API_KEY>/$AMPLITUDE_API_KEY/g" datahub-web-react/src/conf/analytics.ts
10+
- cat datahub-web-react/src/conf/analytics.ts
11+
- ./gradlew :datahub-frontend:dist -x test -x yarnTest -x yarnLint --parallel
12+
- ls -la ./datahub-frontend/build/distributions/
13+
- mv ./datahub-frontend/build/distributions/datahub-frontend-*.zip datahub-frontend.zip
14+
depends_on:
15+
- setup
16+
17+
docker_build_config: &docker_build_config
18+
image: plugins/ecr
19+
environment:
20+
ARTIFACTORY_PASSWORD:
21+
from_secret: ARTIFACTORY_PASSWORD
22+
ARTIFACTORY_USER:
23+
from_secret: ARTIFACTORY_USER
24+
GITHUB_TOKEN:
25+
from_secret: GITHUB_TOKEN
26+
settings:
27+
create_repository: true
28+
region: eu-west-1
29+
assume_role: arn:aws:iam::131063299351:role/automation-drone
30+
repository_policy: .ecr-repository-policy.json
31+
repo: datahub-frontend
32+
custom_labels:
33+
34+
cache_from:
35+
- 131063299351.dkr.ecr.eu-west-1.amazonaws.com/datahub-frontend:${DRONE_BRANCH//\//-}
36+
build_args_from_env:
37+
- ARTIFACTORY_PASSWORD
38+
- ARTIFACTORY_USER
39+
- GITHUB_TOKEN
40+
41+
steps:
42+
- name: setup
43+
image: ubuntu
44+
commands:
45+
- mv /drone/src/* /tmp/
46+
- mkdir -p /drone/src/staging/ /drone/src/production/
47+
- cp -r /tmp/* /drone/src/staging/
48+
- cp -r /tmp/* /drone/src/production/
49+
50+
- name: build_frontend_staging
51+
<<: *build_frontend
52+
environment:
53+
ENVIRONMENT: staging
54+
AMPLITUDE_API_KEY: b46a366c22a2e7fb525ae99c14a693ec
55+
56+
- name: build_frontend_production
57+
<<: *build_frontend
58+
environment:
59+
ENVIRONMENT: production
60+
AMPLITUDE_API_KEY: f0b9cf5c530426c3dbacb91e74f009a5
61+
62+
- name: docker_frontend_staging
63+
<<: *docker_build_config
64+
settings:
65+
context: /drone/src/staging/
66+
dockerfile: /drone/src/staging/docker/datahub-frontend/Dockerfile
67+
tags:
68+
- staging
69+
depends_on:
70+
- build_frontend_staging
71+
72+
- name: docker_frontend_production
73+
<<: *docker_build_config
74+
settings:
75+
context: /drone/src/production/
76+
dockerfile: /drone/src/production/docker/datahub-frontend/Dockerfile
77+
tags:
78+
- production
79+
depends_on:
80+
- build_frontend_production

Diff for: .ecr-repository-policy.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "ECR Repository Policy",
6+
"Effect": "Allow",
7+
"Principal": {
8+
"AWS": "*"
9+
},
10+
"Action": [
11+
"ecr:BatchCheckLayerAvailability",
12+
"ecr:BatchGetImage",
13+
"ecr:GetDownloadUrlForLayer"
14+
],
15+
"Condition": {
16+
"StringEquals": {
17+
"aws:PrincipalOrgID": "o-t9bcvmrskg"
18+
}
19+
}
20+
}
21+
]
22+
}

Diff for: datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/analytics/resolver/GetHighlightsResolver.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private List<Highlight> getHighlights() {
111111
getEntityMetadataStats("Pipelines", EntityType.DATA_FLOW).ifPresent(highlights::add);
112112
getEntityMetadataStats("Tasks", EntityType.DATA_JOB).ifPresent(highlights::add);
113113
getEntityMetadataStats("Domains", EntityType.DOMAIN).ifPresent(highlights::add);
114+
getEntityMetadataStats("Data Products", EntityType.DATA_PRODUCT).ifPresent(highlights::add);
114115
return highlights;
115116
}
116117

Diff for: datahub-web-react/src/app/analytics/analytics.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ const { NODE_ENV } = process.env;
1818

1919
export function getMergedTrackingOptions(options?: any) {
2020
const isThirdPartyLoggingEnabled = JSON.parse(localStorage.getItem(THIRD_PARTY_LOGGING_KEY) || 'false');
21+
2122
return {
2223
...options,
2324
plugins: {
2425
mixpanel: isThirdPartyLoggingEnabled,
25-
amplitude: isThirdPartyLoggingEnabled,
26+
amplitude: true, // Only want amplitude so hard-code true. We hard code the API keys too, so 🤷
2627
googleAnalytics: isThirdPartyLoggingEnabled,
2728
},
2829
};

Diff for: datahub-web-react/src/app/analytics/plugin/amplitude.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ const apiKey = isEnabled ? amplitudeConfigs.apiKey : undefined;
77

88
export default {
99
isEnabled,
10-
plugin: apiKey && amplitude({ apiKey, options: {} }),
10+
plugin:
11+
apiKey &&
12+
amplitude({
13+
apiKey,
14+
options: {
15+
apiEndpoint: 'api.eu.amplitude.com',
16+
serverZone: 'EU',
17+
},
18+
}),
1119
};

Diff for: datahub-web-react/src/app/context/UserContextProvider.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useGetMeLazyQuery } from '../../graphql/me.generated';
33
import { useGetGlobalViewsSettingsLazyQuery } from '../../graphql/app.generated';
44
import { CorpUser, PlatformPrivileges } from '../../types.generated';
55
import { UserContext, LocalState, DEFAULT_STATE, State } from './userContext';
6+
import analytics from '../analytics';
67

78
// TODO: Migrate all usage of useAuthenticatedUser to using this provider.
89

@@ -41,6 +42,21 @@ const UserContextProvider = ({ children }: { children: React.ReactNode }) => {
4142
const [getMe, { data: meData, refetch }] = useGetMeLazyQuery({ fetchPolicy: 'cache-first' });
4243
useEffect(() => getMe(), [getMe]);
4344

45+
/**
46+
* Identify the user in the analytics tool once on component mount.
47+
* This lets Amplitude identify (and thus segment) the users on more attributes.
48+
* There may be a more optimal place to put this call, but I'm not sure
49+
*/
50+
useEffect(() => {
51+
if (meData?.me?.corpUser) {
52+
const corpUser = meData.me.corpUser as CorpUser;
53+
const info = corpUser.info ?? {};
54+
analytics.identify(corpUser.urn, {
55+
...info,
56+
});
57+
}
58+
}, [meData]);
59+
4460
/**
4561
* Retrieve the Global View settings once on component mount.
4662
*/

Diff for: datahub-web-react/src/conf/analytics.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const config: any = {
66
// mixpanel: {
77
// token: 'fad1285da4e618b618973cacf6565e61',
88
// },
9-
// amplitude: {
10-
// apiKey: 'c5c212632315d19c752ab083bc7c92ff',
11-
// },
12-
// logging: true,
9+
amplitude: {
10+
apiKey: '<AMPLITUDE_API_KEY>',
11+
},
12+
logging: true,
1313
datahub: {
1414
enabled: true,
1515
},

Diff for: metadata-service/configuration/src/main/java/com/linkedin/metadata/config/telemetry/TelemetryConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ public class TelemetryConfiguration {
2323
* Whether or not server telemetry should be enabled
2424
*/
2525
public boolean enabledServer;
26-
}
26+
27+
}

0 commit comments

Comments
 (0)