Skip to content

feat(telemetry): wire desktop Registration Client metrics to TUSD ingestion backend - #818

Open
yakshithkd23 wants to merge 3 commits into
mosip:developfrom
yakshithkd23:tel_metric_yak01
Open

yakshithkd23 wants to merge 3 commits into
mosip:developfrom
yakshithkd23:tel_metric_yak01

Conversation

@yakshithkd23

@yakshithkd23 yakshithkd23 commented Jun 24, 2026 •

Copy link
Copy Markdown

Summary

This PR implements the client-side telemetry upload layer for the Desktop Registration Client as part of issue mosip/android-registration-client#719.

The MOSIP Registration Client already collects JVM and application metrics using the existing LoggingJsonMeterRegistry (Micrometer). This PR provides the missing link: a scheduled upload service that transmits these pre-collected metrics to the backend ingestion pipeline implemented in mosip/tusd-server#14.


Historical Context & Evolution

During the initial development and review process against the master branch, the implementation began as a standalone TelemetryUploadService.java. Following architectural feedback to improve maintainability, we refactored the design:

  1. Initial Attempt: Created a dedicated TelemetryUploadService to handle the TUS-based transport logic.

  2. Refinement: During the transition to the develop branch, we identified that merging the scheduling and transport logic into the existing MetricsConfig.java would better align with the project's architecture and avoid unnecessary service fragmentation.

  3. Final Approach: Consolidated the upload logic into MetricsConfig.java. This ensures that the telemetry transport is handled as a natural extension of the metric configuration provided by the MOSIP framework.


Problem

While the MOSIP LoggingJsonMeterRegistry was already correctly collecting and writing telemetry metrics to metrics.log, there was no mechanism to upload these logs to the server. Consequently, telemetry data remained trapped on local disks, preventing centralized monitoring of JVM health, resource utilization, and application performance.


Solution

Integrated the upload transport logic into MetricsConfig.java:

  1. Scheduling: Enabled Spring @EnableScheduling in AppConfig.java.

  2. Upload Logic: Implemented the task within MetricsConfig to utilize the existing telemetry setup.

  3. TUS Integration: Integrated tus-java-client:0.4.3 to handle reliable, resumable chunked uploads of the existing metrics.log file to the mosip-tusd server.

  4. Resilience: The implementation respects the existing log lifecycle—ensuring the file is only deleted after a successful TUS upload, with automatic retries on failure.


Architecture

Plaintext
Desktop Registration Client (JavaFX / Spring Boot)
│
▼
LoggingJsonMeterRegistry (Existing MOSIP Implementation)
│ Writes JSON metrics to metrics.log
│
▼
MetricsConfig (Updated with TUS Transport)
 - Scheduled task (@Scheduled - 15m intervals)
 - TUS Client integration (tus-java-client 0.4.3)
│
│ HTTP TUS Protocol
▼
mosip-tusd server  ← mosip/tusd-server#14
│
▼
Vector sidecar → Kafka Topic (registration-client-telemetry)

Files Changed

File | Change -- | -- MetricsConfig.java | Refactored: Added scheduled upload logic + TUS integration AppConfig.java | Enabled @EnableScheduling mosip-application.properties | Added telemetry/TUS configuration properties

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Enables Spring scheduling in AppConfig and adds a new TelemetryUploadService that periodically reads a local metrics.log file and uploads it to a configured TUS server using resumable uploads, deleting the file on success. New application properties configure the TUS server URL, chunk size, and log path.

Changes

Telemetry Upload via TUS

