Skip to content

Commit

Permalink
[8.17] Add has_custom_cutoff_date to logsdb usage. (elastic#117550)
Browse files Browse the repository at this point in the history
Indicates whether es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override system property has been configured.

A follow up from elastic#116647
  • Loading branch information
martijnvg committed Nov 27, 2024
1 parent 7207148 commit 2710e41
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static TransportVersion def(int id) {
public static final TransportVersion FAST_REFRESH_RCO_2 = def(8_795_00_0);
public static final TransportVersion ESQL_ENRICH_RUNTIME_WARNINGS = def(8_796_00_0);
public static final TransportVersion INGEST_PIPELINE_CONFIGURATION_AS_MAP = def(8_797_00_0);

public static final TransportVersion LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17 = def(8_797_00_1);
/*
* STOP! READ THIS FIRST! No, really,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class LogsDBFeatureSetUsage extends XPackFeatureUsage {
private final int indicesWithSyntheticSource;
private final long numDocs;
private final long sizeInBytes;
private final boolean hasCustomCutoffDate;

public LogsDBFeatureSetUsage(StreamInput input) throws IOException {
super(input);
Expand All @@ -34,6 +35,12 @@ public LogsDBFeatureSetUsage(StreamInput input) throws IOException {
numDocs = 0;
sizeInBytes = 0;
}
var transportVersion = input.getTransportVersion();
if (transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)) {
hasCustomCutoffDate = input.readBoolean();
} else {
hasCustomCutoffDate = false;
}
}

@Override
Expand All @@ -45,6 +52,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(numDocs);
out.writeVLong(sizeInBytes);
}
var transportVersion = out.getTransportVersion();
if (transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)) {
out.writeBoolean(hasCustomCutoffDate);
}
}

public LogsDBFeatureSetUsage(
Expand All @@ -53,13 +64,15 @@ public LogsDBFeatureSetUsage(
int indicesCount,
int indicesWithSyntheticSource,
long numDocs,
long sizeInBytes
long sizeInBytes,
boolean hasCustomCutoffDate
) {
super(XPackField.LOGSDB, available, enabled);
this.indicesCount = indicesCount;
this.indicesWithSyntheticSource = indicesWithSyntheticSource;
this.numDocs = numDocs;
this.sizeInBytes = sizeInBytes;
this.hasCustomCutoffDate = hasCustomCutoffDate;
}

@Override
Expand All @@ -74,11 +87,12 @@ protected void innerXContent(XContentBuilder builder, Params params) throws IOEx
builder.field("indices_with_synthetic_source", indicesWithSyntheticSource);
builder.field("num_docs", numDocs);
builder.field("size_in_bytes", sizeInBytes);
builder.field("has_custom_cutoff_date", hasCustomCutoffDate);
}

@Override
public int hashCode() {
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes);
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes, hasCustomCutoffDate);
}

@Override
Expand All @@ -95,6 +109,7 @@ public boolean equals(Object obj) {
&& Objects.equals(indicesCount, other.indicesCount)
&& Objects.equals(indicesWithSyntheticSource, other.indicesWithSyntheticSource)
&& Objects.equals(numDocs, other.numDocs)
&& Objects.equals(sizeInBytes, other.sizeInBytes);
&& Objects.equals(sizeInBytes, other.sizeInBytes)
&& Objects.equals(hasCustomCutoffDate, other.hasCustomCutoffDate);
}
}
19 changes: 19 additions & 0 deletions x-pack/plugin/logsdb/qa/with-custom-cutoff/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

apply plugin: 'elasticsearch.internal-java-rest-test'

dependencies {
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
}

tasks.named("javaRestTest").configure {
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
buildParams.withFipsEnabledOnly(it)

usesDefaultDistribution()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.logsdb;

import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.hamcrest.Matchers;
import org.junit.ClassRule;

import java.io.IOException;
import java.util.Map;

public class LogsdbWithBasicRestIT extends ESRestTestCase {

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.systemProperty("es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override", "2027-12-31T23:59")
.setting("xpack.security.enabled", "false")
.setting("cluster.logsdb.enabled", "true")
.build();

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

public void testCustomCutoffDateUsage() throws IOException {
var response = getAsMap("/_xpack/usage");
Map<?, ?> usage = (Map<?, ?>) response.get("logsdb");
assertThat(usage, Matchers.hasEntry("available", true));
assertThat(usage, Matchers.hasEntry("enabled", true));
assertThat(usage, Matchers.hasEntry("indices_count", 0));
assertThat(usage, Matchers.hasEntry("indices_with_synthetic_source", 0));
assertThat(usage, Matchers.hasEntry("num_docs", 0));
assertThat(usage, Matchers.hasEntry("size_in_bytes", 0));
assertThat(usage, Matchers.hasEntry("has_custom_cutoff_date", true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected void masterOperation(
}
}
final boolean enabled = LogsDBPlugin.CLUSTER_LOGSDB_ENABLED.get(clusterService.getSettings());
final boolean hasCustomCutoffDate = System.getProperty(SyntheticSourceLicenseService.CUTOFF_DATE_SYS_PROP_NAME) != null;
if (featureService.clusterHasFeature(state, XPackFeatures.LOGSDB_TELMETRY_STATS)) {
final DiscoveryNode[] nodes = state.nodes().getDataNodes().values().toArray(DiscoveryNode[]::new);
final var statsRequest = new IndexModeStatsActionType.StatsRequest(nodes);
Expand All @@ -91,13 +92,16 @@ protected void masterOperation(
finalNumIndices,
finalNumIndicesWithSyntheticSources,
indexStats.numDocs(),
indexStats.numBytes()
indexStats.numBytes(),
hasCustomCutoffDate
)
);
}));
} else {
listener.onResponse(
new XPackUsageFeatureResponse(new LogsDBFeatureSetUsage(true, enabled, numIndices, numIndicesWithSyntheticSources, 0L, 0L))
new XPackUsageFeatureResponse(
new LogsDBFeatureSetUsage(true, enabled, numIndices, numIndicesWithSyntheticSources, 0L, 0L, hasCustomCutoffDate)
)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ final class SyntheticSourceLicenseService {

static final String MAPPINGS_FEATURE_FAMILY = "mappings";
// You can only override this property if you received explicit approval from Elastic.
private static final String CUTOFF_DATE_SYS_PROP_NAME =
"es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override";
static final String CUTOFF_DATE_SYS_PROP_NAME = "es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override";
private static final Logger LOGGER = LogManager.getLogger(SyntheticSourceLicenseService.class);
static final long DEFAULT_CUTOFF_DATE = LocalDateTime.of(2024, 12, 12, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli();

Expand Down Expand Up @@ -129,7 +128,7 @@ private static long getCutoffDate(String cutoffDateAsString) {
LOGGER.info(
"Configuring [{}] to [{}]",
CUTOFF_DATE_SYS_PROP_NAME,
LocalDateTime.ofInstant(Instant.ofEpochSecond(cutoffDate), ZoneOffset.UTC)
LocalDateTime.ofInstant(Instant.ofEpochMilli(cutoffDate), ZoneOffset.UTC)
);
return cutoffDate;
} else {
Expand Down

0 comments on commit 2710e41

Please sign in to comment.