Commit e9310d3e authored by allison.browne's avatar allison.browne

Add index and report aproximate grafana embeds

parent ed243671
...@@ -62,10 +62,10 @@ class Issue < ApplicationRecord ...@@ -62,10 +62,10 @@ class Issue < ApplicationRecord
scope :order_relative_position_asc, -> { reorder(::Gitlab::Database.nulls_last_order('relative_position', 'ASC')) } scope :order_relative_position_asc, -> { reorder(::Gitlab::Database.nulls_last_order('relative_position', 'ASC')) }
scope :preload_associated_models, -> { preload(:labels, project: :namespace) } scope :preload_associated_models, -> { preload(:labels, project: :namespace) }
scope :with_project_grafana_integration, -> { includes(project: :grafana_integration).where(projects: { grafana_integrations: { enabled: true } } ) } scope :with_project_grafana_integration, -> { joins(project: :grafana_integration).where(projects: { grafana_integrations: { enabled: true } } ) }
scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) } scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) }
scope :grafana_embedded, -> { where('"issues"."description_html" LIKE \'%data-dashboard-url%\'').where('"issues"."description" ~* "grafana_integrations"."grafana_url"') } scope :grafana_embedded_aprox, -> { where('"issues"."description" ILIKE \'%\' || "grafana_integrations"."grafana_url" || \'%\'') }
scope :public_only, -> { where(confidential: false) } scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) } scope :confidential_only, -> { where(confidential: true) }
......
class AddIndexToGrafanaIntegrations < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :grafana_integrations, :enabled, where: 'enabled IS TRUE'
end
def down
remove_concurrent_index :grafana_integrations, :enabled
end
end
...@@ -1888,6 +1888,7 @@ ActiveRecord::Schema.define(version: 2019_11_25_140458) do ...@@ -1888,6 +1888,7 @@ ActiveRecord::Schema.define(version: 2019_11_25_140458) do
t.string "encrypted_token_iv", limit: 255, null: false t.string "encrypted_token_iv", limit: 255, null: false
t.string "grafana_url", limit: 1024, null: false t.string "grafana_url", limit: 1024, null: false
t.boolean "enabled", default: false, null: false t.boolean "enabled", default: false, null: false
t.index ["enabled"], name: "index_grafana_integrations_on_enabled", where: "(enabled IS TRUE)"
t.index ["project_id"], name: "index_grafana_integrations_on_project_id" t.index ["project_id"], name: "index_grafana_integrations_on_project_id"
end end
......
...@@ -4,12 +4,12 @@ module Gitlab ...@@ -4,12 +4,12 @@ module Gitlab
class GrafanaEmbedUsageData class GrafanaEmbedUsageData
class << self class << self
def issue_count def issue_count
count = 0 # rubocop:disable CodeReuse/ActiveRecord
Issue.select(:id).with_project_grafana_integration.grafana_embedded.each_batch do |issue_batch| Issue.joins(project: :grafana_integration)
count += issue_batch.count .merge(Project.with_grafana_integration_enabled)
end .where("issues.description LIKE '%' || grafana_integrations.grafana_url || '%'")
.count
count # rubocop:enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -84,7 +84,7 @@ module Gitlab ...@@ -84,7 +84,7 @@ module Gitlab
issues: count(Issue), issues: count(Issue),
issues_with_associated_zoom_link: count(ZoomMeeting.added_to_issue), issues_with_associated_zoom_link: count(ZoomMeeting.added_to_issue),
issues_using_zoom_quick_actions: count(ZoomMeeting.select(:issue_id).distinct), issues_using_zoom_quick_actions: count(ZoomMeeting.select(:issue_id).distinct),
issues_with_embeded_grafana_charts: ::Gitlab::GrafanaEmbedUsageData.issue_count, issues_with_embeded_grafana_charts_aprox: ::Gitlab::GrafanaEmbedUsageData.issue_count,
keys: count(Key), keys: count(Key),
label_lists: count(List.label), label_lists: count(List.label),
lfs_objects: count(LfsObject), lfs_objects: count(LfsObject),
......
...@@ -154,7 +154,7 @@ describe Gitlab::UsageData do ...@@ -154,7 +154,7 @@ describe Gitlab::UsageData do
issues issues
issues_with_associated_zoom_link issues_with_associated_zoom_link
issues_using_zoom_quick_actions issues_using_zoom_quick_actions
issues_with_embeded_grafana_charts issues_with_embeded_grafana_charts_aprox
keys keys
label_lists label_lists
labels labels
...@@ -214,7 +214,7 @@ describe Gitlab::UsageData do ...@@ -214,7 +214,7 @@ describe Gitlab::UsageData do
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1) expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
expect(count_data[:issues_with_associated_zoom_link]).to eq(2) expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
expect(count_data[:issues_using_zoom_quick_actions]).to eq(3) expect(count_data[:issues_using_zoom_quick_actions]).to eq(3)
expect(count_data[:issues_with_embeded_grafana_charts]).to eq(2) expect(count_data[:issues_with_embeded_grafana_charts_aprox]).to eq(2)
expect(count_data[:clusters_enabled]).to eq(4) expect(count_data[:clusters_enabled]).to eq(4)
expect(count_data[:project_clusters_enabled]).to eq(3) expect(count_data[:project_clusters_enabled]).to eq(3)
......
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