Layer / File(s) Summary
Upload configuration properties and scheduling enablement
registration/registration-services/src/main/resources/props/mosip-application.properties, registration/registration-services/src/main/java/io/mosip/registration/config/AppConfig.java
Adds mosip.registration.tus.server.url, mosip.registration.tus.server.upload.chunksize, and mosip.registration.metrics.log.path properties, and enables @EnableScheduling on AppConfig.
TelemetryUploadService implementation
registration/registration-services/src/main/java/io/mosip/registration/config/TelemetryUploadService.java
Adds a scheduled (fixedDelay = 30000) service that validates the local metrics.log file, uploads it in chunks to a TUS server via resumable upload, finishes the upload, and deletes the local file on success while retaining it on failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Scheduler
  participant TelemetryUploadService
  participant TusClient
  participant TUSServer

  Scheduler->>TelemetryUploadService: scheduledUpload() every 30s
  TelemetryUploadService->>TelemetryUploadService: locate metrics.log
  TelemetryUploadService->>TusClient: configure uploadCreationURL + TusURLMemoryStore
  TelemetryUploadService->>TusClient: resumeOrCreateUpload(tusUpload)
  loop upload chunks
    TusClient->>TUSServer: PATCH chunk
    TUSServer-->>TusClient: offset ack
    TelemetryUploadService->>TusClient: uploadChunk()
  end
  TusClient->>TUSServer: finish upload
  TelemetryUploadService->>TelemetryUploadService: delete metrics.log (if upload succeeded)
Loading

Poem

A rabbit hops with metrics in tow,
Chunk by chunk, uploads that flow.
Thirty seconds tick, then off it goes,
To the TUS server, where the log data flows.
🐇📦✨ Clean file, happy hop!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: wiring Registration Client metrics into the TUSD ingestion backend.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@registration/registration-services/src/main/java/io/mosip/registration/config/TelemetryUploadService.java`:
- Around line 26-28: There are now two scheduled telemetry upload paths using
the same TUS config and metrics file, so consolidate the logic into one
scheduler and remove/disable the duplicate. Update TelemetryUploadService and
the existing scheduled exporter in MetricsConfig to keep a single upload flow
for metrics.log, then ensure only one job performs upload and cleanup to avoid
races, double-sends, and conflicting deletions.
- Around line 56-57: The upload flow in
TelemetryUploadService.uploadFileToTusServer is operating on the live
metrics.log that LoggingJsonMeterRegistry is still writing to, which risks
losing or splitting entries and deleting data produced during upload. Change the
upload path to use a rotated or snapshotted copy of the log instead of the
active writer target, and update the cleanup logic in the upload flow so it only
removes the temporary snapshot after a successful transfer.
- Around line 41-45: The scheduled upload in
TelemetryUploadService.scheduledUpload is still using the temporary test cadence
instead of the production interval. Update the `@Scheduled` fixedDelay value back
to 15 minutes (900000 ms), or gate the shorter delay behind a test-only profile
so production behavior remains unchanged.
- Around line 64-72: The resumable upload setup in TelemetryUploadService
currently uses a fresh TusURLMemoryStore, so retry runs cannot recover the
previous upload URL. Update the upload flow in the method that creates the
TusClient to reuse the existing MetricsURLMemoryStore instead of constructing a
new in-memory store, so resumeOrCreateUpload can continue the same upload across
scheduled retries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7482eff3-bca9-4586-b84b-8ffa9b7285cc

📥 Commits

Reviewing files that changed from the base of the PR and between 22fe01f and a8be324.

📒 Files selected for processing (4)
  • registration/registration-services/pom.xml
  • registration/registration-services/src/main/java/io/mosip/registration/config/AppConfig.java
  • registration/registration-services/src/main/java/io/mosip/registration/config/TelemetryUploadService.java
  • registration/registration-services/src/main/resources/props/mosip-application.properties

…estion backend

Signed-off-by: Yakshith K D <yakshithkd97@gmail.com>
…estion backend

- Add TelemetryUploadService to upload metrics.log via TUS protocol
- Enable @EnableScheduling in AppConfig for scheduled uploads
- Add TUS server URL, chunk size, and metrics log path config

Signed-off-by: Yakshith K D <yakshithkd97@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@registration/registration-services/src/main/java/io/mosip/registration/config/TelemetryUploadService.java`:
- Line 27: Remove the redundant `@EnableScheduling` annotation from
TelemetryUploadService, since scheduling is already enabled in AppConfig; keep
the `@Service` focused on service behavior and leave the scheduling enablement
only on the configuration class.
- Around line 56-63: The upload path in
TelemetryUploadService.uploadFileToTusServer currently sends metrics.log as-is,
but that file can contain sensitive `@MetricTag` values produced by
MetricsConfig.tagFactory and written verbatim by LoggingJsonMeterRegistry. Add a
sanitization step before the upload begins that whitelists allowed tags or
redacts sensitive ones (such as userid) from the file contents, and make sure
the cleaned file is what gets egressed instead of the raw metrics log.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fc9329f7-71e1-44e5-be6a-641b40df3073

