Skip to content

Commit df6f95a

Browse files
committed
Add more fields to Bard logging
1 parent 93f996f commit df6f95a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/main/java/bio/terra/app/usermetrics/BardEventProperties.java

+5
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ private BardEventProperties() {}
66
public static final String BILLING_PROFILE_ID_FIELD_NAME = "billingProfileId";
77
public static final String METHOD_FIELD_NAME = "method";
88
public static final String PATH_FIELD_NAME = "path";
9+
public static final String SNAPSHOT_ID_FIELD_NAME = "snapshotId";
910
public static final String SNAPSHOT_NAME_FIELD_NAME = "snapshotName";
11+
12+
public static final String DATASET_ID_FIELD_NAME = "datasetId";
13+
public static final String DATASET_NAME_FIELD_NAME = "datasetName";
14+
public static final String CLOUD_PLATFORM_FIELD_NAME = "cloudPlatform";
1015
}

src/main/java/bio/terra/app/usermetrics/UserLoggingMetrics.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bio.terra.app.usermetrics;
22

33
import java.util.HashMap;
4+
import org.apache.arrow.util.VisibleForTesting;
45
import org.springframework.stereotype.Component;
56

67
/**
@@ -45,4 +46,9 @@ public void setAll(HashMap<String, Object> value) {
4546
properties.putAll(value);
4647
metrics.set(properties);
4748
}
49+
50+
@VisibleForTesting
51+
public void reset() {
52+
metrics.get().clear();
53+
}
4854
}

src/main/java/bio/terra/service/filedata/DrsService.java

+22
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,16 @@ private DRSAccessURL getAccessURL(
491491

492492
BillingProfileModel billingProfileModel = cachedSnapshot.datasetBillingProfileModel;
493493

494+
loggingMetrics.set(BardEventProperties.DATASET_ID_FIELD_NAME, cachedSnapshot.getDatasetId());
495+
loggingMetrics.set(
496+
BardEventProperties.DATASET_NAME_FIELD_NAME, cachedSnapshot.getDatasetName());
497+
loggingMetrics.set(BardEventProperties.SNAPSHOT_ID_FIELD_NAME, snapshotId);
494498
loggingMetrics.set(BardEventProperties.SNAPSHOT_NAME_FIELD_NAME, cachedSnapshot.getName());
495499
loggingMetrics.set(
496500
BardEventProperties.BILLING_PROFILE_ID_FIELD_NAME,
497501
cachedSnapshot.getSnapshotBillingProfileId());
502+
loggingMetrics.set(
503+
BardEventProperties.CLOUD_PLATFORM_FIELD_NAME, cachedSnapshot.getCloudPlatform());
498504

499505
assertAccessMethodMatchingAccessId(accessId, drsObject);
500506

@@ -1002,6 +1008,8 @@ static class SnapshotCacheResult {
10021008
private final CloudPlatform cloudPlatform;
10031009
private final String googleProjectId;
10041010
private final String datasetProjectId;
1011+
private final UUID datasetId;
1012+
private final String datasetName;
10051013
private final boolean globalFileIds;
10061014

10071015
public SnapshotCacheResult(Snapshot snapshot) {
@@ -1025,6 +1033,8 @@ public SnapshotCacheResult(Snapshot snapshot) {
10251033
} else {
10261034
this.datasetProjectId = null;
10271035
}
1036+
this.datasetId = snapshot.getSourceDataset().getId();
1037+
this.datasetName = snapshot.getSourceDataset().getName();
10281038
}
10291039

10301040
public UUID getId() {
@@ -1035,8 +1045,20 @@ public String getName() {
10351045
return this.name;
10361046
}
10371047

1048+
public UUID getDatasetId() {
1049+
return this.datasetId;
1050+
}
1051+
1052+
public String getDatasetName() {
1053+
return this.datasetName;
1054+
}
1055+
10381056
public UUID getSnapshotBillingProfileId() {
10391057
return snapshotBillingProfileId;
10401058
}
1059+
1060+
public CloudPlatform getCloudPlatform() {
1061+
return this.cloudPlatform;
1062+
}
10411063
}
10421064
}

src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import bio.terra.common.fixtures.AuthenticationFixtures;
1616
import bio.terra.common.iam.AuthenticatedUserRequest;
1717
import bio.terra.common.iam.AuthenticatedUserRequestFactory;
18+
import bio.terra.model.CloudPlatform;
1819
import jakarta.servlet.http.HttpServletRequest;
1920
import jakarta.servlet.http.HttpServletResponse;
2021
import java.util.List;
@@ -69,6 +70,7 @@ class UserMetricsInterceptorTest {
6970

7071
@BeforeEach
7172
void setUp() {
73+
eventProperties.reset();
7274
when(metricsConfig.ignorePaths()).thenReturn(List.of());
7375
when(metricsConfig.appId()).thenReturn(APP_ID);
7476
when(metricsConfig.bardBasePath()).thenReturn(BARD_BASE_PATH);
@@ -126,10 +128,19 @@ void testSendEvent() throws Exception {
126128

127129
@Test
128130
void testSendEventWithAdditionalProperties() throws Exception {
131+
UUID datasetId = UUID.randomUUID();
132+
String datasetName = "datasetName";
133+
UUID snapshotId = UUID.randomUUID();
129134
String snapshotName = "snapshotName";
130135
String billingProfileId = UUID.randomUUID().toString();
131-
eventProperties.set(BardEventProperties.BILLING_PROFILE_ID_FIELD_NAME, billingProfileId);
136+
CloudPlatform cloudPlatform = CloudPlatform.GCP;
137+
138+
eventProperties.set(BardEventProperties.DATASET_ID_FIELD_NAME, datasetId);
139+
eventProperties.set(BardEventProperties.DATASET_NAME_FIELD_NAME, datasetName);
140+
eventProperties.set(BardEventProperties.SNAPSHOT_ID_FIELD_NAME, snapshotId);
132141
eventProperties.set(BardEventProperties.SNAPSHOT_NAME_FIELD_NAME, snapshotName);
142+
eventProperties.set(BardEventProperties.BILLING_PROFILE_ID_FIELD_NAME, billingProfileId);
143+
eventProperties.set(BardEventProperties.CLOUD_PLATFORM_FIELD_NAME, cloudPlatform);
133144

134145
mockRequestAuth(request);
135146

@@ -144,8 +155,12 @@ void testSendEventWithAdditionalProperties() throws Exception {
144155
Map.of(
145156
BardEventProperties.METHOD_FIELD_NAME, METHOD.toUpperCase(),
146157
BardEventProperties.PATH_FIELD_NAME, REQUEST_URI,
158+
BardEventProperties.DATASET_ID_FIELD_NAME, datasetId,
159+
BardEventProperties.DATASET_NAME_FIELD_NAME, datasetName,
160+
BardEventProperties.SNAPSHOT_ID_FIELD_NAME, snapshotId,
161+
BardEventProperties.SNAPSHOT_NAME_FIELD_NAME, snapshotName,
147162
BardEventProperties.BILLING_PROFILE_ID_FIELD_NAME, billingProfileId,
148-
BardEventProperties.SNAPSHOT_NAME_FIELD_NAME, snapshotName),
163+
BardEventProperties.CLOUD_PLATFORM_FIELD_NAME, cloudPlatform),
149164
APP_ID,
150165
DNS_NAME)));
151166

0 commit comments

Comments
 (0)