diff options
author | Chris Baumbauer <cab@cabnetworks.net> | 2019-04-06 02:02:39 +0000 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2019-04-06 02:02:39 +0000 |
commit | b77fe7db3e885edca14c862f362e2bbd43f0e498 (patch) | |
tree | cd984b8bb900a6b3e37c8f6106101ba8617bf524 /lib | |
parent | 8e33e7cf474b61bbc684d993d86cb5aa775a01d0 (diff) | |
download | gitlab-ce-b77fe7db3e885edca14c862f362e2bbd43f0e498.tar.gz |
Add Knative metrics to Prometheus
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/prometheus/queries/knative_invocation_query.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/prometheus/queries/knative_invocation_query.rb b/lib/gitlab/prometheus/queries/knative_invocation_query.rb new file mode 100644 index 00000000000..2691abe46d6 --- /dev/null +++ b/lib/gitlab/prometheus/queries/knative_invocation_query.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Gitlab + module Prometheus + module Queries + class KnativeInvocationQuery < BaseQuery + include QueryAdditionalMetrics + + def query(serverless_function_id) + PrometheusMetric + .find_by_identifier(:system_metrics_knative_function_invocation_count) + .to_query_metric.tap do |q| + q.queries[0][:result] = run_query(q.queries[0][:query_range], context(serverless_function_id)) + end + end + + protected + + def context(function_id) + function = Serverless::Function.find_by_id(function_id) + { + function_name: function.name, + kube_namespace: function.namespace + } + end + + def run_query(query, context) + query %= context + client_query_range(query, start: 8.hours.ago.to_f, stop: Time.now.to_f) + end + + def self.transform_reactive_result(result) + result[:metrics] = result.delete :data + result + end + end + end + end +end |