📥 Commits

Reviewing files that changed from the base of the PR and between a8be324 and 7a01e7c.

📒 Files selected for processing (3)
  • registration/registration-services/src/main/java/io/mosip/registration/config/AppConfig.java
  • registration/registration-services/src/main/java/io/mosip/registration/config/TelemetryUploadService.java
  • registration/registration-services/src/main/resources/props/mosip-application.properties

MetricsConfig.java already contains the complete TUS upload scheduler
(exportMetrics, @scheduled every 15 min, TusExecutor with retry,
MetricsURLMemoryStore for resumable uploads).

TelemetryUploadService.java was a duplicate that would race with
MetricsConfig.exportMetrics() on the same file. Removed to keep
a single upload path.

Previous commit adds tus-java-client dependency and TUS config keys
to activate the existing MetricsConfig.exportMetrics() scheduler.

Signed-off-by: Yakshith K D <yakshithkd97@gmail.com>

@yakshithkd23 yakshithkd23 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Wired desktop registration client metrics to Tusd ingestion backend

@yakshithkd23

Copy link
Copy Markdown
Author

Hi Team,

I have finalized the changes for the Telemetry TUSD upload integration. To summarize the progression and current state of this PR:

  1. Context: Initially, the Registration Client was only logging metrics locally via LoggingJsonMeterRegistry. Per team feedback, I moved the development to the develop branch to implement the TUSD upload capability.
  2. Rationalization & Cleanup: I identified that the MetricsConfig class contained legacy TUSD upload logic similar to the TelemetryUploadService I initially proposed. To avoid code duplication and maintain a clean architecture, I have consolidated the upload logic, ensuring it aligns with the MOSIP telemetry schema and protocol requirements.
  3. Changes: This PR now includes minor, targeted updates across three key files to enable the scheduled upload service without redundant code:
  • AppConfig.java: Enabled @EnableScheduling to support the upload task.
  • mosip-application.properties: Added the necessary TUSD server configuration properties.
  • MetricsConfig.java: Optimized to handle the upload flow, leveraging the existing architecture while ensuring data is correctly pushed to the TUSD endpoint.

All end-to-end verifications, including scheduled execution and successful TUSD ingestion, have been validated. I believe this approach meets the requirements for a cloud-native telemetry pipeline while keeping the codebase maintainable.

Please let me know if any further adjustments are required. I am ready for final review and merge.


@yakshithkd23

Copy link
Copy Markdown
Author

Hi team, quick update on the latest changes:

I have finalized the telemetry integration. I performed a review of the develop branch and confirmed that the TUSD upload logic and necessary metrics configuration were already present in MetricsConfig.java. To avoid code duplication and maintain a clean architecture, I have kept the existing implementation rather than creating a redundant service.

Summary of changes:

AppConfig.java: Added @EnableScheduling to trigger the automated upload task.

mosip-application.properties: Added the required TUSD server configuration keys (url, chunksize, log.path).

I have validated that the existing MetricsConfig logic correctly handles the JSON schema and TUS protocol as per MOSIP requirements. Everything is functioning as expected. Please review these final changes. Thanks!

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.

1 participant