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: Add more data for telemetry #9345

Merged
merged 32 commits into from
Oct 19, 2024

Conversation

SimonEntholzer
Copy link
Contributor

@SimonEntholzer SimonEntholzer commented Sep 20, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I documented the Java code using JavaDoc style.

Motivation and Context

We already have a Telemetry service, which collects valuable data from Artemis instances of other universities. To gain more insights, we want to extend it by additional fields.

Description

This PR adds fields to the telemetry data json:

  • isProductionInstance: boolean flag if running instance is a production instance
  • dataSource: if the datasource is mysql or postgres

Steps for Testing

Prerequisites:

  1. Start the server
  2. Check that the telemetry data collection service receives data, and stores it to the database correctly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
TelemetrySendingService.java 94% ✅ ❌
TelemetryService.java 100%

Summary by CodeRabbit

  • New Features

    • Introduced TelemetrySendingService for asynchronous transmission of telemetry data.
    • Added new TelemetryData record to encapsulate telemetry-related information, enhancing monitoring capabilities.
    • Enhanced telemetry data collection with additional fields like isProductionInstance, dataSource, and sendAdminDetails.
    • Added EurekaClientService to retrieve the count of registered instances of the Artemis application.
  • Bug Fixes

    • Improved error handling in telemetry data retrieval.
  • Refactor

    • Restructured package organization for better clarity and maintenance.
    • Updated TelemetryService to improve telemetry sending logic and configuration handling.
  • Tests

    • Updated tests to reflect changes in the package structure for TelemetryService.
    • Enhanced test setup to incorporate additional configurations related to Eureka service discovery and personal data handling.
    • Adjusted tests to verify the scheduling of telemetry tasks and the handling of application data.

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) labels Sep 20, 2024
@SimonEntholzer SimonEntholzer marked this pull request as ready for review September 20, 2024 22:06
@SimonEntholzer SimonEntholzer requested a review from a team as a code owner September 20, 2024 22:06
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes introduce the EurekaClientService, TelemetrySendingService, and TelemetryService classes to enhance telemetry data collection and transmission within a Spring application. The EurekaClientService retrieves the count of registered instances from a Eureka server, while the TelemetrySendingService facilitates the asynchronous sending of telemetry data. The TelemetryService is modified to integrate these new services and manage telemetry tasks based on application properties.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java Introduced EurekaClientService class to interact with a Eureka server, retrieve the count of registered instances, and handle HTTP requests with Basic Authentication.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java Introduced TelemetrySendingService class for asynchronous telemetry data sending, including a nested TelemetryData record, a constructor for dependency injection, and methods for sending telemetry data.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java Moved TelemetryService to a new package, modified fields to be private and final, updated the constructor to accept new parameters, and revised the sendTelemetry method to call sendTelemetryByPostRequest.
src/test/java/de/tum/cit/aet/artemis/core/service/TelemetryServiceTest.java Enhanced testing capabilities for TelemetryService by adding new fields and updating test methods to reflect changes in telemetry task scheduling and application data handling.

Possibly related PRs

  • Development: Make Telemetry service async #9287: The changes in this PR involve the TelemetrySendingService, which is relevant because both the main PR and this PR deal with telemetry services in the same application context, specifically focusing on how telemetry data is sent and managed.

Suggested labels

ready for review, ready to merge

Suggested reviewers

  • JohannesStoehr
  • asliayk
  • b-fein
  • anian03
  • az108
  • undernagruzez
  • BBesrour
  • iyannsch
  • pzdr7

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 7efc0ac and 3b7f759.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.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

📓 Learnings (1)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (1)
Learnt from: SimonEntholzer
PR: ls1intum/Artemis#9345
File: src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java:0-0
Timestamp: 2024-10-08T21:46:22.597Z
Learning: In the `TelemetryService` class, the fields `useTelemetry`, `sendAdminDetails`, `eurekaEnabled`, and `sendingDelay` are intentionally kept public for testability purposes.
🔇 Additional comments (5)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (5)

