Skip to content

Commit 52318d4

Browse files
authored
[8.17] Add has_custom_cutoff_date to logsdb usage. (#117550) (#117614)
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 d86d06c commit 52318d4

File tree

6 files changed

+91
-9
lines changed

6 files changed

+91
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ 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-
207+
public static final TransportVersion LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17 = def(8_797_00_1);
208208
/*
209209
* STOP! READ THIS FIRST! No, really,
210210
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 18 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,12 @@ public LogsDBFeatureSetUsage(StreamInput input) throws IOException {
3435
numDocs = 0;
3536
sizeInBytes = 0;
3637
}
38+
var transportVersion = input.getTransportVersion();
39+
if (transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)) {
40+
hasCustomCutoffDate = input.readBoolean();
41+
} else {
42+
hasCustomCutoffDate = false;
43+
}
3744
}
3845

3946
@Override
@@ -45,6 +52,10 @@ public void writeTo(StreamOutput out) throws IOException {
4552
out.writeVLong(numDocs);
4653
out.writeVLong(sizeInBytes);
4754
}
55+
var transportVersion = out.getTransportVersion();
56+
if (transportVersion.onOrAfter(TransportVersions.LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17)) {
57+
out.writeBoolean(hasCustomCutoffDate);
58+
}
4859
}
4960

5061
public LogsDBFeatureSetUsage(
@@ -53,13 +64,15 @@ public LogsDBFeatureSetUsage(
5364
int indicesCount,
5465
int indicesWithSyntheticSource,
5566
long numDocs,
56-
long sizeInBytes
67+
long sizeInBytes,
68+
boolean hasCustomCutoffDate
5769
) {
5870
super(XPackField.LOGSDB, available, enabled);
5971
this.indicesCount = indicesCount;
6072
this.indicesWithSyntheticSource = indicesWithSyntheticSource;
6173
this.numDocs = numDocs;
6274
this.sizeInBytes = sizeInBytes;
75+
this.hasCustomCutoffDate = hasCustomCutoffDate;
6376
}
6477

6578
@Override
@@ -74,11 +87,12 @@ protected void innerXContent(XContentBuilder builder, Params params) throws IOEx
7487
builder.field("indices_with_synthetic_source", indicesWithSyntheticSource);
7588
builder.field("num_docs", numDocs);
7689
builder.field("size_in_bytes", sizeInBytes);
90+
builder.field("has_custom_cutoff_date", hasCustomCutoffDate);
7791
}
7892

7993
@Override
8094
public int hashCode() {
81-
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes);
95+
return Objects.hash(available, enabled, indicesCount, indicesWithSyntheticSource, numDocs, sizeInBytes, hasCustomCutoffDate);
8296
}
8397

8498
@Override
@@ -95,6 +109,7 @@ public boolean equals(Object obj) {
95109
&& Objects.equals(indicesCount, other.indicesCount)
96110
&& Objects.equals(indicesWithSyntheticSource, other.indicesWithSyntheticSource)
97111
&& Objects.equals(numDocs, other.numDocs)
98-
&& Objects.equals(sizeInBytes, other.sizeInBytes);
112+
&& Objects.equals(sizeInBytes, other.sizeInBytes)
113+
&& Objects.equals(hasCustomCutoffDate, other.hasCustomCutoffDate);
99114
}
100115
}
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)