Skip to content

Commit

Permalink
Introduce monitoring metrics for deploy config enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoehler committed Dec 18, 2023
1 parent 5e12384 commit 1874004
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jobs/director/templates/indicator.yml.erb
Expand Up @@ -25,6 +25,8 @@ spec:
type: "Type of the task (e.g. update_deployment, snapshot_deployment...)"
- name: bosh_resurrection_enabled
promql: bosh_resurrection_enabled
- name: bosh_deploy_config_enabled
promql: bosh_deploy_config_enabled
- name: bosh_networks_dynamic_ips_total
promql: bosh_networks_dynamic_ips_total
documentation:
Expand Down
9 changes: 9 additions & 0 deletions src/bosh-director/lib/bosh/director/api/config_manager.rb
Expand Up @@ -13,6 +13,15 @@ def create(type, name, config_yaml, team_id = nil)
config.save
end

def deploy_config_enabled?
deploy_config = find(type: 'deploy', limit: 999)

deploy_config.each do |config|
return true
end
false
end

def find(type: nil, name: nil, limit: 1)
dataset = Bosh::Director::Models::Config.where(deleted: false)
dataset = dataset.where(type: type) if type
Expand Down
6 changes: 6 additions & 0 deletions src/bosh-director/lib/bosh/director/metrics_collector.rb
Expand Up @@ -10,6 +10,11 @@ def initialize(config)
@config = config
@logger = config.metrics_server_logger

@deploy_config_enabled = Prometheus::Client.registry.gauge(
:bosh_deploy_config_enabled,
docstring: 'Is a config of type deploy uploaded? 0 for no, 1 for yes',
)

@resurrection_enabled = Prometheus::Client.registry.gauge(
:bosh_resurrection_enabled,
docstring: 'Is resurrection enabled? 0 for disabled, 1 for enabled',
Expand Down Expand Up @@ -82,6 +87,7 @@ def ensure_migrations
def populate_metrics
@logger.info('populating metrics')

@deploy_config_enabled.set(Api::ConfigManager.deploy_config_enabled? ? 1 : 0)
@resurrection_enabled.set(Api::ResurrectorManager.new.pause_for_all? ? 0 : 1)

metrics = { 'processing' => {}, 'queued' => {} }
Expand Down
14 changes: 14 additions & 0 deletions src/bosh-director/spec/unit/api/config_manager_spec.rb
Expand Up @@ -282,5 +282,19 @@
end
end

describe '#deploy_config_enabled?' do
context 'when config of type deploy does not exist' do
it "returns 'false'" do
expect(manager.deploy_config_enabled?).to eq(false)
end
end

context 'when config of type deploy does not exist' do
let!(:config_id) { Bosh::Director::Models::Config.make(type: 'deploy', name: 'my-name') }

it "returns 'true'" do
expect(manager.deploy_config_enabled?).to eq(true)
end
end
end
end
12 changes: 12 additions & 0 deletions src/bosh-director/spec/unit/metrics_collector_spec.rb
Expand Up @@ -23,12 +23,14 @@ def tick
allow(Rufus::Scheduler).to receive(:new).and_return(scheduler)
allow(Api::ResurrectorManager).to receive(:new).and_return(resurrector_manager)
allow(resurrector_manager).to receive(:pause_for_all?).and_return(false, true, false)
allow(Api::ConfigManager).to receive(:deploy_config_enabled?).and_return(true, false)
stub_request(:get, /unresponsive_agents/)
.to_return(status: 200, body: JSON.dump('flaky_deployment' => 1, 'good_deployment' => 0))
end

after do
Prometheus::Client.registry.unregister(:bosh_resurrection_enabled)
Prometheus::Client.registry.unregister(:bosh_deploy_config_enabled)
Prometheus::Client.registry.unregister(:bosh_tasks_total)
Prometheus::Client.registry.unregister(:bosh_networks_dynamic_ips_total)
Prometheus::Client.registry.unregister(:bosh_networks_dynamic_free_ips_total)
Expand All @@ -46,6 +48,16 @@ def tick
end
end

describe 'deploy_config_enabled' do
it 'populates the metrics every 30 seconds' do
metrics_collector.start
expect(scheduler.interval_duration).to eq('30s')
expect(Prometheus::Client.registry.get(:bosh_deploy_config_enabled).get).to eq(1)
scheduler.tick
expect(Prometheus::Client.registry.get(:bosh_deploy_config_enabled).get).to eq(0)
end
end

describe 'network metrics' do
let(:manual_network_spec) do
{
Expand Down

0 comments on commit 1874004

Please sign in to comment.