Commit 70a1e8bd authored by alinamihaila's avatar alinamihaila

Add method for_data_warehouse

parent 0f05c6af
......@@ -11,12 +11,12 @@ module Gitlab
attr_reader :time_frame
attr_reader :options
def initialize(time_frame: 'none', options: {})
def initialize(time_frame:, options: {})
@time_frame = time_frame
@options = options
end
def to_sql
def for_data_warehouse
value
end
end
......
......@@ -59,6 +59,10 @@ module Gitlab
Gitlab::Usage::Metrics::Query.for(self.class.metric_operation, relation, self.class.column)
end
def for_data_warehouse
to_sql
end
def suggested_name
Gitlab::Usage::Metrics::NameSuggestion.for(
self.class.metric_operation,
......
......@@ -28,6 +28,11 @@ module Gitlab
end
end
def initialize(time_frame: 'none', options: {})
@time_frame = time_frame
@options = options
end
def value
alt_usage_data(fallback: self.class.fallback) do
self.class.metric_value.call
......
......@@ -6,7 +6,7 @@ module Gitlab
class << self
def add_metric(metric)
metric.value unless metric.is_a?(Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric)
metric.for_data_warehouse
end
def count(relation, column = nil, batch: true, batch_size: nil, start: nil, finish: nil)
......
......@@ -6,7 +6,7 @@ module Gitlab
class UsageDataQueries < UsageData
class << self
def add_metric(metric)
metric.to_sql
metric.for_data_warehouse
end
def count(relation, column = nil, *args, **kwargs)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,6 +5,14 @@ require 'spec_helper'
RSpec.describe Gitlab::UsageDataNonSqlMetrics do
let(:default_count) { Gitlab::UsageDataNonSqlMetrics::SQL_METRIC_DEFAULT }
describe '#add_metric' do
let(:metric) { double(:metric, for_data_warehouse: 1) }
it 'computes the metric value for given metric' do
expect(described_class.add_metric(metric)).to eq(1)
end
end
describe '.count' do
it 'returns default value for count' do
expect(described_class.count(User)).to eq(default_count)
......
......@@ -8,7 +8,7 @@ RSpec.describe Gitlab::UsageDataQueries do
end
describe '#add_metric' do
let(:metric) { double(:metric, to_sql: 'SELECT COUNT("users"."id") FROM "users"') }
let(:metric) { double(:metric, for_data_warehouse: 'SELECT COUNT("users"."id") FROM "users"') }
it 'computes the metric value for given metric' do
expect(described_class.add_metric(metric)).to eq('SELECT COUNT("users"."id") FROM "users"')
......
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