Commit cc6c439b authored by Max Woolf's avatar Max Woolf

Merge branch 'add-network-policies-usage-data' into 'master'

Track usage data for Network Policies UI

See merge request gitlab-org/gitlab!64731
parents 781078f4 4a153096
This diff is collapsed.
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module NetworkPolicies module NetworkPolicies
class ResourcesService class ResourcesService
include NetworkPolicies::Responses include NetworkPolicies::Responses
include Gitlab::Utils::UsageData
LIMIT = 100 LIMIT = 100
...@@ -26,6 +27,12 @@ module NetworkPolicies ...@@ -26,6 +27,12 @@ module NetworkPolicies
private private
def track_usage_data_for_cluster(platform, policies)
return if policies.empty?
track_usage_event(:clusters_using_network_policies_ui, platform.cluster_id)
end
def execute_per_environment(platform, namespace) def execute_per_environment(platform, namespace)
policies = platform.kubeclient policies = platform.kubeclient
.get_network_policies(namespace: namespace) .get_network_policies(namespace: namespace)
...@@ -33,6 +40,7 @@ module NetworkPolicies ...@@ -33,6 +40,7 @@ module NetworkPolicies
policies += platform.kubeclient policies += platform.kubeclient
.get_cilium_network_policies(namespace: namespace) .get_cilium_network_policies(namespace: namespace)
.map { |resource| Gitlab::Kubernetes::CiliumNetworkPolicy.from_resource(resource) } .map { |resource| Gitlab::Kubernetes::CiliumNetworkPolicy.from_resource(resource) }
track_usage_data_for_cluster(platform, policies)
[policies, nil] [policies, nil]
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
[policies, e] [policies, e]
......
---
key_path: redis_hll_counters.network_policies.clusters_using_network_policies_ui_monthly
description: Monthly number of distinct clusters with network policies using the network policies UI
product_section: sec
product_stage: protect
product_group: group::container security
product_category: container_network_security
value_type: number
status: implemented
milestone: "14.1"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64731
time_frame: 28d
data_source: redis_hll
data_category: Operational
distribution:
- ee
tier:
- ultimate
---
key_path: redis_hll_counters.network_policies.clusters_using_network_policies_ui_weekly
description: Weekly number of distinct clusters with network policies using the network policies UI
product_section: sec
product_stage: protect
product_group: group::container security
product_category: container_network_security
value_type: number
status: implemented
milestone: "14.1"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64731
time_frame: 7d
data_source: redis_hll
data_category: Operational
distribution:
- ee
tier:
- ultimate
...@@ -9,7 +9,7 @@ RSpec.describe NetworkPolicies::ResourcesService do ...@@ -9,7 +9,7 @@ RSpec.describe NetworkPolicies::ResourcesService do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :instance) } let(:cluster) { create(:cluster, :instance) }
let!(:cluster_kubernetes_namespace) { create(:cluster_kubernetes_namespace, project: project, cluster: cluster, environment: environment, namespace: 'namespace') } let!(:cluster_kubernetes_namespace) { create(:cluster_kubernetes_namespace, project: project, cluster: cluster, environment: environment, namespace: 'namespace') }
let(:platform) { double('Clusters::Platforms::Kubernetes', kubeclient: kubeclient) } let(:platform) { double('Clusters::Platforms::Kubernetes', kubeclient: kubeclient, cluster_id: cluster.id) }
let(:kubeclient) { double('Kubeclient::Client') } let(:kubeclient) { double('Kubeclient::Client') }
let(:policy) do let(:policy) do
Gitlab::Kubernetes::NetworkPolicy.new( Gitlab::Kubernetes::NetworkPolicy.new(
...@@ -46,6 +46,23 @@ RSpec.describe NetworkPolicies::ResourcesService do ...@@ -46,6 +46,23 @@ RSpec.describe NetworkPolicies::ResourcesService do
expect(subject.payload.last.as_json).to eq(cilium_policy.as_json) expect(subject.payload.last.as_json).to eq(cilium_policy.as_json)
end end
it_behaves_like 'tracking unique hll events' do
subject(:request) { service.execute }
let(:target_id) { 'clusters_using_network_policies_ui' }
let(:expected_type) { instance_of(Integer) }
before do
allow(kubeclient).to receive(:get_network_policies)
.with(namespace: cluster_kubernetes_namespace.namespace)
.and_return [policy.generate]
allow(kubeclient).to receive(:get_cilium_network_policies)
.with(namespace: cluster_kubernetes_namespace.namespace)
.and_return [cilium_policy.generate]
end
end
context 'without deployment_platform' do context 'without deployment_platform' do
let(:platform) { nil } let(:platform) { nil }
......
...@@ -369,3 +369,8 @@ ...@@ -369,3 +369,8 @@
category: testing category: testing
aggregation: weekly aggregation: weekly
feature_flag: users_expanding_widgets_usage_data feature_flag: users_expanding_widgets_usage_data
# Container Security - Network Policies
- name: clusters_using_network_policies_ui
redis_slot: network_policies
category: network_policies
aggregation: weekly
...@@ -46,7 +46,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -46,7 +46,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
'pipeline_authoring', 'pipeline_authoring',
'epics_usage', 'epics_usage',
'epic_boards_usage', 'epic_boards_usage',
'secure' 'secure',
'network_policies'
) )
end end
end end
......
...@@ -1269,7 +1269,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1269,7 +1269,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories } let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories }
let(:ineligible_total_categories) do let(:ineligible_total_categories) do
%w[source_code ci_secrets_management incident_management_alerts snippets terraform incident_management_oncall secure] %w[source_code ci_secrets_management incident_management_alerts snippets terraform incident_management_oncall secure network_policies]
end end
context 'with redis_hll_tracking feature enabled' do context 'with redis_hll_tracking feature enabled' do
......
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