Skip to content

Add --tag flag to agent for custom metric metadata#25

Merged
stympy merged 17 commits intomainfrom
custom-metadata-option
Apr 6, 2026
Merged

Add --tag flag to agent for custom metric metadata#25
stympy merged 17 commits intomainfrom
custom-metadata-option

Conversation

@stympy
Copy link
Copy Markdown
Member

@stympy stympy commented Mar 26, 2026

Summary

  • Adds a repeatable --tag key=value flag (short: -t) to hb agent so users can annotate metric events with custom metadata like environment, role, or a custom hostname
  • Tags can also be set via YAML config under agent.tags
  • CLI flags take precedence over config file tags
  • --tag host=foo overrides the auto-detected hostname; all other built-in metric fields (ts, event_type, used_percent, etc.) are reserved and rejected at startup with a clear error
  • Updates README with config and CLI examples

Test plan

  • Unit tests for tag parsing, merging, config loading, and reserved key validation
  • Integration tests verifying tags appear in all event types (CPU, memory, disk)
  • Integration test confirming host tag overrides auto-detected hostname
  • Verify --tag event_type=foo is rejected at startup

🤖 Generated with Claude Code

stympy and others added 10 commits March 26, 2026 13:57
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tags like --tag event_type=foo or --tag ts=... would overwrite core
payload fields and produce invalid Insights data. Now only "host" is
allowed as an override; all other built-in fields are rejected at
startup with a clear error message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 26, 2026 21:21
Group var declarations, wrap long lines in flag registration
and test assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for custom user-defined tags on hb agent metric events via a repeatable --tag/-t key=value flag and agent.tags config, with CLI tags overriding config.

Changes:

  • Added --tag/-t support to hb agent, with parsing, reserved-key validation, and config/CLI merging.
  • Updated metric submission so tags are injected into the JSON payload (including host override behavior).
  • Added unit/integration-style tests for tag parsing/merging and tag presence across submitted events; updated README examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
cmd/agent.go Implements tag flag/config loading, reserved key validation, and tag merging into metric payload JSON.
cmd/agent_test.go Adds coverage for tag parsing/merging, config loading, and verifying tags/host override appear in emitted events.
README.md Documents agent.tags config and --tag CLI usage examples, including hostname override.
Comments suppressed due to low confidence (1)

cmd/agent_test.go:242

  • reportMetrics is synchronous; the time.Sleep(2 * time.Second) here doesn’t cause additional events to be emitted and only slows the test. Consider removing the sleep and asserting on receivedEvents immediately after reportMetrics returns.
		err := reportMetrics("test-host", nil)
		require.NoError(t, err)

		// Wait for metrics to be reported
		time.Sleep(2 * time.Second)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/agent.go Outdated
stympy and others added 4 commits March 26, 2026 14:29
…c precision

Avoids float64 coercion of uint64 metric fields (e.g. total_bytes)
during the unmarshal/merge/remarshal roundtrip.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@stympy stympy requested a review from joshuap March 26, 2026 21:42
stympy and others added 2 commits March 26, 2026 14:43
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@stympy stympy requested review from a team and removed request for joshuap March 28, 2026 01:43
@stympy stympy merged commit 832d663 into main Apr 6, 2026
4 checks passed
@stympy stympy deleted the custom-metadata-option branch April 6, 2026 16:08
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.

3 participants