-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SLM support to xpack usage and info APIs (#48149)
* Add SLM support to xpack usage and info APIs This is a backport of #48096 This adds the missing xpack usage and info information into the `/_xpack` and `/_xpack/usage` APIs. The output now looks like: ``` GET /_xpack/usage { ... "slm" : { "available" : true, "enabled" : true, "policy_count" : 1, "policy_stats" : { "retention_runs" : 0, ... } } ``` and ``` GET /_xpack { ... "features" : { ... "slm" : { "available" : true, "enabled" : true }, ... } } ``` Relates to #43663 * Fix missing license
- Loading branch information
Showing
7 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
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
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
72 changes: 72 additions & 0 deletions
72
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SLMFeatureSetUsage.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,72 @@ | ||
/* | ||
* 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.slm; | ||
|
||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.slm.SnapshotLifecycleStats; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class SLMFeatureSetUsage extends XPackFeatureSet.Usage { | ||
@Nullable | ||
private final SnapshotLifecycleStats slmStats; | ||
|
||
public SLMFeatureSetUsage(StreamInput in) throws IOException { | ||
super(in); | ||
this.slmStats = in.readOptionalWriteable(SnapshotLifecycleStats::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalWriteable(this.slmStats); | ||
} | ||
|
||
public SLMFeatureSetUsage(boolean available, boolean enabled, @Nullable SnapshotLifecycleStats slmStats) { | ||
super(XPackField.SNAPSHOT_LIFECYCLE, available, enabled); | ||
this.slmStats = slmStats; | ||
} | ||
|
||
public SnapshotLifecycleStats getStats() { | ||
return this.slmStats; | ||
} | ||
|
||
@Override | ||
protected void innerXContent(XContentBuilder builder, Params params) throws IOException { | ||
super.innerXContent(builder, params); | ||
if (slmStats != null) { | ||
builder.field("policy_count", slmStats.getMetrics().size()); | ||
builder.field("policy_stats", slmStats); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(available, enabled, slmStats); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
SLMFeatureSetUsage other = (SLMFeatureSetUsage) obj; | ||
return Objects.equals(available, other.available) && | ||
Objects.equals(enabled, other.enabled) && | ||
Objects.equals(slmStats, other.slmStats); | ||
} | ||
|
||
} |
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
67 changes: 67 additions & 0 deletions
67
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMFeatureSet.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,67 @@ | ||
/* | ||
* 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.slm; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.core.slm.SLMFeatureSetUsage; | ||
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; | ||
|
||
import java.util.Map; | ||
|
||
public class SLMFeatureSet implements XPackFeatureSet { | ||
|
||
private final boolean enabled; | ||
private final XPackLicenseState licenseState; | ||
private ClusterService clusterService; | ||
|
||
@Inject | ||
public SLMFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, ClusterService clusterService) { | ||
this.clusterService = clusterService; | ||
this.enabled = XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.get(settings); | ||
this.licenseState = licenseState; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return XPackField.SNAPSHOT_LIFECYCLE; | ||
} | ||
|
||
@Override | ||
public boolean available() { | ||
return licenseState != null && licenseState.isIndexLifecycleAllowed(); | ||
} | ||
|
||
@Override | ||
public boolean enabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> nativeCodeInfo() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void usage(ActionListener<Usage> listener) { | ||
final ClusterState state = clusterService.state(); | ||
boolean available = licenseState.isIndexLifecycleAllowed(); | ||
final SnapshotLifecycleMetadata slmMeta = state.metaData().custom(SnapshotLifecycleMetadata.TYPE); | ||
final SLMFeatureSetUsage usage = new SLMFeatureSetUsage(available, enabled, | ||
slmMeta == null ? null : slmMeta.getStats()); | ||
listener.onResponse(usage); | ||
} | ||
|
||
} |