Skip to content

Commit

Permalink
#2072: enhance Helm configuration with pre-defined extraFields
Browse files Browse the repository at this point in the history
  • Loading branch information
thjaeckle committed Jan 20, 2025
1 parent 86081de commit 216a776
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
40 changes: 40 additions & 0 deletions deployment/helm/ditto/service-config/things-extension.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,46 @@ ditto {
"{{$header}}"
{{- end }}
]
pre-defined-extra-fields = [
{{- range $index, $extraFieldConfig := .Values.things.config.event.preDefinedExtraFields }}
{
namespaces = [
{{- range $index, $namespace := $extraFieldConfig.namespaces }}
"{{$namespace}}"
{{- end }}
]
{{- if $extraFieldConfig.condition }}
condition = "{{$extraFieldConfig.condition}}"
{{- end }}
extra-fields = [
{{- range $index, $extraField := $extraFieldConfig.extraFields }}
"{{$extraField}}"
{{- end }}
]
}
{{- end }}
]
}
message {
pre-defined-extra-fields = [
{{- range $index, $extraFieldConfig := .Values.things.config.message.preDefinedExtraFields }}
{
namespaces = [
{{- range $index, $namespace := $extraFieldConfig.namespaces }}
"{{$namespace}}"
{{- end }}
]
{{- if $extraFieldConfig.condition }}
condition = "{{$extraFieldConfig.condition}}"
{{- end }}
extra-fields = [
{{- range $index, $extraField := $extraFieldConfig.extraFields }}
"{{$extraField}}"
{{- end }}
]
}
{{- end }}
]
}
}

Expand Down
21 changes: 21 additions & 0 deletions deployment/helm/ditto/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,27 @@ things:
interval: 15m
# the threshold after how many changes to a Thing to do a snapshot
threshold: 50
# event contains configuration related to e.g. publishing of thing events
event:
# preDefinedExtraFields contains pre-defined (configured) extraFields to send along all thing (change) events
preDefinedExtraFields: []
# - namespaces:
# - "org.eclipse.ditto*"
# condition: "eq(attributes/foo,'RQL condition')"
# extraFields:
# - "definition"
# - "attributes/serial"
# message contains configuration related to distributing thing messages
message:
# preDefinedExtraFields contains pre-defined (configured) extraFields to send along all thing messages
preDefinedExtraFields: []
# - namespaces:
# - "namespace1"
# - "namespace2"
# condition: "eq(attributes/foo,'RQL condition')"
# extra-fields:
# - "definition"
# - "attributes/serial"
# entityCreation by default, Ditto allows anyone to create a new entity (thing in this case) in any namespace.
# However, this behavior can be customized, and the ability to create new entities can be restricted:
entityCreation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public interface ThingMessageConfig {

/**
* Contains pre-defined (configured) {@code extraFields} to send along all thing (change) messages.
* Contains pre-defined (configured) {@code extraFields} to send along all thing messages.
*
* @return the pre-defined {@code extraFields} to send along.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ public <T extends DittoHeadersSettable<? extends T>> CompletionStage<T> enrichWi
if (null != thing && !preDefinedExtraFieldsConfigs.isEmpty()) {
final List<PreDefinedExtraFieldsConfig> matchingPreDefinedFieldsConfigs =
preDefinedExtraFieldsConfigs.stream()
.filter(conf -> conf
.getNamespace().stream()
.anyMatch(pattern -> pattern.matcher(thingId.getNamespace()).matches())
.filter(conf -> conf.getNamespace().isEmpty() ||
conf.getNamespace()
.stream()
.anyMatch(pattern ->
pattern.matcher(thingId.getNamespace()).matches()
)
)
.filter(applyPredefinedExtraFieldsCondition(thing, withDittoHeaders))
.toList();
Expand Down

0 comments on commit 216a776

Please sign in to comment.