Skip to content

Do not emit partition_remove_hook and CDR compaction hook metrics whe… - #2077

Merged
dmitry-sinina merged 4 commits into
yeti-switch:masterfrom
dmitry-sinina:_do_not_emit_metrics_on_disabled_hooks
Aug 10, 2026
Merged

Do not emit partition_remove_hook and CDR compaction hook metrics whe…#2077
dmitry-sinina merged 4 commits into
yeti-switch:masterfrom
dmitry-sinina:_do_not_emit_metrics_on_disabled_hooks

Conversation

@dmitry-sinina

Copy link
Copy Markdown
Contributor

…n hooks are disabled

Copilot AI lite review requested due to automatic review settings August 10, 2026 08:45

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

Updates Prometheus hook collectors so they don’t export permanently-zero metric series when the corresponding optional shell hooks are not configured, preventing false “hook has not run” alerts for disabled features.

Changes:

  • Add HookConfig.configured? helper to detect whether a hook command is configured in YetiConfig.
  • Gate “seed zeros at process start” behavior in PartitionRemoveHookCollector and CdrCompactionHookCollector behind hook configuration.
  • Extend collectors’ specs and add new HookConfig specs to cover configured/unconfigured behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
spec/lib/prometheus/partition_remove_hook_collector_spec.rb Adds coverage ensuring no metrics are exported when the hook is unconfigured (but still records reported data).
spec/lib/prometheus/hook_config_spec.rb New unit tests for hook configuration detection, including error-path behavior.
spec/lib/prometheus/cdr_compaction_hook_collector_spec.rb Mirrors partition-remove tests for the CDR compaction hook collector.
lib/prometheus/partition_remove_hook_collector.rb Adds seed_zeros: parameter and skips zero seeding when the hook is not configured.
lib/prometheus/hook_config.rb Introduces centralized hook configuration detection used by collectors.
lib/prometheus/cdr_compaction_hook_collector.rb Adds seed_zeros: parameter and skips zero seeding when the hook is not configured.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +11 to +14
# The zero seed is skipped when no partition_remove_hook is configured: Jobs::PartitionRemoving
# then never runs a hook and never reports, so seeded counters would export a permanently-zero
# series for a feature that is switched off. Without the seed the counters carry no series at all
# (only HELP/TYPE headers), which is what an unconfigured hook should look like.
Comment thread lib/prometheus/hook_config.rb Outdated
Comment on lines +15 to +24
def configured?(name)
YetiConfig.public_send(name).present?
rescue StandardError => e
# YetiConfig is absent when config/yeti_web.yml could not be loaded (see YetiConfigLoader).
# Without it we cannot tell a configured hook from an absent one; not seeding is the quieter
# of the two guesses.
warn "HookConfig: #{e.class} #{e.message}"
false
end
end

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

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

Suppressed comments (4)

lib/prometheus/partition_remove_hook_collector.rb:5

  • collector_labels.rb already requires ../prometheus_config, so this additional require is redundant here and can be removed to avoid duplicated load paths and keep dependencies centralized.
require_relative './collector_labels'
require_relative '../prometheus_config'

lib/prometheus/cdr_compaction_hook_collector.rb:5

  • collector_labels.rb already requires ../prometheus_config, so this additional require is redundant here and can be removed to avoid duplicated load paths and keep dependencies centralized.
require_relative './collector_labels'
require_relative '../prometheus_config'

spec/lib/prometheus_config_spec.rb:11

  • This example currently relies on the real config/yeti_web.yml default (hooks commented out) to make the unconfigured case false. That makes the spec brittle if defaults change or the test config differs. Stub the config key explicitly so the example remains self-contained.
    it 'is false when the hook is not configured' do
      expect(subject).to be(false)
    end

lib/yeti_config_loader.rb:30

  • YetiConfigLoader.call checks File.exist?, which also returns true for directories. If a directory is accidentally passed, the subsequent Config.load_and_set_settings will fail with a less clear error. Use File.file? to ensure the path is an actual file before proceeding.
    # Config.load_and_set_settings does not object to a path that does not exist: it defines an
    # empty YetiConfig and returns, so the absence has to be caught here. Checked before
    # Config.setup so a failure leaves no half-applied global configuration behind.
    raise Error, "config file not found: #{path}" unless File.exist?(path)

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

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

Comment thread lib/yeti_config_loader.rb
Comment on lines +34 to +35
rescue Config::Validation::Error => e
raise Error, "invalid config #{path}: #{e.message}"
@dmitry-sinina
dmitry-sinina merged commit 498cc61 into yeti-switch:master Aug 10, 2026
17 checks passed
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.

2 participants