Commit 70a1e8bd authored by alinamihaila's avatar alinamihaila

Add method for_data_warehouse

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