Class: Gitlab::Prometheus::Queries::EnvironmentQuery

Inherits:
BaseQuery
  • Object
show all
Defined in:
lib/gitlab/prometheus/queries/environment_query.rb

Instance Attribute Summary

Attributes inherited from BaseQuery

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseQuery

#initialize, #raw_cpu_usage_query, #raw_memory_usage_query

Constructor Details

This class inherits a constructor from Gitlab::Prometheus::Queries::BaseQuery

Class Method Details

.transform_reactive_result(result) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


27
28
29
30
# File 'lib/gitlab/prometheus/queries/environment_query.rb', line 27

def self.transform_reactive_result(result)
  result[:metrics] = result.delete :data
  result
end

Instance Method Details

#query(environment_id) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/prometheus/queries/environment_query.rb', line 8

def query(environment_id)
  ::Environment.find_by(id: environment_id).try do |environment|
    environment_slug = environment.slug
    timeframe_start = 8.hours.ago.to_f
    timeframe_end = Time.now.to_f

    memory_query = raw_memory_usage_query(environment_slug)
    cpu_query = raw_cpu_usage_query(environment_slug)

    {
      memory_values: client_query_range(memory_query, start_time: timeframe_start, end_time: timeframe_end),
      memory_current: client_query(memory_query, time: timeframe_end),
      cpu_values: client_query_range(cpu_query, start_time: timeframe_start, end_time: timeframe_end),
      cpu_current: client_query(cpu_query, time: timeframe_end)
    }
  end
end