Skip to content

Improve LocalStateMonitoring for tests. #66997

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

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.shard.IndexSettingProvider;
import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.indices.analysis.AnalysisModule;
Expand Down Expand Up @@ -554,4 +555,12 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
.flatMap(p -> p.getSystemIndexDescriptors(this.settings).stream())
.collect(Collectors.toList());
}

@Override
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
return filterPlugins(MapperPlugin.class).stream()
.map(MapperPlugin::getMetadataMappers)
.flatMap (map -> map.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
1 change: 1 addition & 0 deletions x-pack/plugin/monitoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testImplementation project(xpackModule('watcher'))

testImplementation project(xpackModule('ilm'))
testImplementation project(xpackModule('data-streams'))
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
*/
package org.elasticsearch.xpack.monitoring;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
Expand All @@ -15,13 +19,19 @@
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
import org.elasticsearch.xpack.core.action.TransportXPackUsageAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageResponse;
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction;
import org.elasticsearch.xpack.core.ssl.SSLService;
import org.elasticsearch.xpack.datastreams.DataStreamsPlugin;
import org.elasticsearch.xpack.ilm.IndexLifecycle;
import org.elasticsearch.xpack.watcher.Watcher;

Expand Down Expand Up @@ -79,6 +89,7 @@ protected XPackLicenseState getLicenseState() {
}
});
plugins.add(new IndexLifecycle(settings));
plugins.add(new DataStreamsPlugin()); // Otherwise the watcher history index template can't be added
}

public Monitoring getMonitoring() {
Expand All @@ -89,4 +100,46 @@ public Monitoring getMonitoring() {
protected Class<? extends TransportAction<XPackUsageRequest, XPackUsageResponse>> getUsageAction() {
return MonitoringTransportXPackUsageAction.class;
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
var actions = super.getActions();
Copy link
Member Author

Choose a reason for hiding this comment

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

Additional note: It is not possible to add the ccr / enrich plugins (like with data streams), because the monitoring gradle project can't rely on these gradle modules, because both ccr and enrich gradle projects already depend on the monitoring gradle project.

// ccr StatsCollector
actions.add(new ActionHandler<>(CcrStatsAction.INSTANCE, TransportCcrStatsStubAction.class));
// For EnrichStatsCollector:
actions.add(new ActionHandler<>(EnrichStatsAction.INSTANCE, TransportEnrichStatsStubAction.class));
return actions;
}

public static class TransportCcrStatsStubAction extends HandledTransportAction<CcrStatsAction.Request, CcrStatsAction.Response> {

@Inject
public TransportCcrStatsStubAction(TransportService transportService, ActionFilters actionFilters) {
super(CcrStatsAction.NAME, transportService, actionFilters, CcrStatsAction.Request::new);
}

@Override
protected void doExecute(Task task, CcrStatsAction.Request request, ActionListener<CcrStatsAction.Response> listener) {
AutoFollowStats autoFollowStats =
new AutoFollowStats(0, 0, 0, Collections.emptyNavigableMap(), Collections.emptyNavigableMap());
FollowStatsAction.StatsResponses statsResponses =
new FollowStatsAction.StatsResponses(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
listener.onResponse(new CcrStatsAction.Response(autoFollowStats, statsResponses));
}
}

public static class TransportEnrichStatsStubAction
extends HandledTransportAction<EnrichStatsAction.Request, EnrichStatsAction.Response> {

@Inject
public TransportEnrichStatsStubAction(TransportService transportService, ActionFilters actionFilters) {
super(EnrichStatsAction.NAME, transportService, actionFilters, EnrichStatsAction.Request::new);
}

@Override
protected void doExecute(Task task, EnrichStatsAction.Request request, ActionListener<EnrichStatsAction.Response> listener) {
listener.onResponse(new EnrichStatsAction.Response(Collections.emptyList(), Collections.emptyList()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ private void stopMonitoring() {
));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66586")
public void testLocalAlertsRemoval() throws Exception {
try {
// start monitoring service
Expand Down Expand Up @@ -187,7 +186,6 @@ public void testRepeatedLocalAlertsRemoval() throws Exception {
}
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66586")
public void testDisabledLocalExporterAlertsRemoval() throws Exception {
try {
// start monitoring service
Expand Down Expand Up @@ -230,7 +228,6 @@ public void testDisabledLocalExporterAlertsRemoval() throws Exception {
}
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66586")
public void testLocalExporterWithAlertingDisabled() throws Exception {
try {
// start monitoring service
Expand Down