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: Improve View Build Logs code #10180

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

Conversation

BBesrour
Copy link
Member

@BBesrour BBesrour commented Jan 21, 2025

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 added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added authorities to all new routes and checked the course groups for displaying navigation elements (links, buttons).
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).

Motivation and Context

We removed an unnecessary endpoint. Instead, we display the text file as is and we create a blob from the received text to download the file

Steps for Testing

Prerequisites:

  • 1 Admin/Instructor
  • Few programming exercise submissions
  1. Navigate to the build overview
  2. Click on view build logs. Make sure that the logs are displayed correctly and corresponds to the correct build job
  3. Click on download, make sure that the correct build log was downloaded.

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

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Test Coverage

Summary by CodeRabbit

Summary by CodeRabbit

  • Breaking Changes

    • Removed build log entries retrieval functionality.
    • Simplified build log display from detailed entries to a single string.
  • Bug Fixes

    • Enhanced error messaging for downloading build logs.
  • Refactor

    • Streamlined build log processing in frontend and backend.
    • Modified log retrieval and display mechanisms.
  • Tests

    • Updated test cases to reflect new log handling approach and assertion methods.

@BBesrour BBesrour requested a review from a team as a code owner January 21, 2025 01:09
@BBesrour BBesrour self-assigned this Jan 21, 2025
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) client Pull requests that update TypeScript code. (Added Automatically!) programming Pull requests that affect the corresponding module labels Jan 21, 2025
Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces significant changes to how build logs are handled in the Artemis application. The modifications involve removing the method for retrieving build log entries, changing the data type for build logs from an array to a single string, and updating the corresponding service, component, and test files. The changes simplify the log retrieval and display process, moving from a detailed, structured log representation to a more straightforward string-based approach.

Changes

File Change Summary
src/main/java/.../BuildLogResource.java Removed getBuildLogEntriesForBuildJob method
src/main/webapp/app/entities/programming/build-log.model.ts Updated time property types in BuildLogLines and BuildLogEntry
src/main/webapp/app/localci/build-queue/build-queue.component.html Simplified log display using <pre> tag instead of nested loops
src/main/webapp/app/localci/build-queue/build-queue.component.ts Replaced rawBuildLogs array with rawBuildLogsString
src/main/webapp/app/localci/build-queue/build-queue.service.ts Changed getBuildJobLogs method to return Observable<string>
src/test/java/.../LocalCIResourceIntegrationTest.java Removed testGetBuildLogsEntriesForResult test method
src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts Updated tests to work with string-based log representation
src/test/javascript/spec/component/localci/build-queue/build-queue.service.spec.ts Updated assertion methods and test URLs
src/main/webapp/i18n/de/buildQueue.json Added "downloadError" key for download error message
src/main/webapp/i18n/en/buildQueue.json Added "downloadError" key for download error message

Possibly related PRs

Suggested Labels

bugfix, ready to merge

Suggested Reviewers

  • SimonEntholzer
  • florian-glombik
  • HawKhiem
  • krusche
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
src/main/webapp/app/localci/build-queue/build-queue.component.html (1)

894-897: LGTM! The implementation follows the new Angular syntax guidelines.

The code correctly uses @if and @else directives instead of the older *ngIf syntax.

Consider these improvements for better accessibility and readability:

 @if (rawBuildLogsString) {
-    <pre>{{ rawBuildLogsString }}</pre>
+    <pre class="build-logs" role="log" aria-label="Build logs" tabindex="0">{{ rawBuildLogsString }}</pre>
 } @else {
-    <span jhiTranslate="artemisApp.buildQueue.logs.noLogs"></span>
+    <p class="text-muted" jhiTranslate="artemisApp.buildQueue.logs.noLogs"></p>
 }

Add these styles to your component's CSS:

.build-logs {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.25rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
}
src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (1)

377-377: Consider using more specific expectation.

Using toHaveBeenCalled() instead of toHaveBeenCalledOnce() makes the test less precise. The original expectation would catch potential duplicate calls that could indicate inefficient behavior.

-        expect(mockBuildQueueService.getBuildJobStatistics).toHaveBeenCalled();
+        expect(mockBuildQueueService.getBuildJobStatistics).toHaveBeenCalledOnce();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1543e3e and 6a79759.

📒 Files selected for processing (8)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/localci/BuildLogResource.java (0 hunks)
  • src/main/webapp/app/entities/programming/build-log.model.ts (1 hunks)
  • src/main/webapp/app/localci/build-queue/build-queue.component.html (1 hunks)
  • src/main/webapp/app/localci/build-queue/build-queue.component.ts (2 hunks)
  • src/main/webapp/app/localci/build-queue/build-queue.service.ts (1 hunks)
  • src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalCIResourceIntegrationTest.java (0 hunks)
  • src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (2 hunks)
  • src/test/javascript/spec/component/localci/build-queue/build-queue.service.spec.ts (19 hunks)
💤 Files with no reviewable changes (2)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/localci/BuildLogResource.java
  • src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalCIResourceIntegrationTest.java
✅ Files skipped from review due to trivial changes (1)
  • src/test/javascript/spec/component/localci/build-queue/build-queue.service.spec.ts
🧰 Additional context used
📓 Path-based instructions (5)
src/main/webapp/app/entities/programming/build-log.model.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/localci/build-queue/build-queue.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/localci/build-queue/build-queue.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/localci/build-queue/build-queue.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (8)
src/main/webapp/app/localci/build-queue/build-queue.component.ts (4)

