Skip to content

Commit a42b843

Browse files
authored
Add has_custom_cutoff_date to logsdb usage. (#117550) (#117610)
Indicates whether es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override system property has been configured. A follow up from #116647
1 parent 57de69e commit a42b843

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ static TransportVersion def(int id) {
204204
public static final TransportVersion FAST_REFRESH_RCO_2 = def(8_795_00_0);
205205
public static final TransportVersion ESQL_ENRICH_RUNTIME_WARNINGS = def(8_796_00_0);
206206
public static final TransportVersion INGEST_PIPELINE_CONFIGURATION_AS_MAP = def(8_797_00_0);
207+
public static final TransportVersion LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17 = def(8_797_00_1);
207208
public static final TransportVersion INDEXING_PRESSURE_THROTTLING_STATS = def(8_798_00_0);
208209
public static final TransportVersion REINDEX_DATA_STREAMS = def(8_799_00_0);
209210
public static final TransportVersion ESQL_REMOVE_NODE_LEVEL_PLAN = def(8_800_00_0);
211+
public static final TransportVersion LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE = def(8_801_00_0);
210212
/*
211213
* STOP! READ THIS FIRST! No, really,
212214
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/application/LogsDBFeatureSetUsage.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class LogsDBFeatureSetUsage extends XPackFeatureUsage {
2222
private final int indicesWithSyntheticSource;
2323
private final long numDocs;
2424
private final long sizeInBytes;
25+
private final boolean hasCustomCutoffDate;
2526

2627
public LogsDBFeatureSetUsage(StreamInput input) throws IOException {
2728
super(input);
@@ -34,6 +35,13 @@ public LogsDBFeatureSetUsage(StreamInput input) throws IOException {
3435
numDocs = 0;
3536
sizeInBytes = 0;
3637
}
38+
var transportVersion = input.getTransportVersion();
39+
if (transportVersion.isPatchFrom(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)
40+
|| transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE)) {
41+
hasCustomCutoffDate = input.readBoolean();
42+
} else {
43+
hasCustomCutoffDate = false;
44+
}
3745
}
3846

3947
@Override
@@ -45,6 +53,11 @@ public void writeTo(StreamOutput out) throws IOException {
4553
out.writeVLong(numDocs);
4654
out.writeVLong(sizeInBytes);
4755
}
56+
var transportVersion = out.getTransportVersion();
57+
if (transportVersion.isPatchFrom(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)
58+
|| transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE)) {
59+
out.writeBoolean(hasCustomCutoffDate);
60+
}
4861
}
4962

5063
public LogsDBFeatureSetUsage(
@@ -53,13 +66,15 @@ public LogsDBFeatureSetUsage(
5366
int indicesCount,
5467
int indicesWithSyntheticSource,
5568
long numDocs,
56-
long sizeInBytes
69+
long sizeInBytes,
70+
boolean hasCustomCutoffDate
5771
) {
5872
super(XPackField.LOGSDB, available, enabled);
5973
this.indicesCount = indicesCount;
6074
this.indicesWithSyntheticSource = indicesWithSyntheticSource;
6175
this.numDocs = numDocs;
6276
this.sizeInBytes = sizeInBytes;
77+
this.hasCustomCutoffDate = hasCustomCutoffDate;
6378
}
6479

6580
@Override
@@ -74,11 +89,12 @@ protected void innerXContent(XContentBuilder builder, Params params) throws IOEx
7489
builder.field("indices_with_synthetic_source", indicesWithSyntheticSource);
7590
builder.field("num_docs", numDocs);
7691
builder.field("size_in_bytes", sizeInBytes);
92+
builder.field("has_custom_cutoff_date", hasCustomCutoffDate);
7793
}
7894

7995
@Override
8096
public int hashCode() {
81-
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes);
97+
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes, hasCustomCutoffDate);
8298
}
8399

84100
@Override
@@ -95,6 +111,7 @@ public boolean equals(Object obj) {
95111
&& Objects.equals(indicesCount, other.indicesCount)
96112
&& Objects.equals(indicesWithSyntheticSource, other.indicesWithSyntheticSource)
97113
&& Objects.equals(numDocs, other.numDocs)
98-
&& Objects.equals(sizeInBytes, other.sizeInBytes);
114+
&& Objects.equals(sizeInBytes, other.sizeInBytes)
115+
&& Objects.equals(hasCustomCutoffDate, other.hasCustomCutoffDate);
99116
}
100117
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
apply plugin: 'elasticsearch.internal-java-rest-test'
9+
10+
dependencies {
11+
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
12+
}
13+
14+
tasks.named("javaRestTest").configure {
15+
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
16+
buildParams.withFipsEnabledOnly(it)
17+
18+
usesDefaultDistribution()
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.logsdb;
9+
10+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
11+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
12+
import org.elasticsearch.test.rest.ESRestTestCase;
13+
import org.hamcrest.Matchers;
14+
import org.junit.ClassRule;
15+
16+
import java.io.IOException;
17+
import java.util.Map;
18+
19+
public class LogsdbWithBasicRestIT extends ESRestTestCase {
20+
21+
@ClassRule
22+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
23+
.distribution(DistributionType.DEFAULT)
24+
.systemProperty("es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override", "2027-12-31T23:59")
25+
.setting("xpack.security.enabled", "false")
26+
.setting("cluster.logsdb.enabled", "true")
27+
.build();
28+
29+
@Override
30+
protected String getTestRestCluster() {
31+
return cluster.getHttpAddresses();
32+
}
33+
34+
public void testCustomCutoffDateUsage() throws IOException {
35+
var response = getAsMap("/_xpack/usage");
36+
Map<?, ?> usage = (Map<?, ?>) response.get("logsdb");
37+
assertThat(usage, Matchers.hasEntry("available", true));
38+
assertThat(usage, Matchers.hasEntry("enabled", true));
39+
assertThat(usage, Matchers.hasEntry("indices_count", 0));
40+
assertThat(usage, Matchers.hasEntry("indices_with_synthetic_source", 0));
41+
assertThat(usage, Matchers.hasEntry("num_docs", 0));
42+
assertThat(usage, Matchers.hasEntry("size_in_bytes", 0));
43+
assertThat(usage, Matchers.hasEntry("has_custom_cutoff_date", true));
44+
}
45+
}

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected void masterOperation(
7777
}
7878
}
7979
final boolean enabled = LogsDBPlugin.CLUSTER_LOGSDB_ENABLED.get(clusterService.getSettings());
80+
final boolean hasCustomCutoffDate = System.getProperty(SyntheticSourceLicenseService.CUTOFF_DATE_SYS_PROP_NAME) != null;
8081
if (featureService.clusterHasFeature(state, XPackFeatures.LOGSDB_TELMETRY_STATS)) {
8182
final DiscoveryNode[] nodes = state.nodes().getDataNodes().values().toArray(DiscoveryNode[]::new);
8283
final var statsRequest = new IndexModeStatsActionType.StatsRequest(nodes);
@@ -91,13 +92,16 @@ protected void masterOperation(
9192
finalNumIndices,
9293
finalNumIndicesWithSyntheticSources,
9394
indexStats.numDocs(),
94-
indexStats.numBytes()
95+
indexStats.numBytes(),
96+
hasCustomCutoffDate
9597
)
9698
);
9799
}));
98100
} else {
99101
listener.onResponse(
100-
new XPackUsageFeatureResponse(new LogsDBFeatureSetUsage(true, enabled, numIndices, numIndicesWithSyntheticSources, 0L, 0L))
102+
new XPackUsageFeatureResponse(
103+
new LogsDBFeatureSetUsage(true, enabled, numIndices, numIndicesWithSyntheticSources, 0L, 0L, hasCustomCutoffDate)
104+
)
101105
);
102106
}
103107
}

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/SyntheticSourceLicenseService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ final class SyntheticSourceLicenseService {
2727

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

@@ -129,7 +128,7 @@ private static long getCutoffDate(String cutoffDateAsString) {
129128
LOGGER.info(
130129
"Configuring [{}] to [{}]",
131130
CUTOFF_DATE_SYS_PROP_NAME,
132-
LocalDateTime.ofInstant(Instant.ofEpochSecond(cutoffDate), ZoneOffset.UTC)
131+
LocalDateTime.ofInstant(Instant.ofEpochMilli(cutoffDate), ZoneOffset.UTC)
133132
);
134133
return cutoffDate;
135134
} else {

0 commit comments

Comments
 (0)