Skip to content

Commit 30ced43

Browse files
committed
Add more trace logging when installing monitor watches and (elastic#68752)
unmute TransportMonitoringMigrateAlertsActionTests#testLocalAlertsRemoval and TransportMonitoringMigrateAlertsActionTests#testRepeatedLocalAlertsRemoval tests Somehow during these tests the monitor watches are not installed. Both tests use the local exporter and this exporter only installs the watches under specific conditions via the elected master node. I suspect the conditions are never met. The http exporter is more relaxed when attempting to install monitor watches and the tests using the http exporter seem not to be prone by the fact that tests fail because monitor watches have not been installed. Relates to elastic#66586
1 parent 093ca66 commit 30ced43

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,20 @@ private void setupClusterAlertsTasks(ClusterState clusterState, boolean clusterS
430430
if (watches != null && watches.allPrimaryShardsActive() == false) {
431431
logger.trace("cannot manage cluster alerts because [.watches] index is not allocated");
432432
} else if ((watches == null || indexExists) && watcherSetup.compareAndSet(false, true)) {
433+
logger.trace("installing monitoring watches");
433434
getClusterAlertsInstallationAsyncActions(indexExists, asyncActions, pendingResponses);
435+
} else {
436+
logger.trace("skipping installing monitoring watches, watches=[{}], indexExists=[{}], watcherSetup=[{}]",
437+
watches, indexExists, watcherSetup.get());
434438
}
439+
} else {
440+
logger.trace("watches shouldn't be setup, because state=[{}] and clusterStateChange=[{}]", state.get(), clusterStateChange);
435441
}
442+
} else {
443+
logger.trace("watches can't be used, because xpack.watcher.enabled=[{}] and " +
444+
"xpack.monitoring.exporters._local.cluster_alerts.management.enabled=[{}]",
445+
XPackSettings.WATCHER_ENABLED.get(config.settings()),
446+
CLUSTER_ALERTS_MANAGEMENT_SETTING.getConcreteSettingForNamespace(config.name()).get(config.settings()));
436447
}
437448
}
438449

@@ -581,6 +592,7 @@ private void getClusterAlertsInstallationAsyncActions(final boolean indexExists,
581592
new ResponseActionListener<>("watch", uniqueWatchId, pendingResponses)));
582593
}
583594
} else if (addWatch) {
595+
logger.trace("adding monitoring watch [{}]", uniqueWatchId);
584596
asyncActions.add(() -> putWatch(watcher, watchId, uniqueWatchId, pendingResponses));
585597
}
586598
}

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.test.http.MockRequest;
3636
import org.elasticsearch.test.http.MockResponse;
3737
import org.elasticsearch.test.http.MockWebServer;
38+
import org.elasticsearch.test.junit.annotations.TestLogging;
3839
import org.elasticsearch.xpack.core.XPackSettings;
3940
import org.elasticsearch.xpack.core.monitoring.action.MonitoringMigrateAlertsAction;
4041
import org.elasticsearch.xpack.core.monitoring.action.MonitoringMigrateAlertsRequest;
@@ -124,7 +125,9 @@ private void stopMonitoring() {
124125
));
125126
}
126127

127-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66586")
128+
@TestLogging(
129+
value = "org.elasticsearch.xpack.monitoring.exporter.local:trace",
130+
reason = "to ensure we log local exporter on trace level")
128131
public void testLocalAlertsRemoval() throws Exception {
129132
try {
130133
// start monitoring service
@@ -159,6 +162,9 @@ public void testLocalAlertsRemoval() throws Exception {
159162
}
160163
}
161164

165+
@TestLogging(
166+
value = "org.elasticsearch.xpack.monitoring.exporter.local:trace",
167+
reason = "to ensure we log local exporter on trace level")
162168
public void testRepeatedLocalAlertsRemoval() throws Exception {
163169
try {
164170
// start monitoring service

0 commit comments

Comments
 (0)