Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable metrics for deploy config #2482

Merged
merged 4 commits into from Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
fmoehler marked this conversation as resolved.
Show resolved Hide resolved

deploy_config.each do |config|
return true
end
false
fmoehler marked this conversation as resolved.
Show resolved Hide resolved
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
fmoehler marked this conversation as resolved.
Show resolved Hide resolved
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