Commit a8a6b5c7 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'network-policy-usage-counter' into 'master'

Add usage data counter for network policy packet stats

See merge request gitlab-org/gitlab!30005
parents 3d9ed2b4 e7ef874e
# frozen_string_literal: true
module Gitlab::UsageDataCounters
class NetworkPolicyCounter < BaseCounter
KNOWN_EVENTS = %w[forwards drops].freeze
PREFIX = 'network_policy'
class << self
def add(forwards, drops)
return unless Gitlab::CurrentSettings.usage_ping_enabled?
Gitlab::Redis::SharedState.with do |redis|
redis.multi do
redis.incrby(redis_key(:forwards), forwards)
redis.incrby(redis_key(:drops), drops)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::UsageDataCounters::NetworkPolicyCounter, :clean_gitlab_redis_shared_state do
describe '.add' do
it 'increases drops and forwards counters' do
described_class.add(10, 5)
expect(described_class.totals).to eq(network_policy_forwards: 10, network_policy_drops: 5)
described_class.add(2, 1)
expect(described_class.totals).to eq(network_policy_forwards: 12, network_policy_drops: 6)
end
end
end
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