Skip to content

Commit

Permalink
kie-kogito-serverless-operator-566: Make the operator configure the b…
Browse files Browse the repository at this point in the history
…inary and compress properties for the kogito events grouping in preview and gitops workflow deployments (apache#567)
  • Loading branch information
wmedvede authored and rgdoliveira committed Nov 6, 2024
1 parent d65aa96 commit ba37e18
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ data:
# If true, the workflow deployments will be configured to send accumulated workflow status change events to the Data
# Index Service reducing the number of produced events. Set to false to send individual events.
kogitoEventsGrouping: true
# If true, the accumulated workflow status change events will be sent in binary mode. (reduces the evens size)
kogitoEventsGroupingBinary: true
# If true, the accumulated workflow status change events, when sent in binary mode, will be gzipped at the cost of
# some performance.
kogitoEventsGroupingCompress: false
kind: ConfigMap
metadata:
name: sonataflow-operator-controllers-config
7 changes: 6 additions & 1 deletion config/manager/controllers_cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ postgreSQLPersistenceExtensions:
version: 999-20240912-SNAPSHOT
# If true, the workflow deployments will be configured to send accumulated workflow status change events to the Data
# Index Service reducing the number of produced events. Set to false to send individual events.
kogitoEventsGrouping: true
kogitoEventsGrouping: true
# If true, the accumulated workflow status change events will be sent in binary mode. (reduces the evens size)
kogitoEventsGroupingBinary: true
# If true, the accumulated workflow status change events, when sent in binary mode, will be gzipped at the cost of
# some performance.
kogitoEventsGroupingCompress: false
2 changes: 2 additions & 0 deletions internal/controller/cfg/controllers_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type ControllersCfg struct {
BuilderConfigMapName string `yaml:"builderConfigMapName,omitempty"`
PostgreSQLPersistenceExtensions []GAV `yaml:"postgreSQLPersistenceExtensions,omitempty"`
KogitoEventsGrouping bool `yaml:"kogitoEventsGrouping,omitempty"`
KogitoEventsGroupingBinary bool `yaml:"KogitoEventsGroupingBinary,omitempty"`
KogitoEventsGroupingCompress bool `yaml:"KogitoEventsGroupingCompress,omitempty"`
}

// InitializeControllersCfg initializes the platform configuration for this instance.
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/cfg/controllers_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func TestInitializeControllersCfgAt_ValidFile(t *testing.T) {
Version: "999-SNAPSHOT",
}, postgresExtensions[2])
assert.True(t, cfg.KogitoEventsGrouping)
assert.True(t, cfg.KogitoEventsGroupingBinary)
assert.False(t, cfg.KogitoEventsGroupingCompress)
}

func TestInitializeControllersCfgAt_FileNotFound(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/cfg/testdata/controllers-cfg-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ postgreSQLPersistenceExtensions:
- groupId: org.kie
artifactId: kie-addons-quarkus-persistence-jdbc
version: 999-SNAPSHOT
kogitoEventsGrouping: true
kogitoEventsGrouping: true
kogitoEventsGroupingBinary: true
kogitoEventsGroupingCompress: false
2 changes: 2 additions & 0 deletions internal/controller/profiles/common/constants/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ const (
QuarkusHttpCors = "quarkus.http.cors"
QuarkusHttpCorsOrigins = "quarkus.http.cors.origins"
KogitoEventsGrouping = "kogito.events.grouping"
KogitoEventsGroupingBinary = "kogito.events.grouping.binary"
KogitoEventsGroupingCompress = "kogito.events.grouping.compress"
)
6 changes: 6 additions & 0 deletions internal/controller/profiles/common/properties/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func NewManagedPropertyHandler(workflow *operatorapi.SonataFlow, platform *opera
func setControllersConfigProperties(workflow *operatorapi.SonataFlow, props *properties.Properties) {
if !profiles.IsDevProfile(workflow) && cfg.GetCfg().KogitoEventsGrouping {
props.Set(constants.KogitoEventsGrouping, "true")
if cfg.GetCfg().KogitoEventsGroupingBinary {
props.Set(constants.KogitoEventsGroupingBinary, "true")
if cfg.GetCfg().KogitoEventsGroupingCompress {
props.Set(constants.KogitoEventsGroupingCompress, "true")
}
}
}
}

Expand Down
70 changes: 61 additions & 9 deletions internal/controller/profiles/common/properties/managed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,46 +317,98 @@ func Test_appPropertyHandler_WithServicesWithUserOverrides(t *testing.T) {
assert.Equal(t, "", generatedProps.GetString(constants.JobServiceStatusChangeEventsURL, ""))
}

type eventsGroupingTestSpec struct {
kogitoEventsGrouping bool
kogitoEventsGroupingBinary bool
kogitoEventsGroupingCompress bool
shouldContainEventsGrouping bool
shouldContainEventsGroupingBinary bool
shouldContainEventsGroupingCompress bool
}

func newTestSpec(eventsGrouping bool, eventsGroupingBinary bool, eventsGroupingCompress bool,
shouldContainEventsGrouping bool, shouldContainEventsGroupingBinary bool, shouldContainEventsGroupingCompress bool) *eventsGroupingTestSpec {
return &eventsGroupingTestSpec{
kogitoEventsGrouping: eventsGrouping,
kogitoEventsGroupingBinary: eventsGroupingBinary,
kogitoEventsGroupingCompress: eventsGroupingCompress,
shouldContainEventsGrouping: shouldContainEventsGrouping,
shouldContainEventsGroupingBinary: shouldContainEventsGroupingBinary,
shouldContainEventsGroupingCompress: shouldContainEventsGroupingCompress,
}
}
func Test_appPropertyHandler_KogitoEventsGroupingTrueWithDevProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.DevProfile, true, false)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.DevProfile, newTestSpec(false, false, false, false, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueWithPreviewProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, true, true)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, newTestSpec(true, false, false, true, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueWithGitOpsProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, true, true)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, newTestSpec(true, false, false, true, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingFalseWithDevProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.DevProfile, false, false)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.DevProfile, newTestSpec(false, false, false, false, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingFalseWithPreviewProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, false, false)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, newTestSpec(false, false, false, false, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueBinaryTrueCompressFalseWithPreviewProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, newTestSpec(true, true, false, true, true, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueBinaryTrueCompressTrueWithPreviewProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.PreviewProfile, newTestSpec(true, true, true, true, true, true))
}

func Test_appPropertyHandler_KogitoEventsGroupingFalseWithGitOpsProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, false, false)
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, newTestSpec(false, false, false, false, false, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueBinaryTrueCompressFalseWithGitOpsProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, newTestSpec(true, true, false, true, true, false))
}

