Commit 19c8ef03 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '204802-exclude-instance-services-from-usage-data' into 'master'

Exclude instance-level services from usage data

See merge request gitlab-org/gitlab!38147
parents e0f9392f 0074a8b0
---
title: Replace index for service usage data
merge_request: 38147
author:
type: performance
# frozen_string_literal: true
class ReplaceIndexForServiceUsageData < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
OLD_INDEX_NAME = 'index_services_on_type_and_id_and_template_when_active'
NEW_INDEX_NAME = 'index_services_on_type_id_when_active_not_instance_not_template'
disable_ddl_transaction!
def up
add_concurrent_index :services, [:type, :id], where: 'active = TRUE AND instance = FALSE AND template = FALSE', name: NEW_INDEX_NAME
remove_concurrent_index_by_name :services, OLD_INDEX_NAME
end
def down
add_concurrent_index :services, [:type, :id, :template], where: 'active = TRUE', name: OLD_INDEX_NAME
remove_concurrent_index :services, NEW_INDEX_NAME
end
end
5bda9ae726077c1ea0df2158138f85ca43bfbf5b1a8cf3516bcdf012eac5c0b8
\ No newline at end of file
......@@ -20523,12 +20523,12 @@ CREATE INDEX index_services_on_template ON public.services USING btree (template
CREATE INDEX index_services_on_type ON public.services USING btree (type);
CREATE INDEX index_services_on_type_and_id_and_template_when_active ON public.services USING btree (type, id, template) WHERE (active = true);
CREATE UNIQUE INDEX index_services_on_type_and_instance_partial ON public.services USING btree (type, instance) WHERE (instance = true);
CREATE UNIQUE INDEX index_services_on_type_and_template_partial ON public.services USING btree (type, template) WHERE (template = true);
CREATE INDEX index_services_on_type_id_when_active_not_instance_not_template ON public.services USING btree (type, id) WHERE ((active = true) AND (instance = false) AND (template = false));
CREATE UNIQUE INDEX index_shards_on_name ON public.shards USING btree (name);
CREATE INDEX index_slack_integrations_on_service_id ON public.slack_integrations USING btree (service_id);
......
......@@ -355,7 +355,7 @@ module Gitlab
def services_usage
# rubocop: disable UsageData/LargeTable:
Service.available_services_names.each_with_object({}) do |service_name, response|
response["projects_#{service_name}_active".to_sym] = count(Service.active.where(template: false, type: "#{service_name}_service".camelize))
response["projects_#{service_name}_active".to_sym] = count(Service.active.where(template: false, instance: false, type: "#{service_name}_service".camelize))
end.merge(jira_usage, jira_import_usage)
# rubocop: enable UsageData/LargeTable:
end
......
......@@ -24,6 +24,7 @@ FactoryBot.define do
create(:service, project: projects[2], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'MattermostService', active: false)
create(:service, :template, type: 'MattermostService', active: true)
create(:service, :instance, type: 'MattermostService', active: true)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true)
create(:project_error_tracking_setting, project: projects[0])
create(:project_error_tracking_setting, project: projects[1], enabled: false)
......
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