Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Export admin users in the monitoring #8843

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Hialus
Copy link
Member

@Hialus Hialus commented Jun 22, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) database calls.
  • I strictly followed the server coding and design guidelines.
  • I documented the Java code using JavaDoc style.

Motivation and Context

We want to add a way to monitor the current admin users in Artemis, so that it is not missed if someone fraudulently adds one.

Description

For this I added a MultiGauge to the metrics endpoint exposing this data to e.g. Prometheus. This endpoint is fine for this purpose, as it already is only locked to certain IPs, so no data leakage will occur.
To get all admin users I added a new query in the user repository to only get the logins of the admins,

Steps for Testing

Prerequisites:

  • Local environment
  1. Start the server
  2. Open the URL "http://localhost:8080/management/prometheus" (Adjusted if you changed the port or smth)
  3. Search for artemis_scheduled_users_admins_active
  4. You should at least find the entry artemis_scheduled_users_admins_active{admin="artemis_admin",} 1.0. More if you have more local admin users in Artemis

Review Progress

Performance Review

  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Summary by CodeRabbit

  • New Features

    • Enhanced monitoring with new metrics for active admin accounts and release exam student multipliers.
  • Bug Fixes

    • Improved accuracy in calculating and updating active user metrics.
  • Refactor

    • Renamed method to better reflect its purpose in calculating active user metrics.
  • Tests

    • Updated test methods to align with changes in metric calculations.

@github-actions github-actions bot added the server Pull requests that update Java code. (Added Automatically!) label Jun 22, 2024
@Hialus Hialus marked this pull request as ready for review June 22, 2024 14:03
@Hialus Hialus requested a review from a team as a code owner June 22, 2024 14:03
Copy link

coderabbitai bot commented Jun 22, 2024

Walkthrough

The updates enhance the MetricsBean class by introducing new fields and methods for active admin and release exam student metrics registration and updating. It also includes a new method in UserRepository for retrieving active admin logins. Corresponding test modifications align method name changes with the new functionality.

Changes

File Summary
src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java Added releaseExamStudentMultiplierGauge and activeAdminsGauge. Updated calculateActiveUserMetrics(). Added methods for active admin metrics.
src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java Added findAllActiveAdminLogins() method for retrieving active admin logins.
src/test/java/de/tum/in/www1/artemis/config/MetricsBeanTest.java Renamed method calculateCachedActiveUserNames() to calculateActiveUserMetrics().

Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a2d85ca and b93d99c.

Files selected for processing (2)
  • src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java (4 hunks)
  • src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java (1 hunks)
Additional context used
Path-based instructions (2)
src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

Additional comments not posted (2)
src/main/java/de/tum/in/www1/artemis/config/MetricsBean.java (2)

157-158: New field for tracking active admin users.

The addition of activeAdminsGauge as a MultiGauge field aligns with the PR's objective to monitor admin users. This is crucial for ensuring the security and integrity of admin accounts.


380-382: Well-documented registration of active admin metrics.

The implementation of registerActiveAdminMetrics is concise and well-documented. The JavaDoc addition as per previous suggestions enhances the clarity. Good job adhering to best practices.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

@github-actions github-actions bot added the tests label Jun 22, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

SimonEntholzer
SimonEntholzer previously approved these changes Jun 22, 2024
Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition to be able to monitor active admins 👍

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 22, 2024
marlon-luca-bu
marlon-luca-bu previously approved these changes Jun 23, 2024
Copy link
Contributor

@marlon-luca-bu marlon-luca-bu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Jun 24, 2024
@bensofficial bensofficial removed the deployment-error Added by deployment workflows if an error occured label Jun 24, 2024
@bensofficial bensofficial removed the deployment-error Added by deployment workflows if an error occured label Jun 24, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Copy link
Member

@bensofficial bensofficial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exported admin logins also contain deleted admin users.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Copy link
Member

@bensofficial bensofficial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good to me. Works as expected on Staging ICL.

Copy link
Contributor

@marlon-luca-bu marlon-luca-bu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reapprove Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review server Pull requests that update Java code. (Added Automatically!) tests
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants