Commit e7ef874e authored by ap4y's avatar ap4y

Add usage data counter for network policy packet stats

This MR adds redis based usage data counter that will be used for
collecting usage metrics for network policy packet stats
parent 937d373e
# 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