Line range hint 1-13: LGTM: Package and imports updated correctly.

The package declaration has been updated to reflect the new location of the file, and the necessary import for ProfileService has been added. These changes are appropriate and align with the code's new structure.


25-27: Improved encapsulation with private final fields.

The addition of private final fields useTelemetry and sendAdminDetails enhances encapsulation and immutability. This change aligns with best practices for field declarations in Java.


29-34: Excellent use of constructor injection for configuration values.

The constructor has been updated to use constructor injection for all dependencies, including the configuration values useTelemetry and sendAdminDetails. This approach:

  1. Improves testability by allowing easy mocking of these values in unit tests.
  2. Makes the dependencies explicit and required for instantiation.
  3. Adheres to dependency injection best practices.

Great job on this improvement!


38-41: JavaDoc updated to accurately reflect current implementation.

The JavaDoc for the sendTelemetry method has been appropriately updated to remove references to scheduling and delay, which are no longer part of the implementation. It now clearly describes the method's behavior and the conditions under which telemetry data will not be sent.


44-49: Improved telemetry sending logic, but clarification needed.

The sendTelemetry method has been improved:

  1. It now checks both useTelemetry and profileService.isDevActive() before sending data, which respects user settings and improves efficiency.
  2. The log message has been updated to accurately reflect the immediate nature of the telemetry sending.

However, there's one point that needs clarification:

  • The call to telemetrySendingService.sendTelemetryByPostRequest no longer includes the eurekaEnabled parameter. Could you please explain why this parameter was removed and confirm that it's not needed in the TelemetrySendingService?

To verify the removal of the eurekaEnabled parameter, let's check the TelemetrySendingService:


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0354197 and 3a5d86f.

Files ignored due to path filters (2)
  • src/test/resources/config/application-artemis.yml is excluded by !**/*.yml
  • src/test/resources/config/application.yml is excluded by !**/*.yml
Files selected for processing (4)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (4 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (2 hunks)
  • src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1 hunks)
Additional context used
Path-based instructions (4)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.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/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.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/cit/aet/artemis/core/service/telemetry/TelemetryService.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/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

Additional comments not posted (13)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (2)

1-1: LGTM!

Moving the TelemetryService class to a dedicated telemetry sub-package aligns with the single responsibility principle and improves code organization.


15-15: LGTM!

The import statement for ProfileService follows the coding guideline to avoid wildcard imports.

src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

29-29: LGTM!

The change in import statement for TelemetryService reflects the restructuring of the package hierarchy. Moving the class to a dedicated telemetry subpackage improves code organization and modularity. The change is consistent with the information provided in the list of alterations and does not introduce any functional or logical issues.

src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java (2)

49-73: LGTM!

The method logic is correct, and the implementation is accurate. It follows the provided coding guidelines and best practices.


81-91: LGTM!

The method logic is correct, and the implementation is accurate. It follows the provided coding guidelines and best practices.

src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (8)

1-1: Package restructuring improves modularity

Changing the package to de.tum.cit.aet.artemis.core.service.telemetry better organizes telemetry-related services and enhances code maintainability.


24-24: Importing ProfileService for profile management

The import of ProfileService is appropriate for accessing profile-related information within the telemetry service.


33-34: Expansion of TelemetryData record aligns with data requirements

Adding new fields to TelemetryData allows the collection of more comprehensive telemetry data, fulfilling the PR objectives and adhering to DTO guidelines of minimal necessary data.


41-44: Dependencies added with appropriate access control

The declaration of EurekaClientService and ProfileService as private final complies with the least access principle and supports immutability.


45-49: Constructor updated for proper dependency injection

Including EurekaClientService and ProfileService in the constructor aligns with constructor injection best practices, promoting better testability and adherence to the single responsibility principle.


73-75: Injection of datasourceUrl using @Value annotation

