Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion deployment/helm/ditto/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: |
A digital twin is a virtual, cloud based, representation of his real world counterpart
(real world “Things”, e.g. devices like sensors, smart heating, connected cars, smart grids, EV charging stations etc).
type: application
version: 4.6.0 # chart version is effectively set by release-job
version: 4.6.1 # chart version is effectively set by release-job
appVersion: 3.9.6
keywords:
- iot-chart
Expand Down
22 changes: 22 additions & 0 deletions deployment/helm/ditto/service-config/search-extension.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ ditto {
}
{{- end }}
}

{{- with .Values.thingsSearch.config.operatorMetrics.customMetricsPersistence }}
{{- if .readPreference }}
custom-metrics-persistence {
readPreference = "{{ .readPreference }}"
{{- if .readConcern }}
readConcern = "{{ .readConcern }}"
{{- end }}
}
{{- end }}
{{- end }}

{{- with .Values.thingsSearch.config.operatorMetrics.customAggregationMetricsPersistence }}
{{- if .readPreference }}
custom-aggregation-metrics-persistence {
readPreference = "{{ .readPreference }}"
{{- if .readConcern }}
readConcern = "{{ .readConcern }}"
{{- end }}
}
{{- end }}
{{- end }}
}
}
}
13 changes: 13 additions & 0 deletions deployment/helm/ditto/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,19 @@ thingsSearch:
# # or as index key spec:
# # indexHint:
# # "t.attributes.location": 1
# customMetricsPersistence optionally overrides the MongoDB read preference / read concern used for the
# count based "customMetrics" queries above. When unset (the default), the general query.persistence
# settings are used - so this can offload the periodic operator metric counts to a secondary node without
# affecting user-facing search/count requests.
# customMetricsPersistence:
# readPreference: secondaryPreferred
# readConcern: default
# customAggregationMetricsPersistence optionally overrides the MongoDB read preference / read concern used
# for the "customAggregationMetrics" ($group) queries above. When unset (the default), the general
# query.persistence settings are used. Can be configured independently from customMetricsPersistence.
# customAggregationMetricsPersistence:
# readPreference: secondaryPreferred
# readConcern: default
# dispatchers contains tuning for the things-search service's Pekko dispatchers.
# Defaults below match the in-jar HOCON defaults and only need overriding under sustained load.
dispatchers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public com.mongodb.ReadConcern getMongoReadConcern() {
return mongoReadConcern;
}

/**
* Returns the config string value of this read concern (e.g. {@code "local"}).
*
* @return the read concern config string.
* @since 3.9.7
*/
public String getName() {
return name;
}

/**
* Tries to create a ReadConcern from the given read concern string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public com.mongodb.ReadPreference getMongoReadPreference() {
return mongoReadPreference;
}

/**
* Returns the config string value of this read preference (e.g. {@code "secondaryPreferred"}).
*
* @return the read preference config string.
* @since 3.9.7
*/
public String getName() {
return name;
}

/**
* Tries to create a ReadPreference from the given read preference string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public final class SudoCountThings extends AbstractCommand<SudoCountThings>
JsonFactory.newJsonValueFieldDefinition("indexHint", FieldType.REGULAR,
JsonSchemaVersion.V_2);

static final JsonFieldDefinition<String> JSON_READ_PREFERENCE =
JsonFactory.newStringFieldDefinition("readPreference", FieldType.REGULAR,
JsonSchemaVersion.V_2);

static final JsonFieldDefinition<String> JSON_READ_CONCERN =
JsonFactory.newStringFieldDefinition("readConcern", FieldType.REGULAR,
JsonSchemaVersion.V_2);

@Nullable
private final String filter;

Expand All @@ -82,8 +90,15 @@ public final class SudoCountThings extends AbstractCommand<SudoCountThings>
@Nullable
private final JsonValue indexHint;

@Nullable
private final String readPreference;

@Nullable
private final String readConcern;

private SudoCountThings(final DittoHeaders dittoHeaders, @Nullable final String filter,
@Nullable final Collection<String> namespaces, @Nullable final JsonValue indexHint) {
@Nullable final Collection<String> namespaces, @Nullable final JsonValue indexHint,
@Nullable final String readPreference, @Nullable final String readConcern) {
super(TYPE, dittoHeaders);
this.filter = filter;
if (namespaces != null) {
Expand All @@ -92,6 +107,8 @@ private SudoCountThings(final DittoHeaders dittoHeaders, @Nullable final String
this.namespaces = null;
}
this.indexHint = indexHint;
this.readPreference = readPreference;
this.readConcern = readConcern;
}

/**
Expand All @@ -103,7 +120,7 @@ private SudoCountThings(final DittoHeaders dittoHeaders, @Nullable final String
* @throws NullPointerException if {@code dittoHeaders} is {@code null}.
*/
public static SudoCountThings of(@Nullable final String filter, final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, null, null);
return new SudoCountThings(dittoHeaders, filter, null, null, null, null);
}

