Skip to content

Usage ping agent token

Thong Kuah requested to merge usage_ping_agent_token into master

What does this MR do?

Counts (distinct) kubernetes agents with at least one agent token.

SQL:

Gitlab::UsageData.distinct_count(::Clusters::AgentToken, :agent_id)
[1] pry(main)> Gitlab::UsageData.distinct_count(::Clusters::AgentToken, :agent_id)
   (4.9ms)  SELECT MIN("cluster_agent_tokens"."agent_id") FROM "cluster_agent_tokens"
   (0.4ms)  SELECT MAX("cluster_agent_tokens"."agent_id") FROM "cluster_agent_tokens"
   (0.2ms)  SELECT COUNT(DISTINCT "cluster_agent_tokens"."agent_id") FROM "cluster_agent_tokens" WHERE "cluster_agent_tokens"."agent_id" BETWEEN $1 AND $2  [["agent_id", 1], ["agent_id", 10000]]
=> 1

#database-lab plan:

explain SELECT COUNT(DISTINCT "cluster_agent_tokens"."agent_id") FROM "cluster_agent_tokens" WHERE "cluster_agent_tokens"."agent_id" BETWEEN 1 AND 10000;
 Aggregate  (cost=7.74..7.75 rows=1 width=8) (actual time=0.453..0.453 rows=1 loops=1)
   Buffers: shared hit=10 read=3
   I/O Timings: read=0.269
   ->  Index Only Scan using index_cluster_agent_tokens_on_agent_id on public.cluster_agent_tokens  (cost=0.15..7.73 rows=4 width=8) (actual time=0.051..0.051 rows=0 loops=1)
         Index Cond: ((cluster_agent_tokens.agent_id >= 1) AND (cluster_agent_tokens.agent_id <= 10000))
         Heap Fetches: 0
         Buffers: shared hit=4
Time: 0.696 ms
  - planning: 0.172 ms
  - execution: 0.524 ms
    - I/O read: 0.269 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 10 (~80.00 KiB) from the buffer pool
  - reads: 3 (~24.00 KiB) from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

Related issue: #219716 (closed)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Thong Kuah

Merge request reports