Skip to content

feat: add discovery timestamps to deviceInfo#1441

Open
sinchubhat wants to merge 1 commit into
mainfrom
issue1394-rpc-go
Open

feat: add discovery timestamps to deviceInfo#1441
sinchubhat wants to merge 1 commit into
mainfrom
issue1394-rpc-go

Conversation

@sinchubhat

@sinchubhat sinchubhat commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Add firstDiscovered (immutable) and rename lastUpdated to lastSynced.

Related to #1394

Depends on device-management-toolkit/console#1136

Description:

Field When set Mutable?
firstDiscovered first discovery (discovered=true only) no (write-once)
discovered device creation no (write-once)
lastSynced every sync yes (advances)

Note: lastUpdated is renamed to lastSynced; console maps the legacy lastUpdated on read so existing console keep working.

Observe the fields from the output:
discovered, firstDiscovered and lastSynced

Query from host

TOKEN=$(curl -sk https://localhost:8181/api/v1/authorize -H "Content-Type: application/json" -d '{"username":"<username>","password":"<password>"}' | jq -r '.token') && curl -sk https://localhost:8181/api/v1/devices -H "Authorization: Bearer $TOKEN" | jq '[.[] | {hostname, guid, deviceInfo}]'

Sync before activation:
discovered=true; firstDiscovered and lastSynced are equal:

sudo ./rpc amtinfo --sync --url https://<host_ip_addr>:8181/api/v1/devices \
  --auth-endpoint https://<host_ip_addr>:8181/api/v1/authorize \
  --auth-username <username> --auth-password "<password>" \
  --skip-cert-check --log-level=debug -v

Example:

"deviceInfo": {
  "discovered": true,
  "firstDiscovered": "2026-07-14T07:23:12Z",
  "lastSynced": "2026-07-14T07:23:12Z"
}

Activate directly:
discovered=false; firstDiscovered omitted; lastSynced set.
Use any one of below command:

sudo ./rpc activate --local --profile profile.yaml \
--key "<profile_key>" \
--skip-amt-cert-check --skip-cert-check \
--auth-endpoint "https://<host_ip_addr>:8181/api/v1/authorize" \
--auth-username <username> --auth-password "<password>" -v --log-level=debug

or

sudo ./rpc activate --url "https://<console-host>/api/v1/admin/profiles/export/<profile-name>?domainName=<domain-name>" --auth-username <username> --auth-password <password> --skip-amt-cert-check --skip-cert-check -v --log-level=debug

or

sudo ./rpc activate --profile <path-to-profile-file> --key <32-byte-key> --auth-endpoint https://<console-host>/api/v1/authorize --auth-username <username> --auth-password <password> --skip-amt-cert-check --log-level=debug -v --skip-cert-check

On later syncs: discovered and firstDiscovered stay unchanged (immutable); only lastSynced advances.
Full deactivation deletes the console record, so a later sync/activate creates a new record - firstDiscovered and discovered are set fresh:

sudo ./rpc deactivate --local --skip-amt-cert-check --skip-cert-check \
  --auth-endpoint "https://<host_ip_addr>:8181/api/v1/authorize" \
  --auth-username "<username>" \
  --auth-password "<password>" -v --log-level=debug

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

Adds discovery-related timestamp fields to the device sync payloads sent to Console, improving device lifecycle observability by distinguishing “first seen” vs “last sync” times and clarifying semantics via a field rename.

Changes:

  • Introduces deviceInfo.firstDiscovered (write-once) and deviceInfo.lastSynced (advances each sync), replacing the prior deviceInfo.lastUpdated.
  • Ensures lastSynced is stamped once per sync attempt and reused across the 404 auto-register POST + retry PATCH flow so timestamps agree.
  • Adds test coverage validating timestamp behavior for existing devices and 404 auto-register scenarios for both discovered and explicitly provisioned devices.

Reviewed changes

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

File Description
internal/device/api.go Updates the shared DeviceInfo API shape to include firstDiscovered and rename lastUpdatedlastSynced.
internal/commands/amtinfo.go Stamps and sends lastSynced on every sync; stamps firstDiscovered only on POST create when discovered=true; updates POST fallback to reuse the same sync timestamp.
internal/commands/amtinfo_test.go Adds comprehensive tests asserting correct presence/absence and equality invariants for firstDiscovered / lastSynced across sync scenarios.

Add firstDiscovered (immutable) and rename lastUpdated to lastSynced.

Related to #1394
@sinchubhat
sinchubhat force-pushed the issue1394-rpc-go branch 2 times, most recently from 8d50265 to 3607f94 Compare July 17, 2026 04:43
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.

Add discovery timestamps to device sync payloads

4 participants