Skip to content

[APM] Remove usage of internal client when fetching agent config etags metrics#173001

Merged
sorenlouv merged 2 commits intoelastic:mainfrom
sorenlouv:remove-usage-of-internal-client-for-agent-config-etags
Dec 11, 2023
Merged

[APM] Remove usage of internal client when fetching agent config etags metrics#173001
sorenlouv merged 2 commits intoelastic:mainfrom
sorenlouv:remove-usage-of-internal-client-for-agent-config-etags

Conversation

@sorenlouv
Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv commented Dec 8, 2023

Closes: #170031
Replaces: elastic/elasticsearch#101467

Problem
We need to know if an agent config has been applied at the edge (by APM agents). This is determined by comparing the etag (hash) of the config, with the etag applied at the edges.

Previously the agent config itself contained this information (config.applied_by_agent) but when running with fleet this will instead be captured in agent_config metric documents.

Currently the internal kibana user retrieves the agent_config metric documents from the APM metric index (metrics-apm-* by default). This index is configurable by the end-user so can be changed to something the internal user doesn't have access to. This is a problem.

Solution

This PR replaces the calls made by the internal client with calls made by the authenticated end user (via APMEventClient). This approach works for requests made from the browser/UI but doesn't work for background tasks made by fleet. To work around this we only conditionally query the metric index if the APMEventClient is available.
If APMEventClient is not available applied_by_agent will be undefined

@ghost
Copy link
Copy Markdown

ghost commented Dec 8, 2023

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@sorenlouv sorenlouv force-pushed the remove-usage-of-internal-client-for-agent-config-etags branch from c59fc7b to 6499c97 Compare December 8, 2023 23:49
@sorenlouv sorenlouv added Team:APM - DEPRECATED Use Team:obs-ux-infra_services. Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. labels Dec 9, 2023
@sorenlouv sorenlouv marked this pull request as ready for review December 9, 2023 13:47
@sorenlouv sorenlouv requested a review from a team December 9, 2023 13:47
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/apm-ui (Team:APM)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@sorenlouv sorenlouv force-pushed the remove-usage-of-internal-client-for-agent-config-etags branch from 6499c97 to 36f98aa Compare December 9, 2023 13:48
@sorenlouv sorenlouv removed the Team:APM - DEPRECATED Use Team:obs-ux-infra_services. label Dec 9, 2023
@sorenlouv sorenlouv force-pushed the remove-usage-of-internal-client-for-agent-config-etags branch from 36f98aa to bb39c37 Compare December 10, 2023 23:29
@botelastic botelastic bot added the Team:APM - DEPRECATED Use Team:obs-ux-infra_services. label Dec 10, 2023
@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Detection Engine - Security Solution Cypress Tests #6 / Alert user assignment - ESS & Serverless Updating assignees (single alert) removing all assignees via More actions in alerts table removing all assignees via More actions in alerts table
  • [job] [logs] Serverless Investigations - Security Solution Cypress Tests #5 / Detection response view Redirection to AlertPage should redirect to alert page with host, status and severity as the filters should redirect to alert page with host, status and severity as the filters
  • [job] [logs] Serverless Investigations - Security Solution Cypress Tests #5 / Detection response view Redirection to AlertPage should redirect to alert page with rule name & status as filters should redirect to alert page with rule name & status as filters
  • [job] [logs] Serverless Investigations - Security Solution Cypress Tests #5 / Detection response view Redirection to AlertPage should redirect to alert page with user and status as the filters should redirect to alert page with user and status as the filters
  • [job] [logs] Serverless Investigations - Security Solution Cypress Tests #5 / Detection response view Redirection to AlertPage should redirect to alert page with user, status and severity as the filters should redirect to alert page with user, status and severity as the filters

Metrics [docs]

✅ unchanged

History

  • 💛 Build #182840 was flaky 36f98aad4e3c0fde989944bb0692228cd1fafc17

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@sorenlouv sorenlouv changed the title [APM] Remove usage of internal client when fetching agent config etags [APM] Remove usage of internal client when fetching agent config etags metrics Dec 11, 2023
Copy link
Copy Markdown
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

LGTM... just added small suggestions.

};
}

async function getIsAppliedByAgent({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could probably create a simple unit test to cover this function.

Copy link
Copy Markdown
Contributor Author

@sorenlouv sorenlouv Dec 11, 2023

Choose a reason for hiding this comment

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

This is already covered by the api test. A unit test would mock out the call to getAgentConfigEtagMetrics so it would only cover the check on agentConfiguration.applied_by_agent and appliedEtags.includes(agentConfiguration.etag. I don't think it's worth it.

If it was functionality with value in itself, then maybe, but in this case it's just an implementation detail. It might as well be inlined in findExactConfiguration instead of a separate function.

params
),
getConfigsAppliedToAgentsThroughFleet(internalESClient, apmIndices),
apmEventClient ? getAgentConfigEtagMetrics(apmEventClient) : undefined,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't you call getIsAppliedByAgent so the logic is in one place?

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.

No, getIsAppliedByAgent is for a single agent configuration. In this case we need to fetch every agent configuration, and map them with all available etags so we want to fetch those two in parallel.

@sorenlouv sorenlouv merged commit 58c7958 into elastic:main Dec 11, 2023
@sorenlouv sorenlouv deleted the remove-usage-of-internal-client-for-agent-config-etags branch December 11, 2023 11:28
sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Dec 11, 2023
…s metrics (elastic#173001)

Closes: elastic#170031
Replaces: elastic/elasticsearch#101467

**Problem**
We need to know if an agent config has been applied at the edge (by APM
agents). This is determined by comparing the etag (hash) of the config,
with the etag applied at the edges.

Previously the agent config itself contained this information
(`config.applied_by_agent`) but when running with fleet this will
instead be captured in `agent_config` metric documents.

Currently the internal kibana user retrieves the `agent_config` metric
documents from the APM metric index (`metrics-apm-*` by default). This
index is configurable by the end-user so can be changed to something the
internal user doesn't have access to. This is a problem.

**Solution**

This PR replaces the calls made by the internal client with calls made
by the authenticated end user (via `APMEventClient`). This approach
works for requests made from the browser/UI but doesn't work for
background tasks made by fleet. To work around this we only
conditionally query the metric index if the `APMEventClient` is
available.
If `APMEventClient` is not available `applied_by_agent` will be
`undefined`

(cherry picked from commit 58c7958)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

sorenlouv added a commit to kibanamachine/kibana that referenced this pull request Dec 11, 2023
…s metrics (elastic#173001)

Closes: elastic#170031
Replaces: elastic/elasticsearch#101467

**Problem**
We need to know if an agent config has been applied at the edge (by APM
agents). This is determined by comparing the etag (hash) of the config,
with the etag applied at the edges.

Previously the agent config itself contained this information
(`config.applied_by_agent`) but when running with fleet this will
instead be captured in `agent_config` metric documents.

Currently the internal kibana user retrieves the `agent_config` metric
documents from the APM metric index (`metrics-apm-*` by default). This
index is configurable by the end-user so can be changed to something the
internal user doesn't have access to. This is a problem.

**Solution**

This PR replaces the calls made by the internal client with calls made
by the authenticated end user (via `APMEventClient`). This approach
works for requests made from the browser/UI but doesn't work for
background tasks made by fleet. To work around this we only
conditionally query the metric index if the `APMEventClient` is
available.
If `APMEventClient` is not available `applied_by_agent` will be
`undefined`

(cherry picked from commit 58c7958)
@sorenlouv
Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Dec 11, 2023
…s metrics (elastic#173001)

Closes: elastic#170031
Replaces: elastic/elasticsearch#101467

**Problem**
We need to know if an agent config has been applied at the edge (by APM
agents). This is determined by comparing the etag (hash) of the config,
with the etag applied at the edges.

Previously the agent config itself contained this information
(`config.applied_by_agent`) but when running with fleet this will
instead be captured in `agent_config` metric documents.

Currently the internal kibana user retrieves the `agent_config` metric
documents from the APM metric index (`metrics-apm-*` by default). This
index is configurable by the end-user so can be changed to something the
internal user doesn't have access to. This is a problem.

**Solution**

This PR replaces the calls made by the internal client with calls made
by the authenticated end user (via `APMEventClient`). This approach
works for requests made from the browser/UI but doesn't work for
background tasks made by fleet. To work around this we only
conditionally query the metric index if the `APMEventClient` is
available.
If `APMEventClient` is not available `applied_by_agent` will be
`undefined`

(cherry picked from commit 58c7958)
sorenlouv added a commit that referenced this pull request Dec 12, 2023
…ig etags metrics (#173001) | [APM] Unskip apm api test suite (#173055) (#173120)

Backports the following to `8.12`:

- #173055
- #173001

<!--BACKPORT {commits} BACKPORT-->
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 12, 2023
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

1 similar comment
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

@sorenlouv sorenlouv removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 13, 2023
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 17, 2023
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

@sorenlouv sorenlouv removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 17, 2023
@sorenlouv
Copy link
Copy Markdown
Contributor Author

Backported to 8.12 in #173120

@sorenlouv sorenlouv added the backport:skip This PR does not require backporting label Dec 17, 2023
sorenlouv pushed a commit to sorenlouv/kibana that referenced this pull request May 1, 2024
…s metrics (elastic#173001)

Closes: elastic#170031
Replaces: elastic/elasticsearch#101467

**Problem**
We need to know if an agent config has been applied at the edge (by APM
agents). This is determined by comparing the etag (hash) of the config,
with the etag applied at the edges.

Previously the agent config itself contained this information
(`config.applied_by_agent`) but when running with fleet this will
instead be captured in `agent_config` metric documents.

Currently the internal kibana user retrieves the `agent_config` metric
documents from the APM metric index (`metrics-apm-*` by default). This
index is configurable by the end-user so can be changed to something the
internal user doesn't have access to. This is a problem.

**Solution**

This PR replaces the calls made by the internal client with calls made
by the authenticated end user (via `APMEventClient`). This approach
works for requests made from the browser/UI but doesn't work for
background tasks made by fleet. To work around this we only
conditionally query the metric index if the `APMEventClient` is
available.
If `APMEventClient` is not available `applied_by_agent` will be
`undefined`

(cherry picked from commit 58c7958)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:fix Team:APM - DEPRECATED Use Team:obs-ux-infra_services. Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v8.12.0 v8.13.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kibana_system role missing read permissions for metrics-apm-* and logs-apm-*

5 participants