Skip to content

Conversation

@lujunsan
Copy link
Contributor

@lujunsan lujunsan commented Dec 4, 2025

Summary

Adds a new API endpoint to enable or disable usage metrics collection, allowing the Toolhive UI to control this configuration setting. Both the CLI and API now use shared provider methods for consistency.

Changes

API Endpoints

  • GET /api/v1beta/config/usage-metrics - Get current usage metrics status
  • PUT /api/v1beta/config/usage-metrics - Enable or disable usage metrics

New Files

  • pkg/config/usagemetrics.go - Shared provider methods for usage metrics operations
  • pkg/config/usagemetrics_test.go - Comprehensive tests for provider operations
  • pkg/api/v1/config.go - Config API router with usage metrics endpoints
  • pkg/api/v1/config_test.go - API endpoint tests

Modified Files

  • pkg/config/interface.go - Added SetUsageMetricsEnabled() and GetUsageMetricsEnabled() to Provider interface
  • pkg/api/server.go - Registered config router at /api/v1beta/config
  • cmd/thv/app/config.go - Refactored CLI to use provider methods

Design Decisions

  1. API uses "enabled" not "disabled" - More intuitive UX ({"enabled": true} vs {"disabled": false})
  2. Shared provider methods - Both CLI and API use the same code path for consistency
  3. Follows existing patterns - Matches the CA cert and registry configuration approach
  4. PUT method - Idempotent updates to existing config value

Testing

  • ✅ All API endpoint tests pass (GET, PUT, error cases)
  • ✅ All config provider tests pass (all provider types)
  • ✅ Tests verify config persistence and omitempty YAML behavior
  • ✅ Existing tests continue to pass

Example Usage

# Get current status
curl http://localhost:8080/api/v1beta/config/usage-metrics

# Disable usage metrics
curl -X PUT http://localhost:8080/api/v1beta/config/usage-metrics \
  -H "Content-Type: application/json" \
  -d '{"enabled": false}'

# Enable usage metrics
curl -X PUT http://localhost:8080/api/v1beta/config/usage-metrics \
  -H "Content-Type: application/json" \
  -d '{"enabled": true}'

…toring

Signed-off-by: lujunsan <luisjuncaldev@gmail.com>
@lujunsan lujunsan requested review from ChrisJBurns and dmjb December 4, 2025 15:29
@github-actions github-actions bot added the size/L Large PR: 600-999 lines changed label Dec 4, 2025
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 63.23529% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.39%. Comparing base (0c0d907) to head (829c05f).

Files with missing lines Patch % Lines
pkg/api/v1/config.go 59.09% 15 Missing and 3 partials ⚠️
pkg/config/interface.go 66.66% 4 Missing ⚠️
pkg/config/usagemetrics.go 81.81% 1 Missing and 1 partial ⚠️
pkg/api/server.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2902      +/-   ##
==========================================
+ Coverage   56.36%   56.39%   +0.02%     
==========================================
  Files         323      325       +2     
  Lines       31764    31832      +68     
==========================================
+ Hits        17904    17951      +47     
- Misses      12331    12348      +17     
- Partials     1529     1533       +4     

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants