Skip to content

PMM-14900 Add protection to RTA session against unsupported pmm-agent version#5116

Merged
maxkondr merged 23 commits intov3from
PMM-14900-rta-agent-version
Mar 16, 2026
Merged

PMM-14900 Add protection to RTA session against unsupported pmm-agent version#5116
maxkondr merged 23 commits intov3from
PMM-14900-rta-agent-version

Conversation

@maxkondr
Copy link
Copy Markdown
Contributor

@maxkondr maxkondr commented Mar 6, 2026

PMM-14900

New endpoint is introduced /v1/realtimeanalytics/services:

  • It supports service_type filter as incoming parameter.
  • In case filter is passed - returns service that support RTA of specified type only. (taking into account pmm-agent version as well). For the time being it is MongoDB only, but will be extended in future.
  • in case filter is not defined-  returns service that support RTA (taking into account pmm-agent version as well)
    it has return interface equal to /v1/inventory/services

In case user requested start RTA session for the MongoDB service that is registered in PMM via pmm-agent <3.7.0 version - API returns an error.

Link to the Feature Build: Percona-Lab/pmm-submodules#4256

…version

In case user requested start RTA session for the MongoDB service that is registered in PMM via pmm-agent <3.7.0 version - API returns an error.
@maxkondr maxkondr self-assigned this Mar 6, 2026
@maxkondr maxkondr requested a review from a team as a code owner March 6, 2026 15:01
@maxkondr maxkondr requested review from JiriCtvrtka and ademidoff and removed request for a team March 6, 2026 15:01
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 53.16456% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.24%. Comparing base (42323b1) to head (63be17a).
⚠️ Report is 3 commits behind head on v3.

Files with missing lines Patch % Lines
managed/services/realtimeanalytics/service.go 53.16% 28 Missing and 46 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v3    #5116      +/-   ##
==========================================
- Coverage   46.25%   46.24%   -0.01%     
==========================================
  Files         390      390              
  Lines       40097    40177      +80     
==========================================
+ Hits        18546    18581      +35     
+ Misses      19616    19607       -9     
- Partials     1935     1989      +54     
Flag Coverage Δ
admin 17.89% <ø> (ø)
agent 53.32% <ø> (+0.32%) ⬆️
managed 46.97% <53.16%> (-0.14%) ⬇️
vmproxy 72.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread managed/services/realtimeanalytics/service.go Outdated
Comment thread managed/services/realtimeanalytics/service.go Outdated
Comment thread managed/services/realtimeanalytics/service.go Outdated
Comment thread managed/services/realtimeanalytics/service.go Outdated

for _, svc := range serviceList {
// Check that service has pmm-agent with version supporting RTA.
pmmAgent, err := models.FindPMMAgentsForService(s.db.Querier, svc.ServiceID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line makes the ListServices endpoint very expensive - it will make O(n) calls to the database. Let's consider the following to make it faster:

  1. Fetch all agents
  2. Make an in-memory data structure that maps Agents to a ServiceId, i.e. of type map[string]*models.Agent
  3. Use the map instead of the call to the database

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with the proposed approach is that Service is not directly linked to PMM Agent (doesn't have PMM Agent ID filled and visa versa).

In order to make such mapping it is required to repeat the logic from agent_helpers.FindPMMAgentsForService that results into the same -> no benefits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the implementation of FindPMMAgentsForService, it's even worse - we are dealing with O(n*3) requests, which is way more expensive than it should be.

Let's discuss a better way.

* feat: fetch only available services for RTA

* chore: improve typings

* chore: avoid admin data leakage

* chore: simplify typings

* chore: remove orgRole from query key

* chore: make mongodb key mandatory

* chore: expect all types for RTA

* fix: missing key on map

* chore: disable sort by operation ID

* fix: RealTimeSelection tests

* fix: typings
@fabio-silva fabio-silva requested a review from a team as a code owner March 10, 2026 11:22
@fabio-silva fabio-silva requested review from fabio-silva and matejkubinec and removed request for a team March 10, 2026 11:22
Comment thread managed/services/realtimeanalytics/service.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

@ademidoff I've opened a new pull request, #5136, to work on those changes. Once the pull request is ready, I'll request review from you.

@maxkondr maxkondr merged commit cd2ff30 into v3 Mar 16, 2026
31 checks passed
@maxkondr maxkondr deleted the PMM-14900-rta-agent-version branch March 16, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants