Skip to content

Commit 92436fe

Browse files
committed
Add the table_id as a label
When we send data to prometheus we provide labels, which we can use to create dashboards that are helpful. Currently the labels we send are top-k and month. We also need to add the table_id so that we can see which metrics are for clickstream data, and which are for binary. I've called the label "dataset" rather than table_id as it feels a bit easier to understand.
1 parent 123c60f commit 92436fe

5 files changed

Lines changed: 28 additions & 25 deletions

File tree

app/services/discovery_engine/quality/evaluations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def collect_quality_metrics(month_label)
1818
all_sample_query_sets(month_label).each do |set|
1919
e = DiscoveryEngine::Quality::Evaluation.new(set).fetch_quality_metrics
2020
Rails.logger.info(e)
21-
metric_collector.record_evaluations(e, month_label)
21+
metric_collector.record_evaluations(e, month_label, set.table_id)
2222
end
2323
end
2424

app/services/discovery_engine/quality/sample_query_set.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module Quality
33
class SampleQuerySet
44
BIGQUERY_DATASET_ID = "automated_evaluation_input".freeze
55

6+
attr_reader :table_id
7+
68
def initialize(table_id:, month_label: nil, month: nil, year: nil)
79
@month_label = month_label
810
@month = month
@@ -21,7 +23,7 @@ def name
2123

2224
private
2325

24-
attr_reader :month_label, :table_id, :month, :year
26+
attr_reader :month_label, :month, :year
2527

2628
def create
2729
DiscoveryEngine::Clients

app/services/metrics/evaluation.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ def initialize(registry)
66
@doc_recall = registry.gauge(
77
:search_api_v2_evaluation_monitoring_recall,
88
docstring: "Vertex AI search evaluation recall",
9-
labels: %i[top month],
9+
labels: %i[top month dataset],
1010
)
1111
@doc_precision = registry.gauge(
1212
:search_api_v2_evaluation_monitoring_precision,
1313
docstring: "Vertex AI search evaluation precision",
14-
labels: %i[top month],
14+
labels: %i[top month dataset],
1515
)
1616
@doc_ndcg = registry.gauge(
1717
:search_api_v2_evaluation_monitoring_ndcg,
1818
docstring: "Vertex AI search evaluation ndcg",
19-
labels: %i[top month],
19+
labels: %i[top month dataset],
2020
)
2121
end
2222

23-
def record_evaluations(evaluation_result, month)
24-
metrics.each { |key, registry| record_evaluation(key, registry, month, evaluation_result) }
23+
def record_evaluations(evaluation_result, month, dataset)
24+
metrics.each { |key, registry| record_evaluation(key, registry, month, dataset, evaluation_result) }
2525
end
2626

2727
private
@@ -32,10 +32,10 @@ def metrics
3232
{ doc_recall:, doc_precision:, doc_ndcg: }
3333
end
3434

35-
def record_evaluation(key, registry, month, evaluation_result)
35+
def record_evaluation(key, registry, month, dataset, evaluation_result)
3636
TOP_K_LEVELS.each do |k|
3737
value = evaluation_result[key][:"top_#{k}"]
38-
registry.set(value, labels: { top: k, month: })
38+
registry.set(value, labels: { top: k, month:, dataset: })
3939
end
4040
end
4141
end

spec/services/discovery_engine/quality/evaluations_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
let(:evaluation) { double("evaluation") }
66
let(:evaluation_response) { "amything" }
77
let(:sample_query_sets) { double("sample_query_sets") }
8-
let(:sample_query_set) { double("sample_query_set") }
8+
let(:sample_query_set) { double("sample_query_set", table_id: "clickstream") }
99

1010
before do
1111
allow(DiscoveryEngine::Quality::Evaluation)
@@ -19,11 +19,11 @@
1919

2020
allow(metric_collector)
2121
.to receive(:record_evaluations)
22-
.with(evaluation_response, :last_month)
22+
.with(evaluation_response, :last_month, "clickstream")
2323

2424
allow(metric_collector)
2525
.to receive(:record_evaluations)
26-
.with(evaluation_response, :month_before_last)
26+
.with(evaluation_response, :month_before_last, "clickstream")
2727

2828
allow(DiscoveryEngine::Quality::SampleQuerySets)
2929
.to receive(:new)

spec/services/metrics/evaluation_spec.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
let(:registry) { double("registry") }
55
let(:month) { :last_month }
6+
let(:table_id) { "clickstream" }
67

78
let(:evaluation_response) do
89
{
@@ -44,33 +45,33 @@
4445
describe "#record_evaluations" do
4546
it "records the recall, precision and ndcg score" do
4647
expect(recall_gauge).to receive(:set)
47-
.with(0.988, { labels: { top: "1", month: } })
48+
.with(0.988, { labels: { top: "1", month:, dataset: "clickstream" } })
4849
expect(recall_gauge).to receive(:set)
49-
.with(0.995, { labels: { top: "3", month: } })
50+
.with(0.995, { labels: { top: "3", month:, dataset: "clickstream" } })
5051
expect(recall_gauge).to receive(:set)
51-
.with(0.998, { labels: { top: "5", month: } })
52+
.with(0.998, { labels: { top: "5", month:, dataset: "clickstream" } })
5253
expect(recall_gauge).to receive(:set)
53-
.with(0.999, { labels: { top: "10", month: } })
54+
.with(0.999, { labels: { top: "10", month:, dataset: "clickstream" } })
5455

5556
expect(precision_gauge).to receive(:set)
56-
.with(0.988, { labels: { top: "1", month: } })
57+
.with(0.988, { labels: { top: "1", month:, dataset: "clickstream" } })
5758
expect(precision_gauge).to receive(:set)
58-
.with(0.953, { labels: { top: "3", month: } })
59+
.with(0.953, { labels: { top: "3", month:, dataset: "clickstream" } })
5960
expect(precision_gauge).to receive(:set)
60-
.with(0.896, { labels: { top: "5", month: } })
61+
.with(0.896, { labels: { top: "5", month:, dataset: "clickstream" } })
6162
expect(precision_gauge).to receive(:set)
62-
.with(0.752, { labels: { top: "10", month: } })
63+
.with(0.752, { labels: { top: "10", month:, dataset: "clickstream" } })
6364

6465
expect(ndcg_gauge).to receive(:set)
65-
.with(0.988, { labels: { top: "1", month: } })
66+
.with(0.988, { labels: { top: "1", month:, dataset: "clickstream" } })
6667
expect(ndcg_gauge).to receive(:set)
67-
.with(0.961, { labels: { top: "3", month: } })
68+
.with(0.961, { labels: { top: "3", month:, dataset: "clickstream" } })
6869
expect(ndcg_gauge).to receive(:set)
69-
.with(0.929, { labels: { top: "5", month: } })
70+
.with(0.929, { labels: { top: "5", month:, dataset: "clickstream" } })
7071
expect(ndcg_gauge).to receive(:set)
71-
.with(0.887, { labels: { top: "10", month: } })
72+
.with(0.887, { labels: { top: "10", month:, dataset: "clickstream" } })
7273

73-
evaluation.record_evaluations(evaluation_response, month)
74+
evaluation.record_evaluations(evaluation_response, month, table_id)
7475
end
7576
end
7677
end

0 commit comments

Comments
 (0)