-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] Add action to decommission legacy monitoring cluster alerts (#6…
…4373) (#66309) Adds an action that will proactively remove any watches that monitoring has configured. The action toggles on a new setting that informs the cluster to tear down any previously created cluster alerts, and after that is accepted, the action immediately attempts a best-effort refresh of cluster alert resources in order to force their removal in case collection is disabled or delayed. Since resources are controlled lazily by the existing monitoring exporters, extra care was taken to ensure that any in-flight resource management operations do not race against any resource actions taken by the migration action. Resource installation code was updated with callbacks to report any errors instead of just logging them.
- Loading branch information
Showing
39 changed files
with
2,071 additions
and
224 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...in/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringMigrateAlertsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.monitoring.action; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class MonitoringMigrateAlertsAction extends ActionType<MonitoringMigrateAlertsResponse> { | ||
|
||
public static final MonitoringMigrateAlertsAction INSTANCE = new MonitoringMigrateAlertsAction(); | ||
public static final String NAME = "cluster:admin/xpack/monitoring/migrate/alerts"; | ||
|
||
public MonitoringMigrateAlertsAction() { | ||
super(NAME, MonitoringMigrateAlertsResponse::new); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...n/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringMigrateAlertsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.monitoring.action; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
|
||
import java.io.IOException; | ||
|
||
public class MonitoringMigrateAlertsRequest extends MasterNodeRequest<MonitoringMigrateAlertsRequest> { | ||
|
||
public MonitoringMigrateAlertsRequest() {} | ||
|
||
public MonitoringMigrateAlertsRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
.../java/org/elasticsearch/xpack/core/monitoring/action/MonitoringMigrateAlertsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.monitoring.action; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class MonitoringMigrateAlertsResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private final List<ExporterMigrationResult> exporters; | ||
|
||
public MonitoringMigrateAlertsResponse(List<ExporterMigrationResult> exporters) { | ||
this.exporters = exporters; | ||
} | ||
|
||
public MonitoringMigrateAlertsResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.exporters = in.readList(ExporterMigrationResult::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeList(exporters); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
return builder.startObject() | ||
.array("exporters", exporters) | ||
.endObject(); | ||
} | ||
|
||
public List<ExporterMigrationResult> getExporters() { | ||
return exporters; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MonitoringMigrateAlertsResponse response = (MonitoringMigrateAlertsResponse) o; | ||
return Objects.equals(exporters, response.exporters); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(exporters); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MonitoringMigrateAlertsResponse{" + | ||
"exporters=" + exporters + | ||
'}'; | ||
} | ||
|
||
public static class ExporterMigrationResult implements Writeable, ToXContentObject { | ||
|
||
private final String name; | ||
private final String type; | ||
private final boolean migrationComplete; | ||
private final Exception reason; | ||
|
||
public ExporterMigrationResult(String name, String type, boolean migrationComplete, Exception reason) { | ||
this.name = name; | ||
this.type = type; | ||
this.migrationComplete = migrationComplete; | ||
this.reason = reason; | ||
} | ||
|
||
public ExporterMigrationResult(StreamInput in) throws IOException { | ||
this.name = in.readString(); | ||
this.type = in.readString(); | ||
this.migrationComplete = in.readBoolean(); | ||
this.reason = in.readException(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(name); | ||
out.writeString(type); | ||
out.writeBoolean(migrationComplete); | ||
out.writeException(reason); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("name", name); | ||
builder.field("type", type); | ||
builder.field("migration_complete", migrationComplete); | ||
if (reason != null) { | ||
builder.startObject("reason"); | ||
ElasticsearchException.generateThrowableXContent(builder, params, reason); | ||
builder.endObject(); | ||
} | ||
} | ||
return builder.endObject(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public boolean isMigrationComplete() { | ||
return migrationComplete; | ||
} | ||
|
||
@Nullable | ||
public Exception getReason() { | ||
return reason; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ExporterMigrationResult that = (ExporterMigrationResult) o; | ||
return migrationComplete == that.migrationComplete && | ||
Objects.equals(name, that.name) && | ||
Objects.equals(type, that.type); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, type, migrationComplete); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ExporterMigrationResult{" + | ||
"name='" + name + '\'' + | ||
", type='" + type + '\'' + | ||
", migrationComplete=" + migrationComplete + | ||
", reason=" + reason + | ||
'}'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.