Using @Value("${spring.datasource.url}") to inject datasourceUrl is appropriate and consistent with configuration management practices.


76-78: Injection of eurekaEnabled flag

The use of @Value("${eureka.client.enabled}") to inject the eurekaEnabled property correctly retrieves the configuration value.


79-81: Injection of buildAgentCount configuration

Injecting buildAgentCount with @Value("${artemis.continuous-integration.concurrent-build-size}") appropriately accesses the configuration setting.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 3a5d86f and 3829a34.

Files ignored due to path filters (1)
  • src/test/resources/config/application.yml is excluded by !**/*.yml
Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (4 hunks)
  • src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (3 hunks)
Additional context used
Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.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/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

Additional comments not posted (5)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (4)

1-1: Package refactoring enhances modularity

Moving TelemetrySendingService to the telemetry package improves code organization and aligns the class with its functionality.


33-34: Expanded TelemetryData record captures detailed metrics

Adding new fields to TelemetryData allows for more comprehensive telemetry reporting, fulfilling the PR objectives of collecting richer data.


98-103: Refactor to eliminate duplication when creating TelemetryData

Duplicating the creation of TelemetryData instances can be streamlined to enhance readability and maintainability.

Consider refactoring as follows:

TelemetryData telemetryData;
+String contactInfo = null;
+String adminName = null;
if (sendAdminDetails) {
+    contactInfo = contact;
+    adminName = operatorAdminName;
}
-telemetryData = new TelemetryData(version, serverUrl, operator, activeProfiles, profileService.isProductionActive(), dataSource, numberOfInstances, buildAgentCount,
-        contact, operatorAdminName);
+telemetryData = new TelemetryData(version, serverUrl, operator, activeProfiles, profileService.isProductionActive(), dataSource, numberOfInstances, buildAgentCount,
+        contactInfo, adminName);

Likely invalid or redundant comment.


91-91: Consider enhancing data source detection logic

The current logic assumes only MySQL or defaults to PostgreSQL, which may misclassify other data sources. To improve robustness, handle additional data source types or add validation for unknown types.

Apply this diff to improve the detection logic:

-var dataSource = datasourceUrl.startsWith("jdbc:mysql") ? "mysql" : "postgresql";
+String dataSource;
+if (datasourceUrl.startsWith("jdbc:mysql")) {
+    dataSource = "mysql";
+} else if (datasourceUrl.startsWith("jdbc:postgresql")) {
+    dataSource = "postgresql";
+} else {
+    dataSource = "unknown";
+    log.warn("Unknown datasource URL: {}", datasourceUrl);
+}

Likely invalid or redundant comment.

src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

92-92: Review the necessity of increasing timeouts in tests

The timeout in the await() calls has been increased from 1 second to 2 seconds. Please verify if this increase is necessary. Longer timeouts can slow down the test suite. If possible, optimize the tests to complete within the original timeframe.

Also applies to: 112-112

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: 9

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 3829a34 and e5c690a.

Files ignored due to path filters (1)
  • src/test/resources/config/application.yml is excluded by !**/*.yml