func Test_appPropertyHandler_KogitoEventsGroupingTrueBinaryTrueCompressTrueWithGitOpsProfile(t *testing.T) {
doTestManagedPropsForKogitoEventsGrouping(t, metadata.GitOpsProfile, newTestSpec(true, true, true, true, true, true))
}

func doTestManagedPropsForKogitoEventsGrouping(t *testing.T, profile metadata.ProfileType, kogitoEventsGrouping bool, shouldContain bool) {
func doTestManagedPropsForKogitoEventsGrouping(t *testing.T, profile metadata.ProfileType, testSpec *eventsGroupingTestSpec) {
currentKogitoEventGroupingValue := cfg.GetCfg().KogitoEventsGrouping
cfg.GetCfg().KogitoEventsGrouping = kogitoEventsGrouping
currentKogitoEventGroupingBinaryValue := cfg.GetCfg().KogitoEventsGroupingBinary
currentKogitoEventGroupingCompressValue := cfg.GetCfg().KogitoEventsGroupingCompress
cfg.GetCfg().KogitoEventsGrouping = testSpec.kogitoEventsGrouping
cfg.GetCfg().KogitoEventsGroupingBinary = testSpec.kogitoEventsGroupingBinary
cfg.GetCfg().KogitoEventsGroupingCompress = testSpec.kogitoEventsGroupingCompress
workflow := test.GetBaseSonataFlow("default")
setProfileInFlow(profile)(workflow)
platform := test.GetBasePlatform()
handler, err := NewManagedPropertyHandler(workflow, platform)
cfg.GetCfg().KogitoEventsGrouping = currentKogitoEventGroupingValue
cfg.GetCfg().KogitoEventsGroupingBinary = currentKogitoEventGroupingBinaryValue
cfg.GetCfg().KogitoEventsGroupingCompress = currentKogitoEventGroupingCompressValue
assert.NoError(t, err)
generatedProps, propsErr := properties.LoadString(handler.Build())
assert.NoError(t, propsErr)
if shouldContain {
if testSpec.shouldContainEventsGrouping {
assertHasProperty(t, generatedProps, "kogito.events.grouping", "true")
} else {
assert.NotContains(t, generatedProps.Keys(), "kogito.events.grouping")
}
if testSpec.shouldContainEventsGroupingBinary {
assertHasProperty(t, generatedProps, "kogito.events.grouping.binary", "true")
} else {
assert.NotContains(t, generatedProps.Keys(), "kogito.events.grouping.binary", "true")
}
if testSpec.shouldContainEventsGroupingCompress {
assertHasProperty(t, generatedProps, "kogito.events.grouping.compress", "true")
} else {
assert.NotContains(t, generatedProps.Keys(), "kogito.events.grouping.compress", "true")
}
}

var _ = Describe("Platform properties", func() {
Expand Down
5 changes: 5 additions & 0 deletions operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28155,6 +28155,11 @@ data:
# If true, the workflow deployments will be configured to send accumulated workflow status change events to the Data
# Index Service reducing the number of produced events. Set to false to send individual events.
kogitoEventsGrouping: true
# If true, the accumulated workflow status change events will be sent in binary mode. (reduces the evens size)
kogitoEventsGroupingBinary: true
# If true, the accumulated workflow status change events, when sent in binary mode, will be gzipped at the cost of
# some performance.
kogitoEventsGroupingCompress: false
kind: ConfigMap
metadata:
name: sonataflow-operator-controllers-config
Expand Down

0 comments on commit ba37e18

Please sign in to comment.