-
Notifications
You must be signed in to change notification settings - Fork 16
Create the configuration for a dedicated metrics publishing service #6726
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "../config/environment" | ||
| require "prometheus_exporter/instrumentation" | ||
|
|
||
| PrometheusExporter::Instrumentation::SidekiqStats.start | ||
| PrometheusExporter::Instrumentation::SidekiqQueue.start(all_queues: true) | ||
|
|
||
| at_exit { PrometheusExporter::Client.default.stop(wait_timeout_seconds: 10) } | ||
|
|
||
| Kernel.sleep | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,18 +27,31 @@ def fetch_ecs_task_id | |||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ARGV.include?("local") | ||||||||||||||||||||||||||||||||||
| task_id = "N/A" | ||||||||||||||||||||||||||||||||||
| service_name = "N/A" | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| task_id = fetch_ecs_task_id | ||||||||||||||||||||||||||||||||||
| service_name = ENV["SERVICE_NAME"] | ||||||||||||||||||||||||||||||||||
| # An explicitly-set env var (including empty string) overrides the default. | ||||||||||||||||||||||||||||||||||
| # An empty value omits the label entirely — useful for the metrics task, | ||||||||||||||||||||||||||||||||||
| # whose series identity must stay stable across container replacements. | ||||||||||||||||||||||||||||||||||
| def resolve_label(env_key, &default) | ||||||||||||||||||||||||||||||||||
| if ENV.key?(env_key) | ||||||||||||||||||||||||||||||||||
| value = ENV[env_key] | ||||||||||||||||||||||||||||||||||
| return value.empty? ? nil : value | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| default.call | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| labels = { | ||||||||||||||||||||||||||||||||||
| "TaskId" => resolve_label("PROMETHEUS_TASK_ID_LABEL") do | ||||||||||||||||||||||||||||||||||
| ARGV.include?("skip-server-labels") ? nil : fetch_ecs_task_id | ||||||||||||||||||||||||||||||||||
| end, | ||||||||||||||||||||||||||||||||||
| "ServiceName" => resolve_label("PROMETHEUS_SERVICE_NAME_LABEL") do | ||||||||||||||||||||||||||||||||||
| ARGV.include?("skip-server-labels") ? nil : ENV["SERVICE_NAME"] | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
| }.compact | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+49
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would've expected If I'm right, simply swapping the
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| runner = PrometheusExporter::Server::Runner.new( | ||||||||||||||||||||||||||||||||||
| port: 9394, | ||||||||||||||||||||||||||||||||||
| bind: "0.0.0.0", | ||||||||||||||||||||||||||||||||||
| label: { "TaskId" => task_id, "ServiceName" => service_name }, | ||||||||||||||||||||||||||||||||||
| label: labels, | ||||||||||||||||||||||||||||||||||
| type_collectors: [PrometheusExporter::CustomActiveRecordCollector], | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to load the entire Rails env? Or is this just to load bundler so we can require
prometheus_exporter/instrumentation? Just looking atPrometheusExporter::CustomActiveRecordCollectorit's not clear to me that all of Rails is needed.