Skip to content

Commit

Permalink
[Rules and Alerting][Stack Monitoring] Quote cluster uuid in global s…
Browse files Browse the repository at this point in the history
…tate link sent via alerting rules (elastic#190341)

## Summary

Closes elastic#191250

This PR fixes the URL contained in the Shard size alerting rule when the
email body contains the `{{ context.internalFullMessage}}` action
variable.

The generated URL which triggers a `rison decoder error`

`https://<host>/app/monitoring#/elasticsearch/indices/<index>?_g=(cluster_uuid:foobar))`

is fixed by adding a pair of single quotes around the cluster UUID

`https://<host>/app/monitoring#/elasticsearch/indices/<index>?_g=(cluster_uuid:'foobar'))`

Worth noting that this issue doesn't only impact the Shard size rule,
but many other rule types, namely:
* CPU usage
* Disk usage
* Memory usage
* CCR read exception
* ES version mismatch
* Kibana version mismatch
* Logstash version mismatch
* Missing monitoring data
* Thread pool search rejections
* Thread pool write rejections

---------

Co-authored-by: Valentin Crettaz <valentin.crettaz@consulthys.com>
Co-authored-by: Valentin Crettaz <valentin.crettaz@elastic.co>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent ffd4076 commit 6ba4d74
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/rules/base_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class BaseRule {
}

protected createGlobalStateLink(link: string, clusterUuid: string, ccs?: string) {
const globalState = [`cluster_uuid:${clusterUuid}`];
const globalState = [`cluster_uuid:'${clusterUuid}'`];
if (ccs) {
globalState.push(`ccs:${ccs}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ describe('CCRReadExceptionsRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'BcK-0pmsQniyPQfZuauuXw_remote_cluster_1:.follower_index_1',
context: {
internalFullMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Current 'follower_index' index affected: ${followerIndex}. [View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Current 'follower_index' index affected: ${followerIndex}. [View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Verify follower and leader index relationships on the affected remote cluster.`,
action: `[View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain:
'Verify follower and leader index relationships on the affected remote cluster.',
clusterName,
Expand Down Expand Up @@ -452,9 +452,9 @@ describe('CCRReadExceptionsRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'BcK-0pmsQniyPQfZuauuXw_remote_cluster_1:.follower_index_1',
context: {
internalFullMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Current 'follower_index' index affected: ${followerIndex}. [View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
internalFullMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Current 'follower_index' index affected: ${followerIndex}. [View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
internalShortMessage: `CCR read exceptions alert is firing for the following remote cluster: ${remoteCluster}. Verify follower and leader index relationships on the affected remote cluster.`,
action: `[View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
action: `[View CCR stats](http://localhost:5601/app/monitoring#/elasticsearch/ccr?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
actionPlain:
'Verify follower and leader index relationships on the affected remote cluster.',
clusterName,
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/monitoring/server/rules/cpu_usage_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ describe('CpuUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify CPU level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify CPU level of node.',
clusterName,
count,
Expand Down Expand Up @@ -315,9 +315,9 @@ describe('CpuUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:${ccs}))`,
internalFullMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:${ccs}))`,
internalShortMessage: `CPU usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify CPU level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
actionPlain: 'Verify CPU level of node.',
clusterName,
count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ describe('DiskUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify disk usage level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify disk usage level of node.',
clusterName,
count,
Expand Down Expand Up @@ -381,9 +381,9 @@ describe('DiskUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:${ccs}))`,
internalFullMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:${ccs}))`,
internalShortMessage: `Disk usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify disk usage level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/myNodeId?_g=(cluster_uuid:abc123,ccs:testCluster))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/myNodeId?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
actionPlain: 'Verify disk usage level of node.',
clusterName,
count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ describe('ElasticsearchVersionMismatchAlert', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'abc123',
context: {
action: `[View nodes](UNIT_TEST_URL/app/monitoring#/elasticsearch/nodes?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View nodes](UNIT_TEST_URL/app/monitoring#/elasticsearch/nodes?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify you have the same version across all nodes.',
internalFullMessage: `Elasticsearch version mismatch alert is firing for testCluster. Elasticsearch is running 8.0.0, 7.2.1. [View nodes](UNIT_TEST_URL/app/monitoring#/elasticsearch/nodes?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Elasticsearch version mismatch alert is firing for testCluster. Elasticsearch is running 8.0.0, 7.2.1. [View nodes](UNIT_TEST_URL/app/monitoring#/elasticsearch/nodes?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage:
'Elasticsearch version mismatch alert is firing for testCluster. Verify you have the same version across all nodes.',
versionList: ['8.0.0', '7.2.1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ describe('KibanaVersionMismatchRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'abc123',
context: {
action: `[View instances](UNIT_TEST_URL/app/monitoring#/kibana/instances?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View instances](UNIT_TEST_URL/app/monitoring#/kibana/instances?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify you have the same version across all instances.',
internalFullMessage: `Kibana version mismatch alert is firing for testCluster. Kibana is running 8.0.0, 7.2.1. [View instances](UNIT_TEST_URL/app/monitoring#/kibana/instances?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Kibana version mismatch alert is firing for testCluster. Kibana is running 8.0.0, 7.2.1. [View instances](UNIT_TEST_URL/app/monitoring#/kibana/instances?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage:
'Kibana version mismatch alert is firing for testCluster. Verify you have the same version across all instances.',
versionList: ['8.0.0', '7.2.1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ describe('LargeShardSizeRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'abc123:apm-8.0.0-onboarding-2021.06.30',
context: {
internalFullMessage: `Large shard size alert is firing for the following index: ${shardIndex}. [View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Large shard size alert is firing for the following index: ${shardIndex}. [View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `Large shard size alert is firing for the following index: ${shardIndex}. Investigate indices with large shard sizes.`,
action: `[View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Investigate indices with large shard sizes.',
clusterName,
state: 'firing',
Expand Down Expand Up @@ -327,9 +327,9 @@ describe('LargeShardSizeRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'abc123:apm-8.0.0-onboarding-2021.06.30',
context: {
internalFullMessage: `Large shard size alert is firing for the following index: ${shardIndex}. [View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
internalFullMessage: `Large shard size alert is firing for the following index: ${shardIndex}. [View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
internalShortMessage: `Large shard size alert is firing for the following index: ${shardIndex}. Investigate indices with large shard sizes.`,
action: `[View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
action: `[View index shard size stats](http://localhost:5601/app/monitoring#/elasticsearch/indices/${shardIndex}?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
actionPlain: 'Investigate indices with large shard sizes.',
clusterName,
state: 'firing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ describe('LogstashVersionMismatchRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'abc123',
context: {
action: `[View nodes](UNIT_TEST_URL/app/monitoring#/logstash/nodes?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View nodes](UNIT_TEST_URL/app/monitoring#/logstash/nodes?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify you have the same version across all nodes.',
internalFullMessage: `Logstash version mismatch alert is firing for testCluster. Logstash is running 8.0.0, 7.2.1. [View nodes](UNIT_TEST_URL/app/monitoring#/logstash/nodes?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Logstash version mismatch alert is firing for testCluster. Logstash is running 8.0.0, 7.2.1. [View nodes](UNIT_TEST_URL/app/monitoring#/logstash/nodes?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage:
'Logstash version mismatch alert is firing for testCluster. Verify you have the same version across all nodes.',
versionList: ['8.0.0', '7.2.1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ describe('MemoryUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify memory usage level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain: 'Verify memory usage level of node.',
clusterName,
count,
Expand Down Expand Up @@ -380,9 +380,9 @@ describe('MemoryUsageRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'myNodeId',
context: {
internalFullMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:${ccs}))`,
internalFullMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. [View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:${ccs}))`,
internalShortMessage: `Memory usage alert is firing for node ${nodeName} in cluster: ${clusterName}. Verify memory usage level of node.`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:testCluster))`,
action: `[View node](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:testCluster))`,
actionPlain: 'Verify memory usage level of node.',
clusterName,
count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ describe('MissingMonitoringDataRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'esNode1',
context: {
internalFullMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. [View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
internalFullMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. [View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
internalShortMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. Verify the node is up and running, then double check the monitoring settings.`,
nodes: `node: ${nodeName}`,
node: `node: ${nodeName}`,
action: `[View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid}))`,
action: `[View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}'))`,
actionPlain:
'Verify the node is up and running, then double check the monitoring settings.',
clusterName,
Expand Down Expand Up @@ -287,11 +287,11 @@ describe('MissingMonitoringDataRule', () => {
expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({
id: 'esNode1',
context: {
internalFullMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. [View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:${ccs}))`,
internalFullMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. [View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:${ccs}))`,
internalShortMessage: `We have not detected any monitoring data for node ${nodeName} in cluster: ${clusterName}. Verify the node is up and running, then double check the monitoring settings.`,
nodes: `node: ${nodeName}`,
node: `node: ${nodeName}`,
action: `[View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:${clusterUuid},ccs:${ccs}))`,
action: `[View what monitoring data we do have for this node.](http://localhost:5601/app/monitoring#/elasticsearch/nodes/${nodeId}?_g=(cluster_uuid:'${clusterUuid}',ccs:${ccs}))`,
actionPlain:
'Verify the node is up and running, then double check the monitoring settings.',
clusterName,
Expand Down
Loading

0 comments on commit 6ba4d74

Please sign in to comment.