Skip to content

Commit 0581d82

Browse files
committed
Test to reproduce
1 parent aa74711 commit 0581d82

File tree

1 file changed

+83
-1
lines changed
  • x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample

1 file changed

+83
-1
lines changed

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsampleIT.java

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
5151
"attributes": {
5252
"type": "passthrough",
5353
"priority": 10,
54-
"time_series_dimension": true
54+
"time_series_dimension": true,
55+
"properties": {
56+
"os.name": {
57+
"type": "keyword",
58+
"time_series_dimension": true
59+
}
60+
}
5561
},
5662
"metrics.cpu_usage": {
5763
"type": "double",
@@ -70,7 +76,83 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
7076
.startObject()
7177
.field("@timestamp", ts)
7278
.field("attributes.host.name", randomFrom("host1", "host2", "host3"))
79+
.field("attributes.os.name", randomFrom("linux", "windows", "macos"))
80+
.field("metrics.cpu_usage", randomDouble())
81+
.endObject();
82+
} catch (IOException e) {
83+
throw new RuntimeException(e);
84+
}
85+
};
86+
bulkIndex(dataStreamName, sourceSupplier, 100);
87+
// Rollover to ensure the index we will downsample is not the write index
88+
assertAcked(client().admin().indices().rolloverIndex(new RolloverRequest(dataStreamName, null)));
89+
List<String> backingIndices = waitForDataStreamBackingIndices(dataStreamName, 2);
90+
String sourceIndex = backingIndices.get(0);
91+
String interval = "5m";
92+
String targetIndex = "downsample-" + interval + "-" + sourceIndex;
93+
// Set the source index to read-only state
94+
assertAcked(
95+
indicesAdmin().prepareUpdateSettings(sourceIndex)
96+
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true).build())
97+
);
98+
99+
DownsampleConfig downsampleConfig = new DownsampleConfig(new DateHistogramInterval(interval));
100+
assertAcked(
101+
client().execute(
102+
DownsampleAction.INSTANCE,
103+
new DownsampleAction.Request(TEST_REQUEST_TIMEOUT, sourceIndex, targetIndex, TIMEOUT, downsampleConfig)
104+
)
105+
);
106+
107+
// Wait for downsampling to complete
108+
SubscribableListener<Void> listener = ClusterServiceUtils.addMasterTemporaryStateListener(clusterState -> {
109+
final var indexMetadata = clusterState.metadata().getProject().index(targetIndex);
110+
if (indexMetadata == null) {
111+
return false;
112+
}
113+
var downsampleStatus = IndexMetadata.INDEX_DOWNSAMPLE_STATUS.get(indexMetadata.getSettings());
114+
return downsampleStatus == IndexMetadata.DownsampleTaskStatus.SUCCESS;
115+
});
116+
safeAwait(listener);
117+
118+
assertDownsampleIndexFieldsAndDimensions(sourceIndex, targetIndex, downsampleConfig);
119+
}
120+
121+
public void testDownsamplingPassthroughMetrics() throws Exception {
122+
String dataStreamName = "metrics-foo";
123+
// Set up template
124+
putTSDBIndexTemplate("my-template", List.of("metrics-foo"), null, """
125+
{
126+
"properties": {
127+
"attributes.os.name": {
128+
"type": "keyword",
129+
"time_series_dimension": true
130+
},
131+
"metrics": {
132+
"type": "passthrough",
133+
"priority": 10,
134+
"properties": {
135+
"cpu_usage": {
136+
"type": "double",
137+
"time_series_metric": "counter"
138+
}
139+
}
140+
}
141+
}
142+
}
143+
""", null, null);
144+
145+
// Create data stream by indexing documents
146+
final Instant now = Instant.now();
147+
Supplier<XContentBuilder> sourceSupplier = () -> {
148+
String ts = randomDateForRange(now.minusSeconds(60 * 60).toEpochMilli(), now.plusSeconds(60 * 29).toEpochMilli());
149+
try {
150+
return XContentFactory.jsonBuilder()
151+
.startObject()
152+
.field("@timestamp", ts)
153+
.field("attributes.os.name", randomFrom("linux", "windows", "macos"))
73154
.field("metrics.cpu_usage", randomDouble())
155+
.field("metrics.memory_usage", randomDouble())
74156
.endObject();
75157
} catch (IOException e) {
76158
throw new RuntimeException(e);

0 commit comments

Comments
 (0)