Skip to content

Commit

Permalink
Merge pull request #310 from alphagov/more-quality-reporting
Browse files Browse the repository at this point in the history
Improve search quality monitoring
  • Loading branch information
csutter authored Aug 5, 2024
2 parents be62f83 + a706fe1 commit b0cf6fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
14 changes: 13 additions & 1 deletion app/services/metrics/quality_monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def initialize(registry)
docstring: "Quality monitoring failure count for Search API v2",
labels: %i[dataset_type dataset_name],
)
@quality_monitoring_total = registry.gauge(
:search_api_v2_quality_monitoring_total,
docstring: "Quality monitoring total count for Search API v2",
labels: %i[dataset_type dataset_name],
)
end

def record_score(dataset_type, dataset_name, score)
Expand All @@ -27,8 +32,15 @@ def record_failure_count(dataset_type, dataset_name, count)
})
end

def record_total_count(dataset_type, dataset_name, count)
quality_monitoring_total.set(count, labels: {
dataset_type: dataset_type.to_s,
dataset_name: dataset_name.to_s,
})
end

private

attr_reader :quality_monitoring_score, :quality_monitoring_failures
attr_reader :quality_monitoring_score, :quality_monitoring_failures, :quality_monitoring_total
end
end
12 changes: 2 additions & 10 deletions app/services/quality_monitoring/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def run
mean_score,
),
)
metric_collector.record_score(type, dataset_name, mean_score) if metric_collector

if failure_details.any?
Rails.logger.warn(
Expand All @@ -70,19 +69,12 @@ def run
failure_details.join("\n"),
),
)

err = FailuresEncountered.new(
"Quality monitoring: #{failure_details.size} failures encountered " \
"for #{type} dataset #{dataset_name}",
)
GovukError.notify(
err,
extra: { dataset_name:, type:, failure_details: failure_details.join("\n") },
)
end

if metric_collector
metric_collector.record_score(type, dataset_name, mean_score)
metric_collector.record_failure_count(type, dataset_name, failure_details.size)
metric_collector.record_total_count(type, dataset_name, scores.size)
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/services/metrics/quality_monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
let(:registry) { double("registry") }
let(:score_gauge) { double("score gauge") }
let(:failure_gauge) { double("failure gauge") }
let(:total_gauge) { double("total gauge") }

before do
allow(registry).to receive(:gauge)
.with(:search_api_v2_quality_monitoring_score, anything).and_return(score_gauge)
allow(registry).to receive(:gauge)
.with(:search_api_v2_quality_monitoring_failures, anything).and_return(failure_gauge)
allow(registry).to receive(:gauge)
.with(:search_api_v2_quality_monitoring_total, anything).and_return(total_gauge)

allow(score_gauge).to receive(:set)
end
Expand All @@ -31,4 +34,13 @@
quality_monitoring.record_failure_count(:foo, "bar", 50)
end
end

describe "#record_total_count" do
it "records the total count" do
expect(total_gauge).to receive(:set)
.with(100, labels: { dataset_type: "foo", dataset_name: "bar" })

quality_monitoring.record_total_count(:foo, "bar", 100)
end
end
end

0 comments on commit b0cf6fa

Please sign in to comment.