-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build out the publishing latency SLI
* Fetches Whitehall events from Logit * Fetches Content Store events from Logit * Turns those events into metrics * Sends those metrics to Prometheus's PushGateway In case it's not obvious what's happening with the `OFFSET_MINUTES` and `INTERVAL_MINUTES` here, I've explained the motivation for `from_time` and `to_time` in the commits that introduced `WhitehallEvents` and `ContentStoreEvents`.
- Loading branch information
Showing
3 changed files
with
213 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
require "prometheus/client" | ||
require "prometheus/client/push" | ||
|
||
require "govuk_sli_collector/publishing_latency_sli/content_store_events" | ||
require "govuk_sli_collector/publishing_latency_sli/logit_search" | ||
require "govuk_sli_collector/publishing_latency_sli/record_metrics" | ||
require "govuk_sli_collector/publishing_latency_sli/whitehall_events" | ||
|
||
module GovukSliCollector | ||
class PublishingLatencySli | ||
def call; end | ||
def initialize | ||
@logit_search = LogitSearch.new( | ||
host: ENV.fetch("LOGIT_OPENSEARCH_HOST"), | ||
basic_auth: ENV.fetch("LOGIT_OPENSEARCH_BASIC_AUTH"), | ||
) | ||
@prometheus_pushgateway_url = ENV.fetch("PROMETHEUS_PUSHGATEWAY_URL") | ||
@to_time = minutes_ago(Integer(ENV.fetch("OFFSET_MINUTES"))) | ||
@from_time = @to_time - minutes(Integer(ENV.fetch("INTERVAL_MINUTES"))) | ||
end | ||
|
||
def call | ||
whitehall_events = WhitehallEvents.new(logit_search:).call( | ||
from_time:, | ||
to_time:, | ||
) | ||
|
||
return if whitehall_events.empty? | ||
|
||
content_store_events = ContentStoreEvents.new(logit_search:).call( | ||
from_time:, | ||
matching: whitehall_events, | ||
) | ||
|
||
return if content_store_events.empty? | ||
|
||
prometheus_registry = Prometheus::Client.registry | ||
|
||
RecordMetrics.new(prometheus_registry:).call( | ||
whitehall_events:, | ||
content_store_events:, | ||
) | ||
|
||
Prometheus::Client::Push.new( | ||
job: "govuk_sli_collector_publishing_latency_sli", | ||
gateway: prometheus_pushgateway_url, | ||
).add(prometheus_registry) | ||
end | ||
|
||
private | ||
|
||
attr_reader :logit_search, | ||
:prometheus_pushgateway_url, | ||
:from_time, | ||
:to_time | ||
|
||
def minutes(number_of) | ||
number_of * 60 | ||
end | ||
|
||
def minutes_ago(number_of) | ||
Time.now.utc - minutes(number_of) | ||
end | ||
end | ||
end |
2 changes: 0 additions & 2 deletions
2
lib/govuk_sli_collector/publishing_latency_sli/record_metrics.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require "prometheus/client" | ||
|
||
module GovukSliCollector | ||
class PublishingLatencySli | ||
class RecordMetrics | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters