Skip to content

Add optional alias field for human-friendly machine names - #69

Merged
jantman merged 1 commit into
mainfrom
aliases
Nov 30, 2025
Merged

Add optional alias field for human-friendly machine names#69
jantman merged 1 commit into
mainfrom
aliases

Conversation

@jantman

@jantman jantman commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR introduces an optional alias field to the machines.json configuration schema, allowing human-friendly names to be used in Slack messages and log output instead of machine names.

Key Changes

  • Machine Model: Added optional alias field to configuration schema with display_name property that returns alias if present, otherwise machine name
  • Lookup Support: Added get_machine() method to MachinesConfig that supports lookup by either machine name or alias
  • Slack Integration: Updated all Slack messages and commands to use aliases, including support for multi-word aliases
  • Logging: Updated all log output to use display_name for better readability
  • Tests: Added comprehensive test coverage for alias functionality, including lookup by alias and multi-word alias support
  • Documentation: Updated CLAUDE.md, configuration.rst, and slack.rst to document the new feature

Backwards Compatibility

Machines without an alias configured continue to work exactly as before, using the machine name in all contexts.

Test Plan

  • All 155 existing tests pass with 99% coverage
  • Added new tests for Machine.display_name property
  • Added new tests for MachinesConfig.get_machine() lookup method
  • Added new test for Slack command using alias
  • Updated all affected test assertions
  • Pre-commit hooks pass (black, flake8, mypy, etc.)

🤖 Generated with Claude Code

…names

This update introduces an optional 'alias' field to the machines.json
configuration schema, allowing human-friendly names to be displayed in
Slack messages and log output instead of machine names.

Changes to Machine Model (src/dm_mac/models/machine.py):
- Added 'alias' field to CONFIG_SCHEMA as optional string
- Added 'alias' parameter to Machine.__init__()
- Added display_name property that returns alias if present, else name
- Updated MachinesConfig to build machines_by_alias lookup dictionary
- Added get_machine() method to support lookup by name or alias
- Updated all MachineState logging to use machine.display_name

Changes to Slack Handler (src/dm_mac/slack_handler.py):
- Updated machine_status() to display aliases in status output
- Updated all log_* methods to use machine.display_name in messages
- Modified oops(), lock(), and clear() commands to accept multi-word
  aliases by joining command parts with spaces
- Updated handle_command() to support commands with >= 2 parts
- Changed get_machine() calls to use new MachinesConfig.get_machine()
  method instead of direct machines_by_name dictionary access

Test Updates:
- Added alias to metal-mill in tests/fixtures/machines.json
- Added tests for Machine.display_name property behavior
- Added TestMachinesConfigGetMachine class with tests for lookup by
  name, alias, and non-existent machines
- Added test_handle_command_oops_by_alias() for alias command support
- Updated all Slack message assertions to expect aliases instead of
  machine names where applicable

Documentation Updates:
- Updated CLAUDE.md with alias field description and lookup behavior
- Updated docs/source/configuration.rst with alias field explanation
- Updated docs/source/slack.rst to document alias support in commands

All 155 tests passing with 99% coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/dm_mac
   __init__.py690100% 
   cli_utils.py150100% 
   neongetter.py1860100% 
   slack_handler.py1500100% 
   utils.py250100% 
src/dm_mac/models
   __init__.py00100% 
   machine.py361199%670
   users.py940100% 
src/dm_mac/views
   __init__.py00100% 
   api.py220100% 
   machine.py690100% 
   prometheus.py980100% 
TOTAL1089199% 

Tests Skipped Failures Errors Time
155 0 💤 0 ❌ 0 🔥 13.466s ⏱️

@jantman
jantman merged commit 4bcf1a7 into main Nov 30, 2025
16 checks passed
@jantman
jantman deleted the aliases branch November 30, 2025 13:51
jantman added a commit that referenced this pull request Nov 30, 2025
…oard

This commit adds a display_name label to all machine-based Prometheus metrics,
in addition to the existing machine_name label. The display_name uses the
machine's alias if configured, otherwise falls back to the machine name. This
provides human-friendly names in dashboards and queries while preserving the
technical machine_name for filtering and querying.

Changes to Prometheus Metrics (src/dm_mac/views/prometheus.py):
- Added display_name label to all 19 machine-specific metrics
- Both machine_name and display_name labels are now present on all metrics
- Used m.display_name property which returns alias if set, otherwise name
- Labels are alphabetically sorted: display_name, machine_name

Test Updates (tests/views/test_prometheus.py):
- Updated all expected metric outputs to include both labels
- Metal Mill machine shows display_name="Metal Mill" (uses alias)
- Other machines show display_name equal to machine_name (no alias)
- LED metrics updated to include display_name in addition to led_attribute

Documentation Updates (docs/source/admin.rst):
- Updated all metric examples to show both labels
- Examples now reflect the display_name label in output
- Metal Mill consistently shows display_name="Metal Mill"

Grafana Dashboard Updates (docs/source/grafana-dashboard.json):
- Changed all legendFormat from {{machine_name}} to {{display_name}}
- Updated template variable query to use display_name
- Dashboard now shows human-friendly names (aliases) in legends and labels
- Machine selector dropdown uses display_name for better UX

Dashboard Documentation (docs/source/grafana-dashboard.md):
- Updated metrics table to show both labels for machine metrics
- Updated template variable description
- Clarified that display_name uses alias if present

Benefits:
- Dashboards show human-friendly "Metal Mill" instead of "metal-mill"
- Preserves machine_name for programmatic filtering/querying
- Backward compatible - both labels available for PromQL queries
- Consistent with existing display_name property from PR #69

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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