Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setup() {
}

public void testGetAdditionalIndexSettings() throws Exception {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testGetAdditionalIndexSettings() throws Exception {
}

public void testGetAdditionalIndexSettingsIndexRoutingPathAlreadyDefined() throws Exception {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testGetAdditionalIndexSettingsIndexRoutingPathAlreadyDefined() throw
}

public void testGetAdditionalIndexSettingsMappingsMerging() throws Exception {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand Down Expand Up @@ -211,7 +211,7 @@ public void testGetAdditionalIndexSettingsMappingsMerging() throws Exception {
}

public void testGetAdditionalIndexSettingsNoMappings() {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand All @@ -235,7 +235,7 @@ public void testGetAdditionalIndexSettingsNoMappings() {
}

public void testGetAdditionalIndexSettingsLookAheadTime() throws Exception {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand All @@ -260,7 +260,7 @@ public void testGetAdditionalIndexSettingsLookAheadTime() throws Exception {
}

public void testGetAdditionalIndexSettingsLookBackTime() throws Exception {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Expand Down Expand Up @@ -290,10 +290,11 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreated() throws Exce

Instant sixHoursAgo = Instant.now().minus(6, ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS);
Instant currentEnd = sixHoursAgo.plusMillis(lookAheadTime.getMillis());
ProjectMetadata projectMetadata = DataStreamTestHelper.getClusterStateWithDataStream(
ProjectMetadata projectMetadata = DataStreamTestHelper.getProjectWithDataStream(
randomProjectIdOrDefault(),
dataStreamName,
List.of(new Tuple<>(sixHoursAgo, currentEnd))
).getMetadata().getProject();
);

Instant now = sixHoursAgo.plus(6, ChronoUnit.HOURS);
Settings settings = Settings.EMPTY;
Expand All @@ -317,18 +318,20 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreated() throws Exce
public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMissing() {
String dataStreamName = "logs-app1";
Instant twoHoursAgo = Instant.now().minus(4, ChronoUnit.HOURS).truncatedTo(ChronoUnit.MILLIS);
Metadata.Builder mb = Metadata.builder(
final var projectId = randomProjectIdOrDefault();
ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(
DataStreamTestHelper.getClusterStateWithDataStreams(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a DataStreamTestHelper.getProjectWithDataStreams that works here, like we had for the ...WithDataStream (singular) above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do not. I was struggling with this exact question, because I'm not a huge fan of this approach either. My reason for not adding a getProjectWithDataStreams method is that there are a bunch of different overloads of getClusterStateWithDataStreams already, and adding a project version for every one (not right now, but perhaps over time) feels like it's getting out of hand. I looked at some of the usages but I concluded that they all need a ClusterState because they need to convert it to a ProjectState.

However, I just realized I could maybe do some refactoring of those usages instead to make use of my ESTestCase#projectStateFromProject. Let me experiment with that.

projectId,
List.of(Tuple.tuple(dataStreamName, 1)),
List.of(),
twoHoursAgo.toEpochMilli(),
builder().build(),
1
).getMetadata()
).metadata().getProject(projectId)
);
DataStream ds = mb.dataStream(dataStreamName);
mb.put(ds.copy().setIndexMode(IndexMode.TIME_SERIES).build());
ProjectMetadata projectMetadata = mb.build().getProject();
DataStream ds = projectBuilder.dataStream(dataStreamName);
projectBuilder.put(ds.copy().setIndexMode(IndexMode.TIME_SERIES).build());
ProjectMetadata projectMetadata = projectBuilder.build();

Instant now = twoHoursAgo.plus(2, ChronoUnit.HOURS);
Settings settings = Settings.EMPTY;
Expand Down Expand Up @@ -356,7 +359,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMi
}

public void testGetAdditionalIndexSettingsNonTsdbTemplate() {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";

Settings settings = Settings.EMPTY;
Expand All @@ -377,10 +380,9 @@ public void testGetAdditionalIndexSettingsMigrateToTsdb() {
String dataStreamName = "logs-app1";
IndexMetadata idx = createFirstBackingIndex(dataStreamName).build();
DataStream existingDataStream = newInstance(dataStreamName, List.of(idx.getIndex()));
ProjectMetadata projectMetadata = Metadata.builder()
ProjectMetadata projectMetadata = ProjectMetadata.builder(randomProjectIdOrDefault())
.dataStreams(Map.of(dataStreamName, existingDataStream), Map.of())
.build()
.getProject();
.build();

Settings settings = Settings.EMPTY;
Settings result = provider.getAdditionalIndexSettings(
Expand All @@ -404,16 +406,18 @@ public void testGetAdditionalIndexSettingsMigrateToTsdb() {
public void testGetAdditionalIndexSettingsDowngradeFromTsdb() {
String dataStreamName = "logs-app1";
Instant twoHoursAgo = Instant.now().minus(4, ChronoUnit.HOURS).truncatedTo(ChronoUnit.MILLIS);
final var projectId = randomProjectIdOrDefault();
Metadata.Builder mb = Metadata.builder(
DataStreamTestHelper.getClusterStateWithDataStreams(
projectId,
List.of(Tuple.tuple(dataStreamName, 1)),
List.of(),
twoHoursAgo.toEpochMilli(),
builder().build(),
1
).getMetadata()
);
ProjectMetadata projectMetadata = mb.build().getProject();
ProjectMetadata projectMetadata = mb.build().getProject(projectId);

Settings settings = Settings.EMPTY;
Settings result = provider.getAdditionalIndexSettings(
Expand Down Expand Up @@ -691,7 +695,7 @@ public void testGenerateRoutingPathFromPassThroughObject() throws Exception {
}

private Settings generateTsdbSettings(String mapping, Instant now) throws IOException {
ProjectMetadata projectMetadata = Metadata.EMPTY_METADATA.getProject();
ProjectMetadata projectMetadata = emptyProject();
String dataStreamName = "logs-app1";
Settings settings = Settings.EMPTY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2845,4 +2845,11 @@ public static ProjectState projectStateFromProject(ProjectMetadata.Builder proje
public static ProjectState projectStateWithEmptyProject() {
return projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()));
}

/**
* Constructs an empty {@link ProjectMetadata} with a random ID.
*/
public static ProjectMetadata emptyProject() {
return ProjectMetadata.builder(randomProjectIdOrDefault()).build();
}
}
Loading