Skip to content

fix(api): use startIndex variable in downloadEventLog pagination loop#1114

Open
sinchubhat wants to merge 1 commit into
mainfrom
issue1104-console
Open

fix(api): use startIndex variable in downloadEventLog pagination loop#1114
sinchubhat wants to merge 1 commit into
mainfrom
issue1104-console

Conversation

@sinchubhat

@sinchubhat sinchubhat commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The function calculated and updated startIndex but passed 0 to GetEventLog, breaking pagination. Now passes startIndex and eventLogBatchSize properly.

Fixes #1104

Manual Testing

Setup

  1. Activate the AMT device first
  2. Set environment variables:
GUID="<GUID>"
TOKEN=$(curl -sk https://localhost:8181/api/v1/authorize \
  -H "Content-Type: application/json" \
  -d '{"username":"<username>","password":"<password>"}' | jq -r '.token')

Test Pagination API

Check event logs (page 1 - 5 records):

curl -sk "https://localhost:8181/api/v1/amt/log/event/$GUID?\$top=5&\$skip=0" \
  -H "Authorization: Bearer $TOKEN" | jq

Check event logs (page 2 - next 5 records):

curl -sk "https://localhost:8181/api/v1/amt/log/event/$GUID?\$top=5&\$skip=5" \
  -H "Authorization: Bearer $TOKEN" | jq

Generate More Events

Trigger power cycle to generate new event logs:

Trigger power action to generate likely AMT events (PowerCycle = 5)

curl -sk -X POST "https://localhost:8181/api/v1/amt/power/action/$GUID" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"action":5}' | jq

Verified API pagination works:

curl -sk "https://localhost:8181/api/v1/amt/log/event/$GUID?\$top=10&\$skip=0" \
  -H "Authorization: Bearer $TOKEN" | jq

Test Download (Fixed Endpoint)

Download all event logs via CSV:

You can manually download the csv file from UI or
Downloaded event logs via fixed endpoint:

curl -sk -o event_logs.csv \
  "https://localhost:8181/api/v1/amt/log/event/$GUID/download" \
  -H "Authorization: Bearer $TOKEN"

Verify download contains all events:

wc -l event_logs.csv
head -n 20 event_logs.csv

Output:

Successfully downloaded 18 event logs from multiple boot cycles (timestamps show events from 08:57 and 09:36)
19 lines (18 events + 1 header)

wc -l event_logs.csv
19 event_logs.csv

head -n 20 event_logs.csv
Time,Source,Event Severity,Description
2026-07-06 09:36:41 +0530 IST,BIOS,Non-critical condition,Starting operating system boot process
2026-07-06 09:36:42 +0530 IST,Intel(r) ME,Monitor,Embedded controller/management controller initialization
2026-07-06 09:36:35 +0530 IST,BIOS,Monitor,USB resource configuration
2026-07-06 09:36:35 +0530 IST,BIOS,Monitor,USB resource configuration
2026-07-06 09:36:34 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 09:36:34 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 09:36:34 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 09:36:34 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 09:36:34 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 08:57:28 +0530 IST,BIOS,Non-critical condition,Starting operating system boot process
2026-07-06 08:57:27 +0530 IST,Intel(r) ME,Monitor,Embedded controller/management controller initialization
2026-07-06 08:57:20 +0530 IST,BIOS,Monitor,USB resource configuration
2026-07-06 08:57:20 +0530 IST,BIOS,Monitor,USB resource configuration
2026-07-06 08:57:20 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 08:57:20 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 08:57:20 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 08:57:19 +0530 IST,BIOS,Monitor,PCI resource configuration
2026-07-06 08:57:19 +0530 IST,BIOS,Monitor,PCI resource configuration

The function calculated and updated startIndex but passed 0 to GetEventLog, breaking pagination. Now passes startIndex and eventLogBatchSize properly.

Fixes #1104
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.54%. Comparing base (cc77603) to head (db982ad).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1114      +/-   ##
==========================================
+ Coverage   43.44%   43.54%   +0.10%     
==========================================
  Files         143      143              
  Lines       13621    13621              
==========================================
+ Hits         5917     5931      +14     
+ Misses       7143     7126      -17     
- Partials      561      564       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes v1 AMT event-log CSV download pagination by correctly using the computed startIndex and a non-zero batch size when repeatedly calling GetEventLog, so the download endpoint can retrieve all pages.

Changes:

  • Add an eventLogBatchSize constant and use it (with startIndex) in the downloadEventLog pagination loop.
  • Correct the loop termination condition to stop when HasMoreRecords is false.
  • Add a controller test to assert downloadEventLog paginates by advancing startIndex between batches.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/controller/httpapi/v1/auditlog.go Fixes event-log download pagination to pass startIndex/batch size and stops when no more records are available.
internal/controller/httpapi/v1/auditlog_test.go Adds a test validating that the download endpoint paginates via successive GetEventLog calls with increasing startIndex.
Comments suppressed due to low confidence (1)

internal/controller/httpapi/v1/auditlog.go:136

  • The pagination loop can spin indefinitely if the device returns an empty batch while still reporting HasMoreRecords=true: startIndex won’t advance (+= len(eventLogs.Records)), so the next iteration repeats the same request forever. Adding a defensive break on empty batches avoids a hung download endpoint.
		// Break when no more records are available from AMT.
		if !eventLogs.HasMoreRecords {
			break
		}

		// Update the startIndex for the next batch
		startIndex += len(eventLogs.Records)

@sinchubhat sinchubhat requested review from nbmaiti and sudhir-intc July 6, 2026 04:45
@sudhir-intc

Copy link
Copy Markdown
Contributor

@sinchubhat : could you please capture the results without this PR fix and share the observations for the manual test you have done.

@sinchubhat

sinchubhat commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@sinchubhat : could you please capture the results without this PR fix and share the observations for the manual test you have done.

It does show all the event logs, but gets stuck if we click the download button. Even the curl cmd to download gets stuck.

we can also see below in console logs
{"level":"info","time":"2026-07-05T10:44:09+05:30","caller":"/usr/local/go/src/fmt/print.go:263","message":"[GIN] 2026/07/05 - 10:44:09 | 408 | 15.3s | 127.0.0.1 | GET "/api/v1/amt/log/event/GUID/download""}

issue1104-console-before-fix-1 issue1104-console-before-fix-2 issue1104-console-before-fix-3

@sinchubhat sinchubhat marked this pull request as ready for review July 6, 2026 05:57
@sinchubhat sinchubhat requested a review from a team as a code owner July 6, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

downloadEventLog uses startIndex but never passes to GetEventLog, so, download won't work

4 participants