From c54989612a1fcffeb38f9552218854da8b419138 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 14 Oct 2021 23:30:39 -0400 Subject: [PATCH 1/7] Added GA to dependencies and metrics to the `PatchRoue.java` --- pom.xml | 6 ++ .../org/broadinstitute/dsm/DSMServer.java | 16 +++- .../dsm/analytics/GoogleAnalyticsMetrics.java | 25 +++++ .../GoogleAnalyticsMetricsTracker.java | 94 +++++++++++++++++++ .../broadinstitute/dsm/route/PatchRoute.java | 32 ++++++- .../broadinstitute/dsm/statics/RoutePath.java | 4 + .../dsm/util/ElasticSearchUtil.java | 4 +- 7 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java create mode 100644 src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java diff --git a/pom.xml b/pom.xml index 8507e33ad..34b50313c 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,12 @@ com.google.cloud google-cloud-pubsub + + com.brsanthu + google-analytics-java + 2.0.0 + + org.javalite activejdbc diff --git a/src/main/java/org/broadinstitute/dsm/DSMServer.java b/src/main/java/org/broadinstitute/dsm/DSMServer.java index 9d195128f..10fe64162 100644 --- a/src/main/java/org/broadinstitute/dsm/DSMServer.java +++ b/src/main/java/org/broadinstitute/dsm/DSMServer.java @@ -31,6 +31,7 @@ import org.broadinstitute.ddp.util.BasicTriggerListener; import org.broadinstitute.ddp.util.JsonTransformer; import org.broadinstitute.ddp.util.Utility; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.careevolve.Provider; import org.broadinstitute.dsm.jetty.JettyConfig; import org.broadinstitute.dsm.jobs.*; @@ -167,7 +168,7 @@ protected void configureServer(@NonNull Config config) { logger.info("Using port {}", port); port(port); - registerAppEngineStartupCallback(bootTimeoutSeconds); + registerAppEngineStartupCallback(bootTimeoutSeconds, config); setupDB(config); @@ -834,14 +835,25 @@ public static boolean isTest(@NonNull String shipperName) { return true; } - private static void registerAppEngineStartupCallback(long bootTimeoutSeconds) { + private static void registerAppEngineStartupCallback(long bootTimeoutSeconds, Config cfg) { + GoogleAnalyticsMetricsTracker.setConfig(cfg); // Block until isReady is available, with an optional timeout to prevent // instance for sitting around too long in a nonresponsive state. There is a // judgement call to be made here to allow for lengthy liquibase migrations during boot. logger.info("Will wait for at most {} seconds for boot before GAE termination", bootTimeoutSeconds); get("/_ah/start", new ReadinessRoute(bootTimeoutSeconds)); + + get(RoutePath.GAE.STOP_ENDPOINT, (request, response) -> { + logger.info("Received GAE stop request [{}]", RoutePath.GAE.STOP_ENDPOINT); + //flush out any pending GA events + GoogleAnalyticsMetricsTracker.getInstance().flushOutMetrics(); + + response.status(HttpStatus.SC_OK); + return ""; + }); } + private static class ReadinessRoute implements Route { private final long bootTimeoutSeconds; diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java new file mode 100644 index 000000000..d6c2a25bb --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java @@ -0,0 +1,25 @@ +package org.broadinstitute.dsm.analytics; + +public class GoogleAnalyticsMetrics { + +// public static final String EVENT_CATEGORY_USER_REGISTRATION = "user-registration"; +// public static final String EVENT_ACTION_USER_REGISTRATION = "register-user"; +// public static final String EVENT_LABEL_USER_REGISTRATION = "registration"; we may need it for FON + + public static final String EVENT_CATEGORY_USER_LOGIN = "user-login"; + public static final String EVENT_ACTION_USER_LOGIN = "user-logged-in"; + public static final String EVENT_LABEL_USER_LOGIN = "login"; //studyGuid appended + + public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; + public static final String EVENT_ACTION_PARTICIPANT_LIST = "participant-list-loaded"; + public static final String EVENT_LABEL_PARTICIPANT_LIST = "participant-list-loaded";//studyGuid appended + + public static final String EVENT_CATEGORY_PATCH_DATA = "patch-data"; + public static final String EVENT_ACTION_PATCH_DATA = "patch-data-answers"; + public static final String EVENT_LABEL_PATCH_DATA = "patch-answers"; //studyGuid & original page appended + + public static final String EVENT_CATEGORY_TISSUE_LIST = "tissue-list"; + public static final String EVENT_ACTION_TISSUE_LIST = "tissue-list-loaded"; + public static final String EVENT_LABEL_TISSUE_LIST = "tissue-list-loaded";//studyGuid appended + +} diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java new file mode 100644 index 000000000..77b62f0b0 --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java @@ -0,0 +1,94 @@ +package org.broadinstitute.dsm.analytics; + +import com.brsanthu.googleanalytics.GoogleAnalytics; +import com.brsanthu.googleanalytics.GoogleAnalyticsConfig; +import com.brsanthu.googleanalytics.request.EventHit; +import com.typesafe.config.Config; +import lombok.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GoogleAnalyticsMetricsTracker { + private static final Logger LOG = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); + private static final Integer DEFAULT_BATCH_SIZE = 10; + private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId";//todo pegah add to SM + private static GoogleAnalytics studyAnalyticsTrackers; + private static volatile GoogleAnalyticsMetricsTracker instance; + private static Object lockGA = new Object(); + private static Config CONFIG; + + private GoogleAnalyticsMetricsTracker() { + initStudyMetricTracker(); + } + + public static void setConfig(@NonNull Config config){ + CONFIG = config; + } + + public static GoogleAnalyticsMetricsTracker getInstance() { + if (instance == null) { + synchronized (lockGA) { + if (instance == null) { + instance = new GoogleAnalyticsMetricsTracker(); + } + } + } + return instance; + } + + private GoogleAnalytics getMetricTracker() { + if (studyAnalyticsTrackers == null) { + + initStudyMetricTracker(); + } + return studyAnalyticsTrackers; + } + + private synchronized void initStudyMetricTracker() { + GoogleAnalytics metricTracker = GoogleAnalytics.builder() + .withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(DEFAULT_BATCH_SIZE)) + .withTrackingId(getAnalyticsToken(CONFIG)) + .build(); + studyAnalyticsTrackers = metricTracker; + LOG.info("Initialized GA Metrics Tracker for DSM "); + } + + + private void sendEventMetrics(EventHit eventHit) { + GoogleAnalytics metricTracker = getMetricTracker(); + if (metricTracker != null) { + metricTracker.event().eventCategory(eventHit.eventCategory()) + .eventAction(eventHit.eventAction()) + .eventLabel(eventHit.eventLabel()) + .eventValue(eventHit.eventValue()) + .sendAsync(); + } + } + + public void sendAnalyticsMetrics(String studyGuid, String category, String action, String label, + String labelContent, int value) { + String gaEventLabel = String.join(":", label, + studyGuid); + if (labelContent != null) { + gaEventLabel = String.join(":", gaEventLabel, labelContent); + } + EventHit eventHit = new EventHit(category, action, gaEventLabel, value); + sendEventMetrics(eventHit); + } + + public void flushOutMetrics() { + //lookup all Metrics Trackers and flush out any pending events + LOG.info("Flushing out all pending GA events"); + studyAnalyticsTrackers.flush(); + } + + public String getAnalyticsToken(@NonNull Config config) { + //todo pegah add to conf and read from there + if (config.hasPath(GA_TOKEN_PATH)) { + return config.getString(GA_TOKEN_PATH); + } + throw new RuntimeException("There is no secret in the SM for the Google Analytics"); + } + + +} diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index dbd54fba0..4a7781586 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -7,6 +7,8 @@ import lombok.NonNull; import org.apache.commons.lang3.StringUtils; import org.broadinstitute.ddp.handlers.util.Result; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.db.*; import org.broadinstitute.dsm.db.dao.ddp.participant.ParticipantDao; import org.broadinstitute.dsm.db.dao.ddp.participant.ParticipantDataDao; @@ -42,6 +44,7 @@ import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; + import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; //Class needs to be refactored as soon as possible!!! @@ -132,9 +135,13 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } } else { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); throw new RuntimeException("DBElement not found in ColumnNameMap: " + nameValue.getName()); } } + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(nameValues)); } else { @@ -145,10 +152,14 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { List nameValues = setWorkflowRelatedFields(patch); writeDSMRecordsToES(patch, ddpInstance); //return nameValues with nulls + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(nameValues)); } } else { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); throw new RuntimeException("DBElement not found in ColumnNameMap: " + patch.getNameValue().getName()); } } @@ -177,6 +188,8 @@ else if (StringUtils.isNotBlank(patch.getParent()) && StringUtils.isNotBlank(pat Map map = new HashMap<>(); map.put(PRIMARY_KEY_ID, primaryKeyId); //return map with nulls + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(map)); } else { @@ -244,6 +257,8 @@ else if (StringUtils.isNotBlank(patch.getParent()) && StringUtils.isNotBlank(pat map.put("oncHistoryDetailId", oncHistoryDetailId); nameValues.add(new NameValue("request", OncHistoryDetail.STATUS_REVIEW)); map.put(NAME_VALUE, gson.toJson(nameValues)); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null,GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); //return map with nulls return new Result(200, gson.toJson(map)); } @@ -262,11 +277,10 @@ else if (Patch.ONC_HISTORY_ID.equals(patch.getParent())) { map.put("tissueId", tissueId); if (!nameValues.isEmpty()) { map.put(NAME_VALUE, gson.toJson(nameValues)); - return new Result(200, gson.toJson(map)); } - else { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(map)); - } } } else { @@ -301,6 +315,8 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } } } + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(map)); } else if (Patch.DDP_PARTICIPANT_ID.equals(patch.getParent())) { @@ -314,20 +330,30 @@ else if (Patch.DDP_PARTICIPANT_ID.equals(patch.getParent())) { throw new RuntimeException("DBElement not found in ColumnNameMap: " + patch.getNameValue().getName()); } Patch.patch(String.valueOf(participantId), patch.getUser(), patch.getNameValue(), dbElement); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(200, gson.toJson(Map.of(PARTICIPANT_ID, String.valueOf(participantId)))); } } } + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); throw new RuntimeException("Id and parentId was null"); } catch (DuplicateException e) { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); return new Result(500, "Duplicate value"); } catch (Exception e) { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); throw new RuntimeException("An error occurred while attempting to patch ", e); } } else { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); response.status(500); return new Result(500, UserErrorMessages.NO_RIGHTS); } diff --git a/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java b/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java index 2e9afd15e..5e93291c9 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java +++ b/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java @@ -10,6 +10,10 @@ public enum RequestMethod { GET, PATCH, POST, PUT } + public static final class GAE { + public static final String STOP_ENDPOINT = "/_ah/stop"; + } + public static final String REALM = "realm"; public static final String KIT_TYPE = "kitType"; public static final String UPLOAD_REASONS = "uploadReasons"; diff --git a/src/main/java/org/broadinstitute/dsm/util/ElasticSearchUtil.java b/src/main/java/org/broadinstitute/dsm/util/ElasticSearchUtil.java index ee2798cc8..87cdb28b3 100644 --- a/src/main/java/org/broadinstitute/dsm/util/ElasticSearchUtil.java +++ b/src/main/java/org/broadinstitute/dsm/util/ElasticSearchUtil.java @@ -116,8 +116,8 @@ public class ElasticSearchUtil { private static Map fieldMappings; static { - initClient(); - fetchFieldMappings(); + initClient(); + fetchFieldMappings(); } public static synchronized void initClient() { From 35805e76b988e0ad635fa96b5d73bbc433eb3e90 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 28 Oct 2021 11:36:38 -0400 Subject: [PATCH 2/7] added gender from onc history removed sample type from liquibase and hard coded it --- .../dsm/analytics/GoogleAnalyticsMetricsTracker.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java index 77b62f0b0..f024067ce 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java @@ -83,7 +83,6 @@ public void flushOutMetrics() { } public String getAnalyticsToken(@NonNull Config config) { - //todo pegah add to conf and read from there if (config.hasPath(GA_TOKEN_PATH)) { return config.getString(GA_TOKEN_PATH); } From f49d86deb92b37221b33f608b337661c45ebe531 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 2 Nov 2021 09:12:55 -0400 Subject: [PATCH 3/7] added GoogleAnalyticsMetricsTracker and GoogleAnalyticsMetrics for special events we want to track --- .../GoogleAnalyticsMetricsTracker.java | 28 +++++++++++-------- .../broadinstitute/dsm/route/FilterRoute.java | 4 +++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java index f024067ce..8a7f54cb2 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java @@ -3,16 +3,17 @@ import com.brsanthu.googleanalytics.GoogleAnalytics; import com.brsanthu.googleanalytics.GoogleAnalyticsConfig; import com.brsanthu.googleanalytics.request.EventHit; +import com.brsanthu.googleanalytics.request.GoogleAnalyticsResponse; import com.typesafe.config.Config; import lombok.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class GoogleAnalyticsMetricsTracker { - private static final Logger LOG = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); + private static final Logger logger = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); private static final Integer DEFAULT_BATCH_SIZE = 10; private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId";//todo pegah add to SM - private static GoogleAnalytics studyAnalyticsTrackers; + private static GoogleAnalytics googleAnalyticsTrackers; private static volatile GoogleAnalyticsMetricsTracker instance; private static Object lockGA = new Object(); private static Config CONFIG; @@ -37,31 +38,34 @@ public static GoogleAnalyticsMetricsTracker getInstance() { } private GoogleAnalytics getMetricTracker() { - if (studyAnalyticsTrackers == null) { + if (googleAnalyticsTrackers == null) { initStudyMetricTracker(); } - return studyAnalyticsTrackers; + return googleAnalyticsTrackers; } private synchronized void initStudyMetricTracker() { GoogleAnalytics metricTracker = GoogleAnalytics.builder() - .withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(DEFAULT_BATCH_SIZE)) + .withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(DEFAULT_BATCH_SIZE).setGatherStats(true)) .withTrackingId(getAnalyticsToken(CONFIG)) .build(); - studyAnalyticsTrackers = metricTracker; - LOG.info("Initialized GA Metrics Tracker for DSM "); + googleAnalyticsTrackers = metricTracker; + logger.info("Initialized GA Metrics Tracker for DSM "); } private void sendEventMetrics(EventHit eventHit) { GoogleAnalytics metricTracker = getMetricTracker(); if (metricTracker != null) { - metricTracker.event().eventCategory(eventHit.eventCategory()) + GoogleAnalyticsResponse response = metricTracker.event().eventCategory(eventHit.eventCategory()) .eventAction(eventHit.eventAction()) .eventLabel(eventHit.eventLabel()) .eventValue(eventHit.eventValue()) - .sendAsync(); + .send(); + logger.info(response.getStatusCode()+""); + logger.info(metricTracker.getStats().getEventHits()+""); + } } @@ -74,12 +78,14 @@ public void sendAnalyticsMetrics(String studyGuid, String category, String actio } EventHit eventHit = new EventHit(category, action, gaEventLabel, value); sendEventMetrics(eventHit); + } public void flushOutMetrics() { //lookup all Metrics Trackers and flush out any pending events - LOG.info("Flushing out all pending GA events"); - studyAnalyticsTrackers.flush(); + logger.info("Flushing out all pending GA events"); + googleAnalyticsTrackers.flush(); + googleAnalyticsTrackers.resetStats(); } public String getAnalyticsToken(@NonNull Config config) { diff --git a/src/main/java/org/broadinstitute/dsm/route/FilterRoute.java b/src/main/java/org/broadinstitute/dsm/route/FilterRoute.java index c954f51c2..67e8bcd6b 100644 --- a/src/main/java/org/broadinstitute/dsm/route/FilterRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/FilterRoute.java @@ -1,6 +1,8 @@ package org.broadinstitute.dsm.route; import org.apache.commons.lang3.StringUtils; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.model.filter.FilterFactory; import org.broadinstitute.dsm.model.filter.Filterable; import org.broadinstitute.dsm.security.RequestHandler; @@ -16,6 +18,8 @@ public class FilterRoute extends RequestHandler { @Override public Object processRequest(Request request, Response response, String userId) throws Exception { + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics("", GoogleAnalyticsMetrics.EVENT_CATEGORY_PARTICIPANT_LIST, + GoogleAnalyticsMetrics.EVENT_ACTION_PARTICIPANT_LIST, GoogleAnalyticsMetrics.EVENT_LABEL_PARTICIPANT_LIST, "Filter", 1); QueryParamsMap queryParams = request.queryMap(); String parent = queryParams.get(DBConstants.FILTER_PARENT).value(); if (StringUtils.isBlank(parent)) throw new IllegalArgumentException("parent cannot be empty"); From 85a72ca0f48baf7f052edf4ae89c4575f02a1c85 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 2 Nov 2021 21:39:02 -0400 Subject: [PATCH 4/7] added more loggings --- .../dsm/analytics/GoogleAnalyticsMetrics.java | 2 +- .../GoogleAnalyticsMetricsTracker.java | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java index d6c2a25bb..5a098053c 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java @@ -10,7 +10,7 @@ public class GoogleAnalyticsMetrics { public static final String EVENT_ACTION_USER_LOGIN = "user-logged-in"; public static final String EVENT_LABEL_USER_LOGIN = "login"; //studyGuid appended - public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; + public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; public static final String EVENT_ACTION_PARTICIPANT_LIST = "participant-list-loaded"; public static final String EVENT_LABEL_PARTICIPANT_LIST = "participant-list-loaded";//studyGuid appended diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java index 8a7f54cb2..fc9bcae2a 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java @@ -11,8 +11,8 @@ public class GoogleAnalyticsMetricsTracker { private static final Logger logger = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); - private static final Integer DEFAULT_BATCH_SIZE = 10; - private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId";//todo pegah add to SM + private static final Integer DEFAULT_BATCH_SIZE = 1; + private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId"; private static GoogleAnalytics googleAnalyticsTrackers; private static volatile GoogleAnalyticsMetricsTracker instance; private static Object lockGA = new Object(); @@ -62,7 +62,10 @@ private void sendEventMetrics(EventHit eventHit) { .eventAction(eventHit.eventAction()) .eventLabel(eventHit.eventLabel()) .eventValue(eventHit.eventValue()) + .trackingId(getAnalyticsToken(CONFIG)) .send(); + + logger.info(response.toString()); logger.info(response.getStatusCode()+""); logger.info(metricTracker.getStats().getEventHits()+""); @@ -71,12 +74,13 @@ private void sendEventMetrics(EventHit eventHit) { public void sendAnalyticsMetrics(String studyGuid, String category, String action, String label, String labelContent, int value) { - String gaEventLabel = String.join(":", label, - studyGuid); - if (labelContent != null) { - gaEventLabel = String.join(":", gaEventLabel, labelContent); - } - EventHit eventHit = new EventHit(category, action, gaEventLabel, value); +// String gaEventLabel = String.join(":", label, +// studyGuid); +// if (labelContent != null) { +// gaEventLabel = String.join(":", gaEventLabel, labelContent); +// } + EventHit eventHit = new EventHit(category, action, label, value); + logger.info(eventHit.toString()); sendEventMetrics(eventHit); } From 03751e35555247b4c9528b7795ad9b9849a52fc2 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Fri, 5 Nov 2021 00:16:32 -0400 Subject: [PATCH 5/7] fixed the event sending by adding users added unit test added events --- .../org/broadinstitute/dsm/DSMServer.java | 3 ++ .../dsm/analytics/GoogleAnalyticsMetrics.java | 8 +++- .../GoogleAnalyticsMetricsTracker.java | 15 +++---- .../BaseFilterParticipantList.java | 23 ++++++---- .../broadinstitute/dsm/route/FilterRoute.java | 4 -- .../broadinstitute/dsm/DirectMethodTest.java | 42 ++++++++++++++++++- 6 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/DSMServer.java b/src/main/java/org/broadinstitute/dsm/DSMServer.java index 10fe64162..f403260d4 100644 --- a/src/main/java/org/broadinstitute/dsm/DSMServer.java +++ b/src/main/java/org/broadinstitute/dsm/DSMServer.java @@ -31,6 +31,7 @@ import org.broadinstitute.ddp.util.BasicTriggerListener; import org.broadinstitute.ddp.util.JsonTransformer; import org.broadinstitute.ddp.util.Utility; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.careevolve.Provider; import org.broadinstitute.dsm.jetty.JettyConfig; @@ -174,6 +175,8 @@ protected void configureServer(@NonNull Config config) { // don't run superclass routing--it won't work with JettyConfig changes for capturing proper IP address in GAE setupCustomRouting(config); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics("", GoogleAnalyticsMetrics.EVENT_CATEGORY_SERVER_START, + GoogleAnalyticsMetrics.EVENT_ACTION_SERVER_START, GoogleAnalyticsMetrics.EVENT_LABEL_SERVER_START, 1 ); List allowedOrigins = config.getStringList(ApplicationConfigConstants.CORS_ALLOWED_ORIGINS); enableCORS(StringUtils.join(allowedOrigins, ","), String.join(",", CORS_HTTP_METHODS), String.join(",", CORS_HTTP_HEADERS)); diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java index 5a098053c..7fa466be6 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java @@ -11,8 +11,12 @@ public class GoogleAnalyticsMetrics { public static final String EVENT_LABEL_USER_LOGIN = "login"; //studyGuid appended public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; - public static final String EVENT_ACTION_PARTICIPANT_LIST = "participant-list-loaded"; - public static final String EVENT_LABEL_PARTICIPANT_LIST = "participant-list-loaded";//studyGuid appended + public static final String EVENT_ACTION_PARTICIPANT_LIST = "participant-list-load-time"; + public static final String EVENT_LABEL_PARTICIPANT_LIST = "participant-list-load-time";//studyGuid appended + + public static final String EVENT_CATEGORY_SERVER_START= "server-start"; + public static final String EVENT_ACTION_SERVER_START = "server-start"; + public static final String EVENT_LABEL_SERVER_START = "server-start"; public static final String EVENT_CATEGORY_PATCH_DATA = "patch-data"; public static final String EVENT_ACTION_PATCH_DATA = "patch-data-answers"; diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java index fc9bcae2a..5be5e14a1 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java @@ -11,7 +11,6 @@ public class GoogleAnalyticsMetricsTracker { private static final Logger logger = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); - private static final Integer DEFAULT_BATCH_SIZE = 1; private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId"; private static GoogleAnalytics googleAnalyticsTrackers; private static volatile GoogleAnalyticsMetricsTracker instance; @@ -47,7 +46,7 @@ private GoogleAnalytics getMetricTracker() { private synchronized void initStudyMetricTracker() { GoogleAnalytics metricTracker = GoogleAnalytics.builder() - .withConfig(new GoogleAnalyticsConfig().setBatchingEnabled(true).setBatchSize(DEFAULT_BATCH_SIZE).setGatherStats(true)) + .withConfig(new GoogleAnalyticsConfig().setGatherStats(true).setUserAgent("Custom User Agent")) .withTrackingId(getAnalyticsToken(CONFIG)) .build(); googleAnalyticsTrackers = metricTracker; @@ -72,14 +71,10 @@ private void sendEventMetrics(EventHit eventHit) { } } - public void sendAnalyticsMetrics(String studyGuid, String category, String action, String label, - String labelContent, int value) { -// String gaEventLabel = String.join(":", label, -// studyGuid); -// if (labelContent != null) { -// gaEventLabel = String.join(":", gaEventLabel, labelContent); -// } - EventHit eventHit = new EventHit(category, action, label, value); + public void sendAnalyticsMetrics(String studyGuid, String category, String action, String label, int value) { + String gaEventLabel = String.join(":", label, + studyGuid); + EventHit eventHit = new EventHit(category, action, gaEventLabel, value); logger.info(eventHit.toString()); sendEventMetrics(eventHit); diff --git a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java index ba5c6110d..7f3330016 100644 --- a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java +++ b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java @@ -1,15 +1,11 @@ package org.broadinstitute.dsm.model.filter.participant; -import java.time.LocalDate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - import com.google.gson.Gson; import lombok.NonNull; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.db.DDPInstance; import org.broadinstitute.dsm.db.ViewFilter; import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao; @@ -19,10 +15,9 @@ import org.broadinstitute.dsm.db.structure.DBElement; import org.broadinstitute.dsm.model.Filter; import org.broadinstitute.dsm.model.elasticsearch.ElasticSearch; -import org.broadinstitute.dsm.model.participant.ParticipantWrapper; import org.broadinstitute.dsm.model.filter.BaseFilter; import org.broadinstitute.dsm.model.filter.Filterable; -import org.broadinstitute.dsm.model.participant.ParticipantWrapperDto; +import org.broadinstitute.dsm.model.participant.ParticipantWrapper; import org.broadinstitute.dsm.model.participant.ParticipantWrapperPayload; import org.broadinstitute.dsm.model.participant.ParticipantWrapperResult; import org.broadinstitute.dsm.statics.DBConstants; @@ -31,6 +26,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + public abstract class BaseFilterParticipantList extends BaseFilter implements Filterable { private static final Logger logger = LoggerFactory.getLogger(BaseFilterParticipantList.class); @@ -57,6 +58,7 @@ public BaseFilterParticipantList(String jsonBody) { protected ParticipantWrapperResult filterParticipantList(Filter[] filters, Map columnNameMap, @NonNull DDPInstance instance) { + Long timer = System.currentTimeMillis(); Map queryConditions = new HashMap<>(); List allParticipantData = null; DDPInstanceDto ddpInstanceDto = new DDPInstanceDao().getDDPInstanceByInstanceName(realm).orElseThrow(); @@ -119,9 +121,12 @@ protected ParticipantWrapperResult filterParticipantList(Filter[] filters, Map Date: Fri, 5 Nov 2021 16:05:08 -0400 Subject: [PATCH 6/7] fiixed events in PatchRoute.java --- .../broadinstitute/dsm/route/PatchRoute.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index 4a7781586..2809a0898 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -136,12 +136,12 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } else { GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); throw new RuntimeException("DBElement not found in ColumnNameMap: " + nameValue.getName()); } } GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(nameValues)); } else { @@ -153,13 +153,13 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { writeDSMRecordsToES(patch, ddpInstance); //return nameValues with nulls GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(nameValues)); } } else { GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); throw new RuntimeException("DBElement not found in ColumnNameMap: " + patch.getNameValue().getName()); } } @@ -189,7 +189,7 @@ else if (StringUtils.isNotBlank(patch.getParent()) && StringUtils.isNotBlank(pat map.put(PRIMARY_KEY_ID, primaryKeyId); //return map with nulls GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(map)); } else { @@ -258,7 +258,7 @@ else if (StringUtils.isNotBlank(patch.getParent()) && StringUtils.isNotBlank(pat nameValues.add(new NameValue("request", OncHistoryDetail.STATUS_REVIEW)); map.put(NAME_VALUE, gson.toJson(nameValues)); GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null,GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); //return map with nulls return new Result(200, gson.toJson(map)); } @@ -279,7 +279,7 @@ else if (Patch.ONC_HISTORY_ID.equals(patch.getParent())) { map.put(NAME_VALUE, gson.toJson(nameValues)); } GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(map)); } } @@ -316,7 +316,7 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } } GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(map)); } else if (Patch.DDP_PARTICIPANT_ID.equals(patch.getParent())) { @@ -331,29 +331,29 @@ else if (Patch.DDP_PARTICIPANT_ID.equals(patch.getParent())) { } Patch.patch(String.valueOf(participantId), patch.getUser(), patch.getNameValue(), dbElement); GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(200, gson.toJson(Map.of(PARTICIPANT_ID, String.valueOf(participantId)))); } } } GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); throw new RuntimeException("Id and parentId was null"); } catch (DuplicateException e) { GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); return new Result(500, "Duplicate value"); } catch (Exception e) { GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); throw new RuntimeException("An error occurred while attempting to patch ", e); } } else { GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(null, GoogleAnalyticsMetrics.EVENT_CATEGORY_PATCH_DATA, - GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, null, 1); + GoogleAnalyticsMetrics.EVENT_ACTION_PATCH_DATA, GoogleAnalyticsMetrics.EVENT_LABEL_PATCH_DATA, 1); response.status(500); return new Result(500, UserErrorMessages.NO_RIGHTS); } From 723550b0f42efac14363e38dbf76ba852d87331b Mon Sep 17 00:00:00 2001 From: pegahtah Date: Fri, 5 Nov 2021 16:14:27 -0400 Subject: [PATCH 7/7] added events in participant and tissue list. --- .../filter/tissue/ManualFilterTissueList.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java b/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java index 4ab5b0b4b..3862b0212 100644 --- a/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java @@ -1,11 +1,8 @@ package org.broadinstitute.dsm.model.filter.tissue; -import java.util.ArrayList; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Objects; - import org.apache.commons.lang3.StringUtils; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.db.DDPInstance; import org.broadinstitute.dsm.db.ViewFilter; import org.broadinstitute.dsm.model.TissueList; @@ -17,6 +14,11 @@ import org.slf4j.LoggerFactory; import spark.QueryParamsMap; +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; + //reloadWithDefault/Manual/Empty filtering public class ManualFilterTissueList extends BaseFilterTissueList { @@ -28,6 +30,7 @@ public ManualFilterTissueList(String jsonBody) { @Override public List filter(QueryParamsMap queryParamsMap) { + Long timer = System.currentTimeMillis(); List wrapperList = new ArrayList<>(); if (Objects.isNull(queryParamsMap)) return wrapperList; prepareNeccesaryData(queryParamsMap); @@ -52,6 +55,8 @@ public List filter(QueryParamsMap queryParamsMap) { wrapperList = filterTissueList(filters, PatchUtil.getColumnNameMap(), quickFilterName, ddpInstance, filterQuery); } logger.info("Found " + wrapperList.size() + " tissues for Tissue View"); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_TISSUE_LIST, + GoogleAnalyticsMetrics.EVENT_ACTION_TISSUE_LIST, GoogleAnalyticsMetrics.EVENT_LABEL_TISSUE_LIST, Math.toIntExact((System.currentTimeMillis() - timer)/1000)); return wrapperList; } }