-
Notifications
You must be signed in to change notification settings - Fork 297
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
Conversation
WalkthroughThe changes introduce the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)
📓 Learnings (1)
🔇 Additional comments (5)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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
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_importssrc/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_importssrc/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_importssrc/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 dedicatedtelemetry
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 dedicatedtelemetry
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 modularityChanging the package to
de.tum.cit.aet.artemis.core.service.telemetry
better organizes telemetry-related services and enhances code maintainability.
24-24
: ImportingProfileService
for profile managementThe import of
ProfileService
is appropriate for accessing profile-related information within the telemetry service.
33-34
: Expansion ofTelemetryData
record aligns with data requirementsAdding 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 controlThe declaration of
EurekaClientService
andProfileService
asprivate final
complies with the least access principle and supports immutability.
45-49
: Constructor updated for proper dependency injectionIncluding
EurekaClientService
andProfileService
in the constructor aligns with constructor injection best practices, promoting better testability and adherence to the single responsibility principle.
73-75
: Injection ofdatasourceUrl
using@Value
annotationUsing
@Value("${spring.datasource.url}")
to injectdatasourceUrl
is appropriate and consistent with configuration management practices.
76-78
: Injection ofeurekaEnabled
flagThe use of
@Value("${eureka.client.enabled}")
to inject theeurekaEnabled
property correctly retrieves the configuration value.
79-81
: Injection ofbuildAgentCount
configurationInjecting
buildAgentCount
with@Value("${artemis.continuous-integration.concurrent-build-size}")
appropriately accesses the configuration setting.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
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_importssrc/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 modularityMoving
TelemetrySendingService
to thetelemetry
package improves code organization and aligns the class with its functionality.
33-34
: ExpandedTelemetryData
record captures detailed metricsAdding 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 creatingTelemetryData
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 logicThe 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 testsThe 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
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
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_importssrc/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_importssrc/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 parameterseurekaEnabled
andsendAdminDetails
.
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 toTelemetryService
throughout the codebase have been updated to reflect this change to preventClassNotFoundException
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 organizationUpdating the package to
de.tum.cit.aet.artemis.core.service.telemetry
enhances modularity by grouping telemetry-related classes together.
24-24
: Necessary import ofProfileService
Importing
ProfileService
is appropriate, as it's used to check if the production profile is active.
41-49
: Good use of constructor injection for dependenciesInjecting
EurekaClientService
andProfileService
via the constructor adheres to the dependency injection principle, enhancing testability and modularity.
73-74
: Confirm the accuracy ofbuildAgentCount
valueEnsure 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 logicThe 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 creatingTelemetryData
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 TestsWhen setting
telemetryServiceSpy.sendAdminDetails = false;
, ensure that the default value istrue
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 theTelemetryService
class to ensure the test behaves as intended.
63-63
: Use Consistent Exception Handling in Test MethodsThe
init()
method now throwsJsonProcessingException
. 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 BlockUsing 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 DurationThe 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 ClassesSome of the imported classes, such as
java.util.Map
orcom.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 VersionsThe use of
Map.of()
andList.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 supportsMap.of()
andList.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
usesJavaVersion.VERSION_21
- Some template
build.gradle
files use Java 17, which also supports these methodsThe 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 2Length 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
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 exceptionsCatching 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
📒 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_importssrc/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_importssrc/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_importssrc/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 instancesSince 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 aThread.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 CorrectlyThe import statements have been appropriately updated to support the new test methods and functionalities.
55-61
: New Variables Declared for Test SetupThe addition of
eurekaDefaultZoneUrl
,eurekaRequestUrl
, andapplicationsBody
variables is appropriate and necessary for the enhanced test configurations.
72-78
: Initialization Updates Enhance Test EnvironmentThe enhancements in the
init
method properly configure the telemetry service spy and mock server for the tests.
83-93
: TesttestSendTelemetry_TelemetryEnabled
Updated CorrectlyThe test method has been appropriately updated to include the new mock server expectations and configurations.
95-107
: New Test Method Adds Valuable CoverageThe
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 ScenariosThe
testSendTelemetry_ExceptionHandling()
method appropriately tests the service's behavior when the server responds with an error.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/cit/aet/artemis/telemetry/TelemetryServiceTest.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/EurekaClientService.java
Outdated
Show resolved
Hide resolved
e51fa7c
There was a problem hiding this 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
📒 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_importssrc/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-definedTelemetryData
record with appropriate fieldsThe
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 properlyThe 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 handlingThe
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 informationLogging 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 dataThe
buildTelemetryData
method efficiently gathers all required telemetry information, including conditional inclusion of admin details based on thesendAdminDetails
flag. This ensures flexibility and adherence to privacy considerations.
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetrySendingService.java
Show resolved
Hide resolved
…lemetryService.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this 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
src/main/java/de/tum/cit/aet/artemis/core/service/telemetry/TelemetryService.java
Show resolved
Hide resolved
Development
: Add more data for TelemetryDevelopment
: Add more data for telemetry
Checklist
General
Server
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 instancedataSource
: if the datasource is mysql or postgresSteps for Testing
Prerequisites:
dev
profile locally, make sure to manually comment out the check that disables the telemetry service by default on this profileTestserver 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
Manual Tests
Test Coverage
Summary by CodeRabbit
New Features
TelemetrySendingService
for asynchronous transmission of telemetry data.TelemetryData
record to encapsulate telemetry-related information, enhancing monitoring capabilities.isProductionInstance
,dataSource
, andsendAdminDetails
.EurekaClientService
to retrieve the count of registered instances of the Artemis application.Bug Fixes
Refactor
TelemetryService
to improve telemetry sending logic and configuration handling.Tests
TelemetryService
.