/**
Expand All @@ -117,7 +134,7 @@ public static SudoCountThings of(@Nullable final String filter, final DittoHeade
*/
public static SudoCountThings of(@Nullable final String filter, @Nullable final Collection<String> namespaces,
final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, namespaces, null);
return new SudoCountThings(dittoHeaders, filter, namespaces, null, null, null);
}

/**
Expand All @@ -132,7 +149,47 @@ public static SudoCountThings of(@Nullable final String filter, @Nullable final
*/
public static SudoCountThings of(@Nullable final String filter, @Nullable final Collection<String> namespaces,
@Nullable final JsonValue indexHint, final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint);
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint, null, null);
}

/**
* Returns a new instance of {@code SudoCountThings}.
*
* @param filter the optional filter string.
* @param namespaces the namespaces to perform the count in.
* @param indexHint the optional index hint for the MongoDB query.
* @param readPreference the optional MongoDB read preference to use for this count query (e.g.
* {@code "secondaryPreferred"}); when {@code null} the persistence default read preference is used.
* @param dittoHeaders the headers of the command.
* @return a new command for counting Things.
* @throws NullPointerException if {@code dittoHeaders} is {@code null}.
* @since 3.9.7
*/
public static SudoCountThings of(@Nullable final String filter, @Nullable final Collection<String> namespaces,
@Nullable final JsonValue indexHint, @Nullable final String readPreference,
final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint, readPreference, null);
}

/**
* Returns a new instance of {@code SudoCountThings}.
*
* @param filter the optional filter string.
* @param namespaces the namespaces to perform the count in.
* @param indexHint the optional index hint for the MongoDB query.
* @param readPreference the optional MongoDB read preference to use for this count query (e.g.
* {@code "secondaryPreferred"}); when {@code null} the persistence default read preference is used.
* @param readConcern the optional MongoDB read concern to use for this count query (e.g. {@code "local"});
* when {@code null} the persistence default read concern is used.
* @param dittoHeaders the headers of the command.
* @return a new command for counting Things.
* @throws NullPointerException if {@code dittoHeaders} is {@code null}.
* @since 3.9.7
*/
public static SudoCountThings of(@Nullable final String filter, @Nullable final Collection<String> namespaces,
@Nullable final JsonValue indexHint, @Nullable final String readPreference,
@Nullable final String readConcern, final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint, readPreference, readConcern);
}

/**
Expand All @@ -143,7 +200,7 @@ public static SudoCountThings of(@Nullable final String filter, @Nullable final
* @throws NullPointerException if any argument is {@code null}.
*/
public static SudoCountThings of(final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, null, null, null);
return new SudoCountThings(dittoHeaders, null, null, null, null, null);
}

/**
Expand Down Expand Up @@ -186,7 +243,12 @@ public static SudoCountThings fromJson(final JsonObject jsonObject, final DittoH

final JsonValue extractedIndexHint = jsonObject.getValue(JSON_INDEX_HINT).orElse(null);

return new SudoCountThings(dittoHeaders, extractedFilter, extractedNamespaces, extractedIndexHint);
final String extractedReadPreference = jsonObject.getValue(JSON_READ_PREFERENCE).orElse(null);

final String extractedReadConcern = jsonObject.getValue(JSON_READ_CONCERN).orElse(null);

return new SudoCountThings(dittoHeaders, extractedFilter, extractedNamespaces, extractedIndexHint,
extractedReadPreference, extractedReadConcern);
});
}

Expand Down Expand Up @@ -217,6 +279,26 @@ public Optional<JsonValue> getIndexHint() {
return Optional.ofNullable(indexHint);
}

/**
* Get the optional MongoDB read preference override for this count query.
*
* @return the optional read preference (e.g. {@code "secondaryPreferred"}).
* @since 3.9.7
*/
public Optional<String> getReadPreference() {
return Optional.ofNullable(readPreference);
}

