diff --git a/src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java b/src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java index 31a23f52c6e6..60165060ca72 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java +++ b/src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java @@ -61,8 +61,9 @@ public class MetricsBean { /** * Some metrics (e.g. the number of upcoming exercises) are calculated for multiple lookahead periods. * Each period/range is exposed as metrics with a according tag "range" + * NOTE: we reduced the intervals temporarily until more intervals are necessary */ - private static final int[] MINUTE_RANGES_LOOKAHEAD = { 15, 30, 45, 60, 120 }; + private static final int[] MINUTE_RANGES_LOOKAHEAD = { 15 }; private final MeterRegistry meterRegistry; @@ -210,9 +211,6 @@ private void registerWebsocketMetrics() { // Publish the number of currently (via WebSockets) connected sessions Gauge.builder("artemis.instance.websocket.sessions", webSocketHandler, MetricsBean::extractWebsocketSessionCount).strongReference(true) .description("Number of sessions connected to this Artemis instance").register(meterRegistry); - // TODO: DEPRECATED metric with same value - Should be removed after October 2023 - Gauge.builder("artemis.instance.websocket.users", webSocketHandler, MetricsBean::extractWebsocketSessionCount).strongReference(true) - .description("Number of sessions connected to this Artemis instance").register(meterRegistry); // Publish the number of currently (via WebSockets) connected users Gauge.builder("artemis.global.websocket.users", userRegistry, MetricsBean::extractWebsocketUserCount).strongReference(true) diff --git a/src/test/java/de/tum/in/www1/artemis/config/MetricsBeanTest.java b/src/test/java/de/tum/in/www1/artemis/config/MetricsBeanTest.java index f4074f1ad64b..3c1b6889dd04 100644 --- a/src/test/java/de/tum/in/www1/artemis/config/MetricsBeanTest.java +++ b/src/test/java/de/tum/in/www1/artemis/config/MetricsBeanTest.java @@ -331,11 +331,11 @@ void testPrometheusMetricsExercises() { course1.setStudentGroupName(TEST_PREFIX + "course1students"); course1.addExercises(exerciseRepository - .save(QuizExerciseFactory.generateQuizExercise(ZonedDateTime.now().plusMinutes(25), ZonedDateTime.now().plusMinutes(55), QuizMode.SYNCHRONIZED, course1))); - course1.addExercises( - exerciseRepository.save(QuizExerciseFactory.generateQuizExercise(ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(3), QuizMode.SYNCHRONIZED, course1))); + .save(QuizExerciseFactory.generateQuizExercise(ZonedDateTime.now().plusMinutes(5), ZonedDateTime.now().plusMinutes(55), QuizMode.SYNCHRONIZED, course1))); course1.addExercises(exerciseRepository - .save(textExerciseUtilService.createIndividualTextExercise(course1, ZonedDateTime.now().plusMinutes(1), ZonedDateTime.now().plusMinutes(25), null))); + .save(QuizExerciseFactory.generateQuizExercise(ZonedDateTime.now().plusMinutes(1), ZonedDateTime.now().plusMinutes(3), QuizMode.SYNCHRONIZED, course1))); + course1.addExercises(exerciseRepository + .save(textExerciseUtilService.createIndividualTextExercise(course1, ZonedDateTime.now().plusMinutes(1), ZonedDateTime.now().plusMinutes(12), null))); courseRepository.save(course1); metricsBean.recalculateMetrics(); @@ -356,12 +356,9 @@ void testPrometheusMetricsExercises() { // Should now have one active user assertMetricEquals(1, "artemis.scheduled.exercises.due.student_multiplier.active.14", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); - // Only one quiz is released within the next 30 minutes - assertMetricEquals(1, "artemis.scheduled.exercises.release.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "30"); - assertMetricEquals(3 * 1, "artemis.scheduled.exercises.release.student_multiplier", "exerciseType", ExerciseType.QUIZ.toString(), "range", "30"); - - // Only one active user - assertMetricEquals(1, "artemis.scheduled.exercises.release.student_multiplier.active.14", "exerciseType", ExerciseType.QUIZ.toString(), "range", "30"); + // Two quizzes are released within the next 15 minutes, but have the same users (-> Users are only counted once) + assertMetricEquals(2, "artemis.scheduled.exercises.release.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); + assertMetricEquals(3 * 1, "artemis.scheduled.exercises.release.student_multiplier", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); // Add activity to another user quizExerciseUtilService.saveQuizSubmission(exerciseUtilService.getFirstExerciseWithType(course1, QuizExercise.class), ParticipationFactory.generateQuizSubmission(true), @@ -370,11 +367,7 @@ void testPrometheusMetricsExercises() { metricsBean.recalculateMetrics(); // Should now have two active users - assertMetricEquals(2, "artemis.scheduled.exercises.release.student_multiplier.active.14", "exerciseType", ExerciseType.QUIZ.toString(), "range", "30"); - - // Both quizzes end within the next 120 minutes, but have the same users (-> Users are only counted once) - assertMetricEquals(2, "artemis.scheduled.exercises.due.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "120"); - assertMetricEquals(3 * 1, "artemis.scheduled.exercises.due.student_multiplier", "exerciseType", ExerciseType.QUIZ.toString(), "range", "120"); + assertMetricEquals(2, "artemis.scheduled.exercises.release.student_multiplier.active.14", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); var course2 = courseUtilService.createCourse(); course2.setStudentGroupName(TEST_PREFIX + "course2students"); @@ -385,19 +378,19 @@ void testPrometheusMetricsExercises() { metricsBean.recalculateMetrics(); - // 3 quizzes end within the next 120 minutes, and are in two different courses -> 6 different users in total - assertMetricEquals(3, "artemis.scheduled.exercises.due.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "120"); - assertMetricEquals(3 * 2, "artemis.scheduled.exercises.due.student_multiplier", "exerciseType", ExerciseType.QUIZ.toString(), "range", "120"); + // 2 quizzes end within the next 15 minutes, and are in two different courses -> 6 different users in total + assertMetricEquals(2, "artemis.scheduled.exercises.due.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); + assertMetricEquals(3 * 2, "artemis.scheduled.exercises.due.student_multiplier", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); // One text exercise is released within the next 30 minutes - assertMetricEquals(1, "artemis.scheduled.exercises.release.count", "exerciseType", ExerciseType.TEXT.toString(), "range", "30"); + assertMetricEquals(1, "artemis.scheduled.exercises.release.count", "exerciseType", ExerciseType.TEXT.toString(), "range", "15"); } @Test void testPrometheusMetricsExams() { var users = userUtilService.addUsers(TEST_PREFIX, 3, 0, 0, 0); var course = courseUtilService.createCourse(); - var exam1 = examUtilService.addExam(course, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(20), ZonedDateTime.now().plusMinutes(40)); + var exam1 = examUtilService.addExam(course, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(2), ZonedDateTime.now().plusMinutes(10)); var registeredExamUser1 = new ExamUser(); registeredExamUser1.setUser(users.get(0)); registeredExamUser1.setExam(exam1); @@ -415,7 +408,7 @@ void testPrometheusMetricsExams() { examUtilService.addExerciseGroupsAndExercisesToExam(exam1, false); courseRepository.save(course); - var exam2 = examUtilService.addExam(course, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(65), ZonedDateTime.now().plusMinutes(85)); + var exam2 = examUtilService.addExam(course, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(5), ZonedDateTime.now().plusMinutes(12)); var registeredExamUser3 = new ExamUser(); registeredExamUser3.setUser(users.get(0)); registeredExamUser3.setExam(exam2); @@ -429,25 +422,13 @@ void testPrometheusMetricsExams() { metricsBean.recalculateMetrics(); - // One exam ends within the next 60 minutes - assertMetricEquals(1, "artemis.scheduled.exams.due.count", "range", "60"); - assertMetricEquals(1 * 2, "artemis.scheduled.exams.due.student_multiplier", "range", "60"); // 2 students are registered for the exam + // Two exams start within the next 15 minutes, but have the same users (-> Users are only counted once) + assertMetricEquals(2, "artemis.scheduled.exams.release.count", "range", "15"); + assertMetricEquals(1 * 2, "artemis.scheduled.exams.release.student_multiplier", "range", "15"); // Two exams ends within the next 120 minutes - assertMetricEquals(2, "artemis.scheduled.exams.due.count", "range", "120"); - assertMetricEquals(1 * 2, "artemis.scheduled.exams.due.student_multiplier", "range", "120"); // 2 + 1 students are registered for the exam, but they are duplicate users - - // No exam starts within the next 15 minutes - assertMetricEquals(0, "artemis.scheduled.exams.release.count", "range", "15"); - assertMetricEquals(0, "artemis.scheduled.exams.release.student_multiplier", "range", "15"); - - // One exam starts within the next 30 minutes - assertMetricEquals(1, "artemis.scheduled.exams.release.count", "range", "30"); - assertMetricEquals(1 * 2, "artemis.scheduled.exams.release.student_multiplier", "range", "30"); // 2 registered students - - // Two exams start within the next 120 minutes, but have the same users (-> Users are only counted once) - assertMetricEquals(2, "artemis.scheduled.exams.release.count", "range", "120"); - assertMetricEquals(1 * 2, "artemis.scheduled.exams.release.student_multiplier", "range", "120"); + assertMetricEquals(2, "artemis.scheduled.exams.due.count", "range", "15"); + assertMetricEquals(1 * 2, "artemis.scheduled.exams.due.student_multiplier", "range", "15"); // 2 + 1 students are registered for the exam, but they are duplicate users var registeredExamUser4 = new ExamUser(); registeredExamUser4.setUser(users.get(2)); @@ -459,12 +440,12 @@ void testPrometheusMetricsExams() { metricsBean.recalculateMetrics(); - // Two exams start within the next 120 minutes, but have the same users (-> Users are only counted once) - assertMetricEquals(2, "artemis.scheduled.exams.release.count", "range", "120"); - assertMetricEquals(1 * 2 + 1 * 1, "artemis.scheduled.exams.release.student_multiplier", "range", "120"); + // Two exams start within the next 15 minutes, but have the same users (-> Users are only counted once) + assertMetricEquals(2, "artemis.scheduled.exams.release.count", "range", "15"); + assertMetricEquals(1 * 2 + 1 * 1, "artemis.scheduled.exams.release.student_multiplier", "range", "15"); // Exam exercises are not returned in the exercises metrics - assertMetricEquals(0, "artemis.scheduled.exercises.due.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "60"); + assertMetricEquals(0, "artemis.scheduled.exercises.due.count", "exerciseType", ExerciseType.QUIZ.toString(), "range", "15"); } @Test