Skip to content

[ResponseOps][alerting] add rule info to logging in alertsClient#190857

Merged
pmuellr merged 1 commit intoelastic:mainfrom
pmuellr:190376-improve-alerts-client-log-messages
Aug 22, 2024
Merged

[ResponseOps][alerting] add rule info to logging in alertsClient#190857
pmuellr merged 1 commit intoelastic:mainfrom
pmuellr:190376-improve-alerts-client-log-messages

Conversation

@pmuellr
Copy link
Contributor

@pmuellr pmuellr commented Aug 20, 2024

Summary

While investigating some issues with the alertsClient, I realized that we weren't writing out any rule information for the logged messages. This made debugging quite difficult, as I wanted to see the rule, so had to search through the alerts indices for the specified alert to get it's rule id, rule type, etc.

As an example, see #190376

This PR adds that kind of rule info to the logged messages in alertsClient, as well as the typical sort of tags we write out (rule id, rule type, module).

Checklist

Delete any items that are not applicable to this PR.

While investigating some issues with the alertsClient, I realized that
we weren't writing out any rule information for the logged messages.
This made debugging quite difficult, as I wanted to see the rule, so
had to search through the alerts indices for the specified alert to get
it's rule id, rule type, etc.

This PR adds that kind of rule info to the logged messages in alertsClient,
as well as the typical sort of tags we write out (rule id, rule type, module).
@pmuellr pmuellr added Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.15.1 labels Aug 20, 2024
@pmuellr pmuellr requested a review from a team as a code owner August 20, 2024 20:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@pmuellr pmuellr requested review from doakalexi and ymao1 August 20, 2024 20:18
@kibana-ci
Copy link

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

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

Copy link
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

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

Nice, this is useful!

this._isUsingDataStreams = this.options.dataStreamAdapter.isUsingDataStreams();
this.ruleInfoMessage = `for ${this.ruleType.id}:${this.options.rule.id} '${this.options.rule.name}'`;
this.logTags = { tags: [this.ruleType.id, this.options.rule.id, 'alerts-client'] };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

With this PR: #187785, the logger that's passed into the alerts client should already include the rule ID and rule type ID in the tags, so I think you just need to add the alerts-client tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this out, and it didn't add the tags. Looks like we're getting a normal logger here

this.logger = context.logger.get(loggerId);

which is then replaced in run() here:

this.logger = createTaskRunnerLogger({ logger: this.logger, tags: [ruleId, this.ruleType.id] });

Looking through the code, seems like it should have picked up ours, not the original one, not sure why it didn't.

I tested this by changing a condition around one of the comparisons in the code that would generate a log, like here:

} else if (!isValidAlertIndexName(alertIndex)) {

I changed !isValidAlertIndexName() to isValidAlertIndexName().

To see the tags when running, I had to switch to JSON mode:

logging:
  appenders:
    console_appender:
      type: console
      layout:
        type: json
#        type: pattern - what I normally use
#        highlight: true

I also ran this in a debugger and saw that it wasn't our logger but a base one, when the alertsClient logger logged.

I feel like opening another issue to investigate this, rather than trying to figure out why, then fix it, and find 10K tests to fix :-). But maybe it's simpler?

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. But I'm fine with figuring it out later :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's here:

Instead of passing in this.options.logger into the AlertsClient, we could pass in opts.logger to get the TaskRunner logger. But again, it's not a big deal and I don't think it's something we need to update rn.

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@doakalexi doakalexi left a comment

Choose a reason for hiding this comment

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

LGTM!

@pmuellr pmuellr merged commit 07717a4 into elastic:main Aug 22, 2024
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 22, 2024
…stic#190857)

## Summary

While investigating some issues with the alertsClient, I realized that
we weren't writing out any rule information for the logged messages.
This made debugging quite difficult, as I wanted to see the rule, so had
to search through the alerts indices for the specified alert to get it's
rule id, rule type, etc.

As an example, see elastic#190376

This PR adds that kind of rule info to the logged messages in
alertsClient, as well as the typical sort of tags we write out (rule id,
rule type, module).

(cherry picked from commit 07717a4)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.15

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Aug 22, 2024
…nt (#190857) (#191094)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[ResponseOps][alerting] add rule info to logging in alertsClient
(#190857)](#190857)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Patrick
Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2024-08-22T14:29:22Z","message":"[ResponseOps][alerting]
add rule info to logging in alertsClient (#190857)\n\n##
Summary\r\n\r\nWhile investigating some issues with the alertsClient, I
realized that\r\nwe weren't writing out any rule information for the
logged messages.\r\nThis made debugging quite difficult, as I wanted to
see the rule, so had\r\nto search through the alerts indices for the
specified alert to get it's\r\nrule id, rule type, etc.\r\n\r\nAs an
example, see https://github.com/elastic/kibana/issues/190376\r\n\r\nThis
PR adds that kind of rule info to the logged messages
in\r\nalertsClient, as well as the typical sort of tags we write out
(rule id,\r\nrule type,
module).","sha":"07717a43ab369847d87c8e15071759502a89c48b","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v8.16.0","v8.15.1"],"title":"[ResponseOps][alerting]
add rule info to logging in
alertsClient","number":190857,"url":"https://github.com/elastic/kibana/pull/190857","mergeCommit":{"message":"[ResponseOps][alerting]
add rule info to logging in alertsClient (#190857)\n\n##
Summary\r\n\r\nWhile investigating some issues with the alertsClient, I
realized that\r\nwe weren't writing out any rule information for the
logged messages.\r\nThis made debugging quite difficult, as I wanted to
see the rule, so had\r\nto search through the alerts indices for the
specified alert to get it's\r\nrule id, rule type, etc.\r\n\r\nAs an
example, see https://github.com/elastic/kibana/issues/190376\r\n\r\nThis
PR adds that kind of rule info to the logged messages
in\r\nalertsClient, as well as the typical sort of tags we write out
(rule id,\r\nrule type,
module).","sha":"07717a43ab369847d87c8e15071759502a89c48b"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/190857","number":190857,"mergeCommit":{"message":"[ResponseOps][alerting]
add rule info to logging in alertsClient (#190857)\n\n##
Summary\r\n\r\nWhile investigating some issues with the alertsClient, I
realized that\r\nwe weren't writing out any rule information for the
logged messages.\r\nThis made debugging quite difficult, as I wanted to
see the rule, so had\r\nto search through the alerts indices for the
specified alert to get it's\r\nrule id, rule type, etc.\r\n\r\nAs an
example, see https://github.com/elastic/kibana/issues/190376\r\n\r\nThis
PR adds that kind of rule info to the logged messages
in\r\nalertsClient, as well as the typical sort of tags we write out
(rule id,\r\nrule type,
module).","sha":"07717a43ab369847d87c8e15071759502a89c48b"}},{"branch":"8.15","label":"v8.15.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Patrick Mueller <patrick.mueller@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.15.1 v8.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants