Commit 45c009b8 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '44291-usage-ping-for-kubernetes-integration' into 'master'

Resolve "Usage ping for Kubernetes integration"

Closes #44291

See merge request gitlab-org/gitlab-ce!17922
parents 6b89ab11 b26913a3
...@@ -51,6 +51,10 @@ module Clusters ...@@ -51,6 +51,10 @@ module Clusters
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :disabled, -> { where(enabled: false) } scope :disabled, -> { where(enabled: false) }
scope :user_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:user]) }
scope :gcp_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:gcp]) }
scope :gcp_installed, -> { gcp_provided.includes(:provider_gcp).where(cluster_providers_gcp: { status: ::Clusters::Providers::Gcp.state_machines[:status].states[:created].value }) }
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) } scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
def status_name def status_name
......
...@@ -4,6 +4,8 @@ module Clusters ...@@ -4,6 +4,8 @@ module Clusters
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
scope :installed, -> { where(status: self.state_machines[:status].states[:installed].value) }
state_machine :status, initial: :not_installable do state_machine :status, initial: :not_installable do
state :not_installable, value: -2 state :not_installable, value: -2
state :errored, value: -1 state :errored, value: -1
......
---
title: Add additional cluster usage metrics to usage ping.
merge_request: 17922
author:
type: changed
...@@ -30,6 +30,7 @@ module Gitlab ...@@ -30,6 +30,7 @@ module Gitlab
usage_data usage_data
end end
# rubocop:disable Metrics/AbcSize
def system_usage_data def system_usage_data
{ {
counts: { counts: {
...@@ -50,6 +51,12 @@ module Gitlab ...@@ -50,6 +51,12 @@ module Gitlab
clusters: ::Clusters::Cluster.count, clusters: ::Clusters::Cluster.count,
clusters_enabled: ::Clusters::Cluster.enabled.count, clusters_enabled: ::Clusters::Cluster.enabled.count,
clusters_disabled: ::Clusters::Cluster.disabled.count, clusters_disabled: ::Clusters::Cluster.disabled.count,
clusters_platforms_gke: ::Clusters::Cluster.gcp_installed.enabled.count,
clusters_platforms_user: ::Clusters::Cluster.user_provided.enabled.count,
clusters_applications_helm: ::Clusters::Applications::Helm.installed.count,
clusters_applications_ingress: ::Clusters::Applications::Ingress.installed.count,
clusters_applications_prometheus: ::Clusters::Applications::Prometheus.installed.count,
clusters_applications_runner: ::Clusters::Applications::Runner.installed.count,
in_review_folder: ::Environment.in_review_folder.count, in_review_folder: ::Environment.in_review_folder.count,
groups: Group.count, groups: Group.count,
issues: Issue.count, issues: Issue.count,
......
...@@ -12,6 +12,14 @@ describe Gitlab::UsageData do ...@@ -12,6 +12,14 @@ describe Gitlab::UsageData do
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true) create(:service, project: projects[1], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'SlackService', active: true)
gcp_cluster = create(:cluster, :provided_by_gcp)
create(:cluster, :provided_by_user)
create(:cluster, :provided_by_user, :disabled)
create(:clusters_applications_helm, :installed, cluster: gcp_cluster)
create(:clusters_applications_ingress, :installed, cluster: gcp_cluster)
create(:clusters_applications_prometheus, :installed, cluster: gcp_cluster)
create(:clusters_applications_runner, :installed, cluster: gcp_cluster)
end end
subject { described_class.data } subject { described_class.data }
...@@ -64,6 +72,12 @@ describe Gitlab::UsageData do ...@@ -64,6 +72,12 @@ describe Gitlab::UsageData do
clusters clusters
clusters_enabled clusters_enabled
clusters_disabled clusters_disabled
clusters_platforms_gke
clusters_platforms_user
clusters_applications_helm
clusters_applications_ingress
clusters_applications_prometheus
clusters_applications_runner
in_review_folder in_review_folder
groups groups
issues issues
...@@ -97,6 +111,15 @@ describe Gitlab::UsageData do ...@@ -97,6 +111,15 @@ describe Gitlab::UsageData do
expect(count_data[:projects_jira_active]).to eq(2) expect(count_data[:projects_jira_active]).to eq(2)
expect(count_data[:projects_slack_notifications_active]).to eq(2) expect(count_data[:projects_slack_notifications_active]).to eq(2)
expect(count_data[:projects_slack_slash_active]).to eq(1) expect(count_data[:projects_slack_slash_active]).to eq(1)
expect(count_data[:clusters_enabled]).to eq(6)
expect(count_data[:clusters_disabled]).to eq(1)
expect(count_data[:clusters_platforms_gke]).to eq(1)
expect(count_data[:clusters_platforms_user]).to eq(1)
expect(count_data[:clusters_applications_helm]).to eq(1)
expect(count_data[:clusters_applications_ingress]).to eq(1)
expect(count_data[:clusters_applications_prometheus]).to eq(1)
expect(count_data[:clusters_applications_runner]).to eq(1)
end end
end end
......
...@@ -3,6 +3,18 @@ require 'rails_helper' ...@@ -3,6 +3,18 @@ require 'rails_helper'
describe Clusters::Applications::Helm do describe Clusters::Applications::Helm do
include_examples 'cluster application core specs', :clusters_applications_helm include_examples 'cluster application core specs', :clusters_applications_helm
describe '.installed' do
subject { described_class.installed }
let!(:cluster) { create(:clusters_applications_helm, :installed) }
before do
create(:clusters_applications_helm, :errored)
end
it { is_expected.to contain_exactly(cluster) }
end
describe '#install_command' do describe '#install_command' do
let(:helm) { create(:clusters_applications_helm) } let(:helm) { create(:clusters_applications_helm) }
......
...@@ -11,6 +11,18 @@ describe Clusters::Applications::Ingress do ...@@ -11,6 +11,18 @@ describe Clusters::Applications::Ingress do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async) allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)
end end
describe '.installed' do
subject { described_class.installed }
let!(:cluster) { create(:clusters_applications_ingress, :installed) }
before do
create(:clusters_applications_ingress, :errored)
end
it { is_expected.to contain_exactly(cluster) }
end
describe '#make_installed!' do describe '#make_installed!' do
before do before do
application.make_installed! application.make_installed!
......
...@@ -4,6 +4,18 @@ describe Clusters::Applications::Prometheus do ...@@ -4,6 +4,18 @@ describe Clusters::Applications::Prometheus do
include_examples 'cluster application core specs', :clusters_applications_prometheus include_examples 'cluster application core specs', :clusters_applications_prometheus
include_examples 'cluster application status specs', :cluster_application_prometheus include_examples 'cluster application status specs', :cluster_application_prometheus
describe '.installed' do
subject { described_class.installed }
let!(:cluster) { create(:clusters_applications_prometheus, :installed) }
before do
create(:clusters_applications_prometheus, :errored)
end
it { is_expected.to contain_exactly(cluster) }
end
describe 'transition to installed' do describe 'transition to installed' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
......
...@@ -8,6 +8,18 @@ describe Clusters::Applications::Runner do ...@@ -8,6 +8,18 @@ describe Clusters::Applications::Runner do
it { is_expected.to belong_to(:runner) } it { is_expected.to belong_to(:runner) }
describe '.installed' do
subject { described_class.installed }
let!(:cluster) { create(:clusters_applications_runner, :installed) }
before do
create(:clusters_applications_runner, :errored)
end
it { is_expected.to contain_exactly(cluster) }
end
describe '#install_command' do describe '#install_command' do
let(:kubeclient) { double('kubernetes client') } let(:kubeclient) { double('kubernetes client') }
let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) } let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) }
......
...@@ -39,6 +39,42 @@ describe Clusters::Cluster do ...@@ -39,6 +39,42 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) } it { is_expected.to contain_exactly(cluster) }
end end
describe '.user_provided' do
subject { described_class.user_provided }
let!(:cluster) { create(:cluster, :provided_by_user) }
before do
create(:cluster, :provided_by_gcp)
end
it { is_expected.to contain_exactly(cluster) }
end
describe '.gcp_provided' do
subject { described_class.gcp_provided }
let!(:cluster) { create(:cluster, :provided_by_gcp) }
before do
create(:cluster, :provided_by_user)
end
it { is_expected.to contain_exactly(cluster) }
end
describe '.gcp_installed' do
subject { described_class.gcp_installed }
let!(:cluster) { create(:cluster, :provided_by_gcp) }
before do
create(:cluster, :providing_by_gcp)
end
it { is_expected.to contain_exactly(cluster) }
end
describe 'validation' do describe 'validation' do
subject { cluster.valid? } subject { cluster.valid? }
......
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