Files selected for processing (3)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (3 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (4 hunks)
  • src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (3 hunks)
Additional context used
Path-based instructions (3)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.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/cit/aet/artemis/core/service/telemetry/TelemetryService.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/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

Additional comments not posted (14)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (2)

57-57: LGTM!

The method call to sendTelemetryByPostRequest has been correctly updated with the new parameters eurekaEnabled and sendAdminDetails.


1-1: Verify all references to the updated package.

The package declaration has changed to de.tum.cit.aet.artemis.core.service.telemetry. Ensure that all references to TelemetryService throughout the codebase have been updated to reflect this change to prevent ClassNotFoundException or other runtime issues.

Run the following script to verify the package change:

src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (6)

1-1: Package restructuring improves code organization

Updating the package to de.tum.cit.aet.artemis.core.service.telemetry enhances modularity by grouping telemetry-related classes together.


24-24: Necessary import of ProfileService

Importing ProfileService is appropriate, as it's used to check if the production profile is active.


41-49: Good use of constructor injection for dependencies

Injecting EurekaClientService and ProfileService via the constructor adheres to the dependency injection principle, enhancing testability and modularity.


73-74: Confirm the accuracy of buildAgentCount value

Ensure that the buildAgentCount retrieved from ${artemis.continuous-integration.concurrent-build-size} accurately reflects the number of build agents in the system, especially if the configuration can change at runtime.


90-90: Consider enhancing data source detection logic

The current logic assumes only MySQL or defaults to PostgreSQL, which might misidentify other data sources. Please consider handling additional data source types or adding validation to prevent incorrect identification.


98-99: Refactor to eliminate duplication when creating TelemetryData

There's duplicated code when setting up TelemetryData instances. Refactoring can simplify the code and enhance maintainability.

src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (6)

96-96: Ensure Consistent Use of Boolean Flags in Tests

When setting telemetryServiceSpy.sendAdminDetails = false;, ensure that the default value is true in the test context to validate the change effectively. This helps confirm that the test specifically checks the absence of personal data when the flag is disabled.

Check the default value of sendAdminDetails in the TelemetryService class to ensure the test behaves as intended.


63-63: Use Consistent Exception Handling in Test Methods

The init() method now throws JsonProcessingException. Verify if other test methods need to handle or declare this exception, ensuring consistency across the test class.

Check if any overridden methods or interfaces require updating due to this change.


63-71: Handle Exceptions Appropriately Instead of Empty Catch Block

Using an empty catch block can suppress exceptions that may indicate underlying issues. Rather than ignoring the exception, consider logging it to aid in debugging if an unexpected error occurs.

Apply this diff to log the exception:

try {
    var eurekaURI = new URI(defaultZoneUrl);
    eurekaRequestUrl = eurekaURI.getScheme() + "://" + eurekaURI.getAuthority() + "/api/eureka/applications";
}
- catch (Exception ignored) {
-     // Exception can be ignored because defaultZoneUrl is guaranteed to be valid in the test environment
+ catch (Exception e) {
+     // Log the exception for debugging purposes
+     e.printStackTrace();
}

Alternatively, if the exception can truly be ignored, ensure that the caught exception is as specific as possible (e.g., URISyntaxException) and maintain a comment explaining why it is safe to ignore.

[Alternatively, as per the guidelines, the assistant should note that this was already addressed in past comments.]

However, since this issue was previously raised and addressed by adding a comment, you can consider this resolved.


91-91: Review Increased Timeout Duration

The timeout in the await assertion has been increased from 1 second to 2 seconds in multiple tests. Ensure that this change is necessary and that the longer timeout does not mask potential performance issues.

Consider whether the increased timeout is required due to environmental factors or if it indicates a slowdown in the code under test. If the latter, investigate and address the root cause.

Also applies to: 106-106, 126-126


14-15: Import Only Necessary Classes

Some of the imported classes, such as java.util.Map or com.fasterxml.jackson.core.JsonProcessingException, might not be needed if they are not used elsewhere in the code. Review the imports and remove any that are unnecessary to keep the codebase clean.

Also applies to: 31-31


73-73: Ensure Compatibility with Older Java Versions

The use of Map.of() and List.of() requires Java 9 or higher. If your project aims to maintain compatibility with earlier Java versions, consider using alternative methods for creating maps and lists.

Run the following script to check the project's Java version compatibility:

Verification successful

Java Version Compatibility Confirmed

The project's main build.gradle file specifies Java 21, which fully supports Map.of() and List.of() methods. These methods are compatible with Java 9 and above, so there's no compatibility issue with older Java versions in the main project.

Note:

  • The main build.gradle uses JavaVersion.VERSION_21
  • Some template build.gradle files use Java 17, which also supports these methods

The original concern about maintaining compatibility with earlier Java versions is not applicable in this context.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the project is set to use Java 9 or higher.

# Test: Look for Java version in build files. Expect: Java version 9 or higher.
rg --type gradle --type maven 'sourceCompatibility|java.version' -A 2

Length of output: 101


Script:

#!/bin/bash
# Description: Check Java version in Gradle and Maven build files

# Search for Gradle build files
echo "Searching Gradle build files:"
fd -e gradle -e gradle.kts | xargs -I {} sh -c 'echo "File: {}"; cat {} | grep -i "sourceCompatibility\|targetCompatibility\|JavaVersion"'

echo -e "\nSearching Maven POM files:"
fd -e xml -n pom.xml | xargs -I {} sh -c 'echo "File: {}"; cat {} | grep -i "<java.version>\|<maven.compiler.source>\|<maven.compiler.target>"'

Length of output: 1894

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 26, 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: 12

🧹 Outside diff range comments (1)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (1)

Line range hint 59-66: Avoid catching general exceptions

Catching the general Exception can obscure specific issues and make debugging more difficult. It's better to catch specific exceptions that can be anticipated and handled appropriately.

Consider narrowing down the catch block to handle specific exceptions or rethrow exceptions when necessary.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e5c690a and 8988d00.

📒 Files selected for processing (4)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (4 hunks)
  • src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.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/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.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/cit/aet/artemis/core/service/telemetry/TelemetryService.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/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

🔇 Additional comments (8)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java (2)

39-41: 🧹 Nitpick (assertive)

Ensure consistency in dependency injection by using annotations

While constructor injection is preferred, consider adding @Autowired for clarity and consistency throughout the codebase.

Apply this diff to add the annotation:

 public EurekaClientService(RestTemplate restTemplate) {
+    @Autowired
     this.restTemplate = restTemplate;
 }

Likely invalid or redundant comment.


53-77: Verify that the service handles delayed registration of Eureka instances

Since Eureka instances might not register immediately upon application startup, there is a possibility that the telemetry data is sent before all nodes have been registered, leading to an inaccurate count. Ensure that the service accounts for this delay.

Run the following script to check if the service waits appropriately:

✅ Verification successful

Verification Successful: Service Accounts for Delayed Eureka Registration

The TelemetrySendingService.java includes a Thread.sleep(waitInSeconds * 1000); before querying Eureka, effectively handling potential delays in Eureka instance registration.

  • File: src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
  • Relevant Lines: Implemented delay using Thread.sleep(waitInSeconds * 1000);
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's a delay or mechanism to account for Eureka registration latency.

# Test: Search for any scheduling or delay implementations in the service.
# Expect: Methods or configurations that handle delayed execution.

rg --type java --context 5 'Scheduled' src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/

Length of output: 99


Script:

#!/bin/bash
# Description: Search for alternative delay or retry mechanisms in the EurekaClientService.

# Test: Look for keywords related to retry logic, sleep statements, or other delay implementations.
# Expect: Methods or configurations that handle delayed execution.

rg --type java --context 5 -e 'retry' -e 'sleep' -e 'delay' src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/

Length of output: 1474

src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java (6)

4-31: Import Statements Added Correctly

The import statements have been appropriately updated to support the new test methods and functionalities.


55-61: New Variables Declared for Test Setup

The addition of eurekaDefaultZoneUrl, eurekaRequestUrl, and applicationsBody variables is appropriate and necessary for the enhanced test configurations.


72-78: Initialization Updates Enhance Test Environment

The enhancements in the init method properly configure the telemetry service spy and mock server for the tests.


83-93: Test testSendTelemetry_TelemetryEnabled Updated Correctly

The test method has been appropriately updated to include the new mock server expectations and configurations.


95-107: New Test Method Adds Valuable Coverage

The testSendTelemetry_TelemetryEnabledWithoutPersonalData() method effectively tests the scenario where personal data should not be sent, aligning with the PR objectives.


121-127: Exception Handling Test Validates Error Scenarios

The testSendTelemetry_ExceptionHandling() method appropriately tests the service's behavior when the server responds with an error.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 26, 2024
Copy link
Contributor

@b-fein b-fein left a comment

Choose a reason for hiding this comment

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

Question if the EurekaClientService can be simplified.

Change request mostly to get notified about a re-review-request once the code style/Javadoc issue is resolved.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 49423d7 and 7efc0ac.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.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/cit/aet/artemis/core/service/telemetry/TelemetryService.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

📓 Learnings (3)
📓 Common learnings
Learnt from: SimonEntholzer
PR: ls1intum/Artemis#9345
File: src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java:0-0
Timestamp: 2024-10-08T21:46:22.597Z
Learning: In the `TelemetryService` class, the fields `useTelemetry`, `sendAdminDetails`, `eurekaEnabled`, and `sendingDelay` are intentionally kept public for testability purposes.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (1)
Learnt from: SimonEntholzer
PR: ls1intum/Artemis#9345
File: src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java:0-0
Timestamp: 2024-10-08T21:46:22.597Z
Learning: In the `TelemetryService` class, the fields `useTelemetry`, `sendAdminDetails`, `eurekaEnabled`, and `sendingDelay` are intentionally kept public for testability purposes.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java (1)
Learnt from: SimonEntholzer
PR: ls1intum/Artemis#9345
File: src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java:0-0
Timestamp: 2024-10-08T21:46:22.597Z
Learning: In the `TelemetryService` class, the fields `useTelemetry`, `sendAdminDetails`, `eurekaEnabled`, and `sendingDelay` are intentionally kept public for testability purposes.
🔇 Additional comments (5)
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java (5)

33-35: Well-defined TelemetryData record with appropriate fields

The TelemetryData record is correctly defined with all necessary fields to capture telemetry information. The use of @JsonInclude(JsonInclude.Include.NON_EMPTY) ensures that only non-empty fields are serialized, which is efficient for data transmission.


43-47: Constructor implements constructor injection properly

The constructor initializes all dependencies via constructor injection, adhering to best practices for dependency management in Spring applications.


86-105: Asynchronous telemetry sending with proper exception handling

The sendTelemetryByPostRequest method is appropriately annotated with @Async to enable asynchronous execution. Exceptions are caught and logged, ensuring that any issues during the telemetry transmission are recorded without disrupting the application's workflow.


96-97: Review logging of response body for sensitive information

Logging the response body from the telemetry server may inadvertently expose sensitive information if the response contains such data. Ensure that the response body is safe to log or consider logging only the status code or a confirmation message.


107-127: buildTelemetryData method accurately collects telemetry data

The buildTelemetryData method efficiently gathers all required telemetry information, including conditional inclusion of admin details based on the sendAdminDetails flag. This ensures flexibility and adherence to privacy considerations.

@SimonEntholzer SimonEntholzer requested a review from b-fein October 12, 2024 19:52
…lemetryService.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@SimonEntholzer SimonEntholzer requested a review from pzdr7 October 14, 2024 07:07
Copy link
Contributor

@iyannsch iyannsch left a comment

Choose a reason for hiding this comment

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

Thanks for incorporating the new changes requested and reducing the feature set in favor of the request! The new code looks good, I just got one small remark ☺️

@krusche krusche added this to the 7.6.1 milestone Oct 19, 2024
@SimonEntholzer SimonEntholzer temporarily deployed to artemis-test4.artemis.cit.tum.de October 19, 2024 18:13 — with GitHub Actions Inactive
@krusche krusche changed the title Development: Add more data for Telemetry Development: Add more data for telemetry Oct 19, 2024
@krusche krusche merged commit 850394c into develop Oct 19, 2024
42 of 46 checks passed
@krusche krusche deleted the feature/telemetry/add-additional-fields branch October 19, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Pull requests that affect the corresponding module server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants