Usage ping agent token
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
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
Edited by Thong Kuah