/**
* Get the optional MongoDB read concern override for this count query.
*
* @return the optional read concern (e.g. {@code "local"}).
* @since 3.9.7
*/
public Optional<String> getReadConcern() {
return Optional.ofNullable(readConcern);
}

@Override
protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion,
final Predicate<JsonField> thePredicate) {
Expand All @@ -227,6 +309,8 @@ protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final Js
.map(JsonValue::of)
.collect(JsonCollectors.valuesToArray()), predicate));
getIndexHint().ifPresent(hint -> jsonObjectBuilder.set(JSON_INDEX_HINT, hint, predicate));
getReadPreference().ifPresent(rp -> jsonObjectBuilder.set(JSON_READ_PREFERENCE, rp, predicate));
getReadConcern().ifPresent(rc -> jsonObjectBuilder.set(JSON_READ_CONCERN, rc, predicate));
}

@Override
Expand All @@ -236,7 +320,7 @@ public Category getCategory() {

@Override
public SudoCountThings setDittoHeaders(final DittoHeaders dittoHeaders) {
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint);
return new SudoCountThings(dittoHeaders, filter, namespaces, indexHint, readPreference, readConcern);
}

@Override
Expand All @@ -250,12 +334,14 @@ public boolean equals(@Nullable final Object o) {
final SudoCountThings that = (SudoCountThings) o;
return Objects.equals(filter, that.filter) &&
Objects.equals(namespaces, that.namespaces) &&
Objects.equals(indexHint, that.indexHint);
Objects.equals(indexHint, that.indexHint) &&
Objects.equals(readPreference, that.readPreference) &&
Objects.equals(readConcern, that.readConcern);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), filter, namespaces, indexHint);
return Objects.hash(super.hashCode(), filter, namespaces, indexHint, readPreference, readConcern);
}

@Override
Expand All @@ -264,6 +350,8 @@ public String toString() {
"filter='" + filter + "'" +
", namespaces=" + namespaces +
", indexHint=" + indexHint +
", readPreference=" + readPreference +
", readConcern=" + readConcern +
"]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,42 @@ public void setDittoHeadersPreservesIndexHint() {
assertThat(withNewHeaders.getIndexHint()).contains(JsonValue.of("my_index"));
}

@Test
public void toJsonWithReadPreferenceAndReadConcern() {
final SudoCountThings command = SudoCountThings.of(
KNOWN_FILTER_STR, List.of("ns1"), JsonValue.of("my_index"), "secondaryPreferred", "local",
DittoHeaders.empty());

final String json = command.toJsonString();
final SudoCountThings deserialized = SudoCountThings.fromJson(json, DittoHeaders.empty());

assertThat(deserialized.getFilter()).contains(KNOWN_FILTER_STR);
assertThat(deserialized.getIndexHint()).contains(JsonValue.of("my_index"));
assertThat(deserialized.getReadPreference()).contains("secondaryPreferred");
assertThat(deserialized.getReadConcern()).contains("local");
}

@Test
public void toJsonWithoutReadPreferenceOrReadConcern() {
final SudoCountThings command = SudoCountThings.of(KNOWN_FILTER_STR, DittoHeaders.empty());

final String json = command.toJsonString();
final SudoCountThings deserialized = SudoCountThings.fromJson(json, DittoHeaders.empty());

assertThat(deserialized.getReadPreference()).isEmpty();
assertThat(deserialized.getReadConcern()).isEmpty();
}

@Test
public void setDittoHeadersPreservesReadPreferenceAndReadConcern() {
final SudoCountThings command = SudoCountThings.of(
KNOWN_FILTER_STR, null, null, "secondaryPreferred", "local", DittoHeaders.empty());

final SudoCountThings withNewHeaders = command.setDittoHeaders(
DittoHeaders.newBuilder().correlationId("test").build());

assertThat(withNewHeaders.getReadPreference()).contains("secondaryPreferred");
assertThat(withNewHeaders.getReadConcern()).contains("local");
}

}
Loading
Loading