207-207: LGTM! Good practice initializing the string.

The string initialization is explicit and follows TypeScript best practices.


431-432: LGTM! Proper state reset.

Good practice clearing the logs and resetting the ID before loading new logs.


437-438: LGTM! Clean type handling.

The type handling for the build logs response is correct and matches the service return type.


450-463: LGTM! Improved file download implementation.

The implementation:

  1. Properly creates a Blob with correct MIME type
  2. Uses URL.createObjectURL for efficient handling
  3. Correctly cleans up the URL object to prevent memory leaks
src/main/webapp/app/entities/programming/build-log.model.ts (1)

12-12: Verify the impact of optional time property.

Making the time property optional could affect code that assumes its presence. Please ensure that all consumers of BuildLogLines handle the case where time is undefined.

Run the following script to find potential issues:

src/main/webapp/app/localci/build-queue/build-queue.service.ts (1)

Line range hint 197-202: LGTM! Clean and effective implementation.

The changes align well with the PR objectives:

  • Return type changed to Observable<string> for simpler log handling
  • Response type correctly set to 'text'
  • Error handling maintained with user-friendly message
src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (2)

665-666: LGTM! Test data updated to match new implementation.

The changes correctly reflect the transition from array-based to string-based log handling:

  • Test data simplified to multi-line string
  • Expectation updated to check rawBuildLogsString

Also applies to: 671-671


673-693: LGTM! Comprehensive download functionality tests.

The new tests thoroughly cover the Blob and URL handling:

  • Blob creation with correct type
  • URL object lifecycle (create and revoke)
  • Download trigger via anchor element
  • Cleanup of resources

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 21, 2025
coolchock
coolchock previously approved these changes Jan 24, 2025
Copy link
Contributor

@coolchock coolchock 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
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.

Code looks good, left one comment concerning the tests

Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

tested on TS1, works as expected.

Unsure if that counts but code also looks good to. Added one inline-suggestion

Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

2 small questions or comments

@BBesrour BBesrour dismissed stale reviews from coderabbitai[bot] and coolchock via c71c643 January 29, 2025 01:15
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: 0

🧹 Nitpick comments (3)
src/main/webapp/app/localci/build-queue/build-queue.component.ts (1)

451-457: Consider adding error type information for better error handling.

The error handling in the catch block could be more specific by typing the error parameter.

-            } catch (error) {
+            } catch (error: unknown) {
src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (2)

680-689: Consider improving test assertions for error handling.

The test should verify both success and failure scenarios of the download functionality.

         const downloadSpy = jest.spyOn(DownloadUtil, 'downloadFile');
 
         component.downloadBuildLogs();
 
         expect(downloadSpy).toHaveBeenCalledOnce();
         expect(downloadSpy).toHaveBeenCalledWith(mockBlob, `${buildJobId}.log`);
-        expect(alertServiceErrorStub).toHaveBeenCalled();
+        expect(alertServiceErrorStub).not.toHaveBeenCalled();
+
+        // Test error scenario
+        downloadSpy.mockImplementationOnce(() => { throw new Error('Download failed'); });
+        component.downloadBuildLogs();
+        expect(alertServiceErrorStub).toHaveBeenCalledWith('artemisApp.buildQueue.logs.downloadError');

690-696: Consider removing redundant test.

The second download test appears redundant as it's testing the same functionality. Consider removing it or testing a different scenario.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a79759 and c71c643.

📒 Files selected for processing (5)
  • src/main/webapp/app/entities/programming/build-log.model.ts (0 hunks)
  • src/main/webapp/app/localci/build-queue/build-queue.component.ts (3 hunks)
  • src/main/webapp/i18n/de/buildQueue.json (1 hunks)
  • src/main/webapp/i18n/en/buildQueue.json (1 hunks)
  • src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (5 hunks)
💤 Files with no reviewable changes (1)
  • src/main/webapp/app/entities/programming/build-log.model.ts
🧰 Additional context used
📓 Path-based instructions (3)
src/main/webapp/i18n/de/buildQueue.json (1)

Pattern src/main/webapp/i18n/de/**/*.json: German language translations should be informal (dutzen) and should never be formal (sietzen). So the user should always be addressed with "du/dein" and never with "sie/ihr".

src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/localci/build-queue/build-queue.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: client-style
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: Build and Push Docker Image
  • GitHub Check: server-tests
  • GitHub Check: Build .war artifact
  • GitHub Check: Analyse
🔇 Additional comments (7)
src/main/webapp/app/localci/build-queue/build-queue.component.ts (3)

31-31: LGTM!

The imports are correctly added and properly organized.

Also applies to: 37-37


208-208: LGTM!

The property is correctly typed and initialized.


432-444: LGTM!

The viewBuildLogs method correctly handles the build logs as a string and properly manages component state.

src/main/webapp/i18n/en/buildQueue.json (1)

82-83: LGTM!

The error messages are clear, consistent, and properly organized.

src/main/webapp/i18n/de/buildQueue.json (1)

82-83: LGTM!

The German translations are correctly formatted and follow the informal style guide (using "du/dein" form).

src/test/javascript/spec/component/localci/build-queue/build-queue.component.spec.ts (2)

270-271: LGTM!

The AlertService is properly injected and mocked for testing.

Also applies to: 285-285, 291-292


672-678: LGTM!

The test correctly verifies the log content handling.

Copy link
Contributor

@az108 az108 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 implementing the changes, Code 👍

Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

code looks good after minor changes since last approval 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) programming Pull requests that affect the corresponding module 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.

5 participants