This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit dc7e2de7 authored by Johannes Kainz's avatar Johannes Kainz
Browse files

disabled the mapping of exercises to number of views, likes and downloads

parent 00ce69cf
Branches
Tags
2 merge requests!120Bringing monitoring to production,!100Monitoring
...@@ -52,10 +52,15 @@ public class MonitoringService { ...@@ -52,10 +52,15 @@ public class MonitoringService {
private final AtomicLong numberUsers; private final AtomicLong numberUsers;
private final AtomicLong numberActiveUsers; private final AtomicLong numberActiveUsers;
private final AtomicLong numberLikes;
private final AtomicLong numberViews;
private final AtomicLong numberDownloads;
private final Map<String, AtomicInteger> numberExercises; private final Map<String, AtomicInteger> numberExercises;
private final Map<String, AtomicLong> numberLikes;
private final Map<String, AtomicLong> numberViews; private final Map<String, AtomicLong> numberLikesMap;
private final Map<String, AtomicLong> numberDownloads; private final Map<String, AtomicLong> numberViewsMap;
private final Map<String, AtomicLong> numberDownloadsMap;
private final MeterRegistry meterRegistry; private final MeterRegistry meterRegistry;
...@@ -74,9 +79,9 @@ public class MonitoringService { ...@@ -74,9 +79,9 @@ public class MonitoringService {
this.statisticsService = statisticsService; this.statisticsService = statisticsService;
this.numberExercises = new HashMap<>(); this.numberExercises = new HashMap<>();
this.numberLikes = new HashMap<>(); this.numberLikesMap = new HashMap<>();
this.numberViews = new HashMap<>(); this.numberViewsMap = new HashMap<>();
this.numberDownloads = new HashMap<>(); this.numberDownloadsMap = new HashMap<>();
this.numberUsers = this.numberUsers =
meterRegistry.gauge( meterRegistry.gauge(
...@@ -101,6 +106,24 @@ public class MonitoringService { ...@@ -101,6 +106,24 @@ public class MonitoringService {
} catch (IOException exception) { } catch (IOException exception) {
log.warn("An IOException occurred when searching for all exercises\n" + Arrays.toString(exception.getStackTrace())); log.warn("An IOException occurred when searching for all exercises\n" + Arrays.toString(exception.getStackTrace()));
} }
this.numberLikes =
meterRegistry.gauge(
NUMBER_LIKE_NAME,
Tags.of(HOURLY_TAG),
new AtomicLong(this.numberLikesMap.values().stream().mapToLong(AtomicLong::get).sum())
);
this.numberViews =
meterRegistry.gauge(
NUMBER_VIEW_NAME,
Tags.of(HOURLY_TAG),
new AtomicLong(this.numberViewsMap.values().stream().mapToLong(AtomicLong::get).sum())
);
this.numberDownloads =
meterRegistry.gauge(
NUMBER_DOWNLOAD_NAME,
Tags.of(HOURLY_TAG),
new AtomicLong(this.numberDownloadsMap.values().stream().mapToLong(AtomicLong::get).sum())
);
} }
/** /**
...@@ -122,6 +145,8 @@ public class MonitoringService { ...@@ -122,6 +145,8 @@ public class MonitoringService {
} catch (IOException exception) { } catch (IOException exception) {
log.warn("An IOException occurred\n" + Arrays.toString(exception.getStackTrace())); log.warn("An IOException occurred\n" + Arrays.toString(exception.getStackTrace()));
} }
this.setExerciseStatistics();
log.debug("Finished monitoring cron job"); log.debug("Finished monitoring cron job");
} }
...@@ -141,17 +166,28 @@ public class MonitoringService { ...@@ -141,17 +166,28 @@ public class MonitoringService {
log.debug("set the exercise statistics for {}", exerciseIDs); log.debug("set the exercise statistics for {}", exerciseIDs);
exerciseIDs.forEach(exerciseID -> { exerciseIDs.forEach(exerciseID -> {
this.setNumberLikesForExerciseID(exerciseID); this.setNumberLikes(exerciseID);
final Optional<StatisticsDTO> statisticOptional = this.statisticsService.findOneByExerciseID(exerciseID); final Optional<StatisticsDTO> statisticOptional = this.statisticsService.findOneByExerciseID(exerciseID);
if (statisticOptional.isPresent()) { if (statisticOptional.isPresent()) {
StatisticsDTO statistic = statisticOptional.get(); StatisticsDTO statistic = statisticOptional.get();
this.setNumberViewsForExerciseID(exerciseID, statistic.getViews()); this.setNumberViews(exerciseID, statistic.getViews());
this.setNumberDownloadsForExerciseID(exerciseID, statistic.getDownloads()); this.setNumberDownloads(exerciseID, statistic.getDownloads());
} }
}); });
} }
/**
* Sets likes, views and downloads
*
*/
private void setExerciseStatistics() {
log.debug("set the exercise statistics");
this.numberLikes.set(this.numberLikesMap.values().stream().mapToLong(AtomicLong::get).sum());
this.numberViews.set(this.numberViewsMap.values().stream().mapToLong(AtomicLong::get).sum());
this.numberDownloads.set(this.numberDownloadsMap.values().stream().mapToLong(AtomicLong::get).sum());
}
/** /**
* Sets the given value as number of all exercises * Sets the given value as number of all exercises
* *
...@@ -226,20 +262,20 @@ public class MonitoringService { ...@@ -226,20 +262,20 @@ public class MonitoringService {
* *
* @param exerciseID given exercise ID * @param exerciseID given exercise ID
*/ */
private void setNumberLikesForExerciseID(String exerciseID) { private void setNumberLikes(String exerciseID) {
long numberLikes = this.likesService.findNumberOfLikesByExerciseID(exerciseID); long numberLikes = this.likesService.findNumberOfLikesByExerciseID(exerciseID);
if (!this.numberLikes.containsKey(exerciseID)) { if (!this.numberLikesMap.containsKey(exerciseID)) {
this.numberLikes.put( this.numberLikesMap.put(
exerciseID, exerciseID,
meterRegistry.gauge( //meterRegistry.gauge(
NUMBER_LIKE_NAME, // NUMBER_LIKE_NAME,
Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)), // Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)),
new AtomicLong(numberLikes) new AtomicLong(numberLikes)
) //)
); );
} else { } else {
this.numberLikes.get(exerciseID).set(numberLikes); this.numberLikesMap.get(exerciseID).set(numberLikes);
} }
} }
...@@ -249,14 +285,18 @@ public class MonitoringService { ...@@ -249,14 +285,18 @@ public class MonitoringService {
* @param exerciseID given exercise ID * @param exerciseID given exercise ID
* @param views given number of views * @param views given number of views
*/ */
private void setNumberViewsForExerciseID(String exerciseID, long views) { private void setNumberViews(String exerciseID, long views) {
if (!this.numberViews.containsKey(exerciseID)) { if (!this.numberViewsMap.containsKey(exerciseID)) {
this.numberViews.put( this.numberViewsMap.put(
exerciseID, exerciseID,
meterRegistry.gauge(NUMBER_VIEW_NAME, Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)), new AtomicLong(views)) //meterRegistry.gauge(
// NUMBER_VIEW_NAME,
// Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)),
new AtomicLong(views)
//)
); );
} else { } else {
this.numberViews.get(exerciseID).set(views); this.numberViewsMap.get(exerciseID).set(views);
} }
} }
...@@ -266,18 +306,18 @@ public class MonitoringService { ...@@ -266,18 +306,18 @@ public class MonitoringService {
* @param exerciseID given exercise ID * @param exerciseID given exercise ID
* @param downloads given number of downloads * @param downloads given number of downloads
*/ */
private void setNumberDownloadsForExerciseID(String exerciseID, long downloads) { private void setNumberDownloads(String exerciseID, long downloads) {
if (!this.numberDownloads.containsKey(exerciseID)) { if (!this.numberDownloadsMap.containsKey(exerciseID)) {
this.numberDownloads.put( this.numberDownloadsMap.put(
exerciseID, exerciseID,
meterRegistry.gauge( //meterRegistry.gauge(
NUMBER_DOWNLOAD_NAME, // NUMBER_DOWNLOAD_NAME,
Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)), // Tags.of(HOURLY_TAG, Tag.of(EXERCISE_TAG, exerciseID)),
new AtomicLong(downloads) new AtomicLong(downloads)
) //)
); );
} else { } else {
this.numberDownloads.get(exerciseID).set(downloads); this.numberDownloadsMap.get(exerciseID).set(downloads);
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment