Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

sorenlouv
Copy link
Member

@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

@apmmachine
Copy link
Contributor

🤖 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 All issues that need APM UI Team support Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team 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 as a code owner December 9, 2023 13:47
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
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 All issues that need APM UI Team support 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 All issues that need APM UI Team support label Dec 10, 2023
@kibana-ci
Copy link
Collaborator

💛 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
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
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
Member 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.

internalESClient.search<AgentConfiguration>(
'list_agent_configuration',
params
),
getConfigsAppliedToAgentsThroughFleet(internalESClient, apmIndices),
apmEventClient ? getAgentConfigEtagMetrics(apmEventClient) : undefined,
Copy link
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
Member 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
42 checks passed
@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
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
Member 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
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
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
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
Member Author

Backported to 8.12 in #173120

@sorenlouv sorenlouv added the backport:skip This commit 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 commit does not require backporting release_note:fix Team:APM All issues that need APM UI Team support Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team 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-*
6 participants