Commit 442f5991 authored by Ben Kochie's avatar Ben Kochie Committed by Bob Van Landuyt

Adjust redis cache metrics

* Remove `controller` and `action` labels from duration histogram.
* Create a new simple counter for `controller` and `action`.
* Adjust histogram buckets to observe smaller response times.
parent 4ef648cd
---
title: Adjust redis cache metrics
merge_request: 30572
author:
type: changed
...@@ -34,6 +34,9 @@ The following metrics are available: ...@@ -34,6 +34,9 @@ The following metrics are available:
| filesystem_writable | Gauge | 9.4 | Whether or not the filesystem is writable | | filesystem_writable | Gauge | 9.4 | Whether or not the filesystem is writable |
| filesystem_read_latency_seconds | Gauge | 9.4 | Read latency of a specific filesystem | | filesystem_read_latency_seconds | Gauge | 9.4 | Read latency of a specific filesystem |
| filesystem_readable | Gauge | 9.4 | Whether or not the filesystem is readable | | filesystem_readable | Gauge | 9.4 | Whether or not the filesystem is readable |
| gitlab_cache_misses_total | Counter | 10.2 | Cache read miss |
| gitlab_cache_operation_duration_seconds | Histogram | 10.2 | Cache access time |
| gitlab_cache_operations_total | Counter | 12.2 | Cache operations by controller/action |
| http_requests_total | Counter | 9.4 | Rack request count | | http_requests_total | Counter | 9.4 | Rack request count |
| http_request_duration_seconds | Histogram | 9.4 | HTTP response time from rack middleware | | http_request_duration_seconds | Histogram | 9.4 | HTTP response time from rack middleware |
| pipelines_created_total | Counter | 9.4 | Counter of pipelines created | | pipelines_created_total | Counter | 9.4 | Counter of pipelines created |
......
...@@ -50,7 +50,8 @@ module Gitlab ...@@ -50,7 +50,8 @@ module Gitlab
def observe(key, duration) def observe(key, duration)
return unless current_transaction return unless current_transaction
metric_cache_operation_duration_seconds.observe(current_transaction.labels.merge({ operation: key }), duration / 1000.0) metric_cache_operations_total.increment(current_transaction.labels.merge({ operation: key }))
metric_cache_operation_duration_seconds.observe({ operation: key }, duration / 1000.0)
current_transaction.increment(:cache_duration, duration, false) current_transaction.increment(:cache_duration, duration, false)
current_transaction.increment(:cache_count, 1, false) current_transaction.increment(:cache_count, 1, false)
current_transaction.increment("cache_#{key}_duration".to_sym, duration, false) current_transaction.increment("cache_#{key}_duration".to_sym, duration, false)
...@@ -63,12 +64,20 @@ module Gitlab ...@@ -63,12 +64,20 @@ module Gitlab
Transaction.current Transaction.current
end end
def metric_cache_operations_total
@metric_cache_operations_total ||= ::Gitlab::Metrics.counter(
:gitlab_cache_operations_total,
'Cache operations',
Transaction::BASE_LABELS
)
end
def metric_cache_operation_duration_seconds def metric_cache_operation_duration_seconds
@metric_cache_operation_duration_seconds ||= ::Gitlab::Metrics.histogram( @metric_cache_operation_duration_seconds ||= ::Gitlab::Metrics.histogram(
:gitlab_cache_operation_duration_seconds, :gitlab_cache_operation_duration_seconds,
'Cache access time', 'Cache access time',
Transaction::BASE_LABELS.merge({ action: nil }), {},
[0.001, 0.01, 0.1, 1, 10] [0.00001, 0.0001, 0.001, 0.01, 0.1, 1.0]
) )
end end
......
...@@ -201,7 +201,15 @@ describe Gitlab::Metrics::Subscribers::RailsCache do ...@@ -201,7 +201,15 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it 'observes cache metric' do it 'observes cache metric' do
expect(subscriber.send(:metric_cache_operation_duration_seconds)) expect(subscriber.send(:metric_cache_operation_duration_seconds))
.to receive(:observe) .to receive(:observe)
.with(transaction.labels.merge(operation: :delete), event.duration / 1000.0) .with({ operation: :delete }, event.duration / 1000.0)
subscriber.observe(:delete, event.duration)
end
it 'increments the operations total' do
expect(subscriber.send(:metric_cache_operations_total))
.to receive(:increment)
.with(transaction.labels.merge(operation: :delete))
subscriber.observe(:delete, event.duration) subscriber.observe(:delete, event.duration)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment