Skip to content

Commit

Permalink
Merge pull request #3520 from alphagov/prometheus-labels-for-content-…
Browse files Browse the repository at this point in the history
…type

Add document_type and schema_name to prom labels
  • Loading branch information
richardTowers authored Jan 15, 2025
2 parents 997e932 + d23fcf0 commit 48c7f6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def show
load_content_item

set_expiry
set_prometheus_labels

if is_service_manual?
show_service_manual_page
Expand Down Expand Up @@ -234,6 +235,14 @@ def set_expiry
)
end

def set_prometheus_labels
prometheus_labels = request.env.fetch("govuk.prometheus_labels", {})
request.env["govuk.prometheus_labels"] = prometheus_labels.merge(
document_type: @content_item.document_type,
schema_name: @content_item.schema_name,
)
end

def service_url(original_url)
ga_param = params[:_ga]
return original_url if ga_param.nil?
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_equal content_item["title"], assigns[:content_item].title
end

test "sets prometheus labels on the rack env" do
content_item = content_store_has_schema_example("case_study", "case_study")

get :show, params: { path: path_for(content_item) }
assert_response :success
assert_equal @request.env["govuk.prometheus_labels"], { document_type: "case_study", schema_name: "case_study" }
end

test "gets item from content store and keeps existing ordered_related_items when links already exist" do
content_item = content_store_has_schema_example("guide", "guide")

Expand Down

0 comments on commit 48c7f6d

Please sign in to comment.