Skip to content

Resolve "MAU based metrics from CI tunnel usage"

What does this MR do and why?

This is the gitlab-org/gitlab part that implements #346967 (closed). There's also a KAS counterpart: gitlab-org/cluster-integration/gitlab-agent!695 (merged).

!92300 (merged) should be released first.

This makes the kubernetes/usage_metrics more generic and flexible by expecting a hash of counters and a hash of unique_counters. With this, we don't need to keep parsing attribute names in search for suffixes to determine the logic to be applied.

This MR also adds the new HLL Redis counter to track the MAU usage of the CI/CD Tunnel feature.

This MR also deprecates the existing counter API attributes, as we want to start using the new hashes. In the next milestone, KAS won't send this old counters anymore, so we can start relying only on the new API.

Screenshots or screen recordings

Redis key after triggering the internal request:

> redis-cli -s redis/redis.socket
redis redis/redis.socket> keys *{agent}*
1) "{agent}_users_using_ci_tunnel-2022-30"

Checking metric from rails c:

[2] pry(main)> Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: 'agent_users_using_ci_tunnel', start_date: Date.current.beginning_of_week, end_date: Date.current.next_week)
=> 1

Generating metrics:

> bundle exec rake gitlab:usage_data:generate | jq .redis_hll_counters.kubernetes_agent
{
  "agent_users_using_ci_tunnel_weekly": 0,
  "agent_users_using_ci_tunnel_monthly": 0
}

# tests old counters still work
> bundle exec rake gitlab:usage_data:generate | jq .counts.kubernetes_agent_k8s_api_proxy_request
6192

# tests old counters still work
> bundle exec rake gitlab:usage_data:generate | jq .counts.kubernetes_agents
2

How to set up and validate locally

This is a complicated set up. I'm happy to go on a call to help set up if needed.

For a full complete test, one needs to:

  1. Enable the metric feature flag: Feature.enable(:track_agent_users_using_ci_tunnel)
  2. Set up a local K8s cluster with something like kind or k3d.
  3. Set up local runners.
  4. Set up a project configured to used the CI/CD tunnel.
  5. Run a kubectl command on your CI/CD job using the tunnel.
  6. Verify that the deprecated counters are still counting.
  7. On {GDK_ROOT}/gitlab-k8s-agent, run git checkout feature/track-users-ci-tunnel-interaction.
  8. Restart your gitlab-k8s-agent server.
  9. Restart Redis to cleanup the counters.
  10. Repeat step 4.
  11. Verify that the new counters and unique_counters are working.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #346967 (closed)

Edited by João Alexandre Cunha

Merge request reports