Skip to content

Commit

Permalink
Added the cluster namesapce to handle the metrics between stage and prod
Browse files Browse the repository at this point in the history
  • Loading branch information
jayamala17 committed May 23, 2024
1 parent 401af8b commit 1bae19d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ APTRUST_REMOTE_SETTINGS_AWS_SECRET_ACCESS_KEY=

# Metrics push gateway url
PROMETHEUS_PUSH_GATEWAY=http://pushgateway:9091
CLUSTER_NAMESPACE=test-ns
6 changes: 5 additions & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def get_subset_by_key_stem(stem)
Metrics = Struct.new(
"MetricsConfig",
:push_gateway_url,
:cluster_namespace,
keyword_init: true
)

Expand Down Expand Up @@ -327,7 +328,10 @@ def self.create_config(data)
),
remote: create_remote_config(data.get_subset_by_key_stem("APTRUST_REMOTE_"))
),
metrics: Metrics.new(push_gateway_url: data.get_value(key: "PROMETHEUS_PUSH_GATEWAY"))
metrics: Metrics.new(
push_gateway_url: data.get_value(key: "PROMETHEUS_PUSH_GATEWAY"),
cluster_namespace: data.get_value(key: "CLUSTER_NAMESPACE")
)
)
end

Expand Down
4 changes: 3 additions & 1 deletion lib/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MetricsProvider
def initialize(
status_event_repo:,
push_gateway_url:,
cluster_namespace:,
start_time:,
end_time:,
registry: nil
Expand All @@ -28,6 +29,7 @@ def initialize(
@end_time = end_time
@status_event_repo = status_event_repo
@push_gateway_url = push_gateway_url
@cluster_namespace = cluster_namespace
@registry = registry
end

Expand Down Expand Up @@ -88,7 +90,7 @@ def set_processing_duration

def gateway
@gateway ||= Prometheus::Client::Push.new(
job: "DarkBlueMetric",
job: @cluster_namespace,
gateway: @push_gateway_url
)
end
Expand Down
3 changes: 2 additions & 1 deletion run_dark_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def self.parse(options)
start_time: start_time,
end_time: end_time,
status_event_repo: S.status_event_repo,
push_gateway_url: config.metrics.push_gateway_url
push_gateway_url: config.metrics.push_gateway_url,
cluster_namespace: config.metrics.cluster_namespace
)
metrics.set_all_metrics
2 changes: 2 additions & 0 deletions test/test_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def setup
@end_time = @start_time + 5
@status_event_repo = StatusEventRepository::StatusEventInMemoryRepository.new
@push_gateway_url = "http://fake.pushgateway"
@cluster_namespace = "test-ns"

@registry_mock = Minitest::Mock.new
@gauge_mock = Minitest::Mock.new
Expand All @@ -23,6 +24,7 @@ def setup
end_time: @end_time,
status_event_repo: @status_event_repo,
push_gateway_url: @push_gateway_url,
cluster_namespace: @cluster_namespace,
registry: @registry_mock
)
end
Expand Down

0 comments on commit 1bae19d

Please sign in to comment.