Skip to content

Commit 1539adf

Browse files
authored
Merge branch 'main' into fix/classic-validator-early-returns-on-different-scopes
2 parents 894fbe0 + ded1255 commit 1539adf

File tree

15 files changed

+140
-17
lines changed

15 files changed

+140
-17
lines changed

cmd/monaco/integrationtest/utils/monaco/cmd.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func Run(t *testing.T, fs afero.Fs, command string) error {
4747
if !strings.HasPrefix(c, prefix) {
4848
return fmt.Errorf("command must start with '%s'", prefix)
4949
}
50-
t.Logf("Running command: %s", command)
5150
c = strings.TrimPrefix(c, prefix)
5251

5352
args := strings.Split(c, " ")
@@ -58,5 +57,10 @@ func Run(t *testing.T, fs afero.Fs, command string) error {
5857
// explicit cancel for each monaco run invocation
5958
ctx, cancel := context.WithCancel(t.Context())
6059
defer cancel()
61-
return runner.RunCmd(ctx, cmd)
60+
61+
t.Logf("Running command: %s", command)
62+
err := runner.RunCmd(ctx, cmd)
63+
t.Logf("Finished command: %s", command)
64+
65+
return err
6266
}

cmd/monaco/integrationtest/v2/integration_test_utils.go

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func runIntegration(t *testing.T, opts testOptions, testFunc TestFunc) {
137137

138138
if !opts.skipCleanup {
139139
defer func() {
140+
t.Log("Starting cleanup")
140141
integrationtest.CleanupIntegrationTest(t, opts.fs, opts.manifestPath, opts.specificEnvironment, suffix)
141142
}()
142143
}

cmd/monaco/integrationtest/v2/settings_integration_test.go

+43-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func TestOrdered_InsertAtFrontAndBackWorks(t *testing.T) {
398398
const manifestFile = configFolder + "/manifest.yaml"
399399

400400
const specificEnvironment = "platform"
401-
const project = "both-back-and-front-are-set"
401+
const project = "both-back-and-front-are-set-with-initial"
402402
const schema = "builtin:url-based-sampling"
403403

404404
RunIntegrationWithCleanup(t, configFolder, manifestFile, specificEnvironment, "InsertAtBackWorks", func(fs afero.Fs, tc TestContext) {
@@ -417,6 +417,48 @@ func TestOrdered_InsertAtFrontAndBackWorks(t *testing.T) {
417417
Filter: filterObjectsForScope(pgiMeId),
418418
})
419419

420+
assert.Equal(t, 3, len(list), "Exactly three configs should be deployed")
421+
422+
// Verify that last is actually the first object
423+
first := settingsExternalIdForTest(t, coordinate.Coordinate{Project: project, Type: schema, ConfigId: "first"}, tc)
424+
assert.Equal(t, 0, findPositionWithExternalId(t, list, first))
425+
426+
// Verify that last is actually the last object
427+
last := settingsExternalIdForTest(t, coordinate.Coordinate{Project: project, Type: schema, ConfigId: "last"}, tc)
428+
assert.Equal(t, len(list)-1, findPositionWithExternalId(t, list, last))
429+
})
430+
}
431+
432+
func TestOrdered_InsertAtFrontAndBackWorksDeployTwice(t *testing.T) {
433+
const configFolder = "test-resources/settings-ordered/insert-position"
434+
435+
const manifestFile = configFolder + "/manifest.yaml"
436+
437+
const specificEnvironment = "platform"
438+
const project = "both-back-and-front-are-set-deploy-twice"
439+
const schema = "builtin:url-based-sampling"
440+
441+
RunIntegrationWithCleanup(t, configFolder, manifestFile, specificEnvironment, "InsertAtBackWorks", func(fs afero.Fs, tc TestContext) {
442+
pgiMeId := randomMeID("PROCESS_GROUP_INSTANCE")
443+
setTestEnvVar(t, "MONACO_TARGET_ENTITY_SCOPE", pgiMeId, tc.suffix)
444+
t.Log("Monitored entity ID for testing ('MONACO_TARGET_ENTITY_SCOPE') =", pgiMeId)
445+
446+
// first
447+
err := monaco.Run(t, fs, fmt.Sprintf("monaco deploy %s --project %s --verbose", manifestFile, project))
448+
require.NoError(t, err)
449+
// second
450+
err = monaco.Run(t, fs, fmt.Sprintf("monaco deploy %s --project %s --verbose", manifestFile, project))
451+
require.NoError(t, err)
452+
453+
integrationtest.AssertAllConfigsAvailability(t, fs, manifestFile, []string{project}, specificEnvironment, true)
454+
455+
sClient := createSettingsClientFromManifest(t, fs, manifestFile, "platform")
456+
457+
list, err := sClient.List(t.Context(), schema, dtclient.ListSettingsOptions{
458+
DiscardValue: true,
459+
Filter: filterObjectsForScope(pgiMeId),
460+
})
461+
420462
assert.Equal(t, 2, len(list), "Exactly two configs should be deployed")
421463

422464
// Verify that last is actually the first object

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/both-back-and-front-are-set/config.yaml cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/both-back-and-front-are-set-deploy-twice/config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Test if setting `insertAfter` to `BACK` works as expected.
1+
# Test if setting `insertAfter` to `BACK` works as expected when deploying the configs twice
22
#
33
# First config, `first`, is deployed and will be added to the front
44
# Second config, `last`, will be added to the back.
@@ -15,6 +15,7 @@ configs:
1515
insertAfter: FRONT
1616
config:
1717
template: url-sampling.json
18+
name: first
1819

1920
- id: last
2021
type:
@@ -26,3 +27,4 @@ configs:
2627
insertAfter: BACK
2728
config:
2829
template: url-sampling.json
30+
name: last
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{
2-
"enabled": true,
3-
"ignore": false,
4-
"factor": "6",
5-
"path": "test",
6-
"pathComparisonType": "EQUALS",
7-
"queryParameters": [],
8-
"httpMethodAny": true
9-
}
1+
{
2+
"enabled": true,
3+
"ignore": false,
4+
"factor": "6",
5+
"path": "{{ .name }}",
6+
"pathComparisonType": "EQUALS",
7+
"queryParameters": [],
8+
"httpMethodAny": true
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Test if setting `insertAfter` to `BACK` works as expected with an initial config as 'separator'.
2+
# Without the separator, the configs are deployed in parallel and might run into a race condition on the remote server leading to an unpredictable ordering.
3+
#
4+
# First, `initial` is deployed. Then `first` and `last` are deployed in parallel.
5+
# `first` should be on the first position, `last` on the last position.
6+
7+
configs:
8+
- id: initial
9+
type:
10+
settings:
11+
schema: builtin:url-based-sampling
12+
scope:
13+
type: environment
14+
name: MONACO_TARGET_ENTITY_SCOPE
15+
insertAfter: FRONT
16+
config:
17+
template: url-sampling.json
18+
name: initial
19+
20+
- id: first
21+
type:
22+
settings:
23+
schema: builtin:url-based-sampling
24+
scope:
25+
type: environment
26+
name: MONACO_TARGET_ENTITY_SCOPE
27+
insertAfter: FRONT
28+
config:
29+
template: url-sampling.json
30+
name: first
31+
parameters:
32+
_phantom:
33+
type: reference
34+
property: id
35+
configId: initial
36+
37+
- id: last
38+
type:
39+
settings:
40+
schema: builtin:url-based-sampling
41+
scope:
42+
type: environment
43+
name: MONACO_TARGET_ENTITY_SCOPE
44+
insertAfter: BACK
45+
config:
46+
template: url-sampling.json
47+
name: last
48+
parameters:
49+
_phantom:
50+
type: reference
51+
property: id
52+
configId: initial
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"enabled": true,
3+
"ignore": false,
4+
"factor": "6",
5+
"path": "{{ .name }}",
6+
"pathComparisonType": "EQUALS",
7+
"queryParameters": [],
8+
"httpMethodAny": true
9+
}

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-not-set/config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ configs:
1414
name: MONACO_TARGET_ENTITY_SCOPE
1515
config:
1616
template: url-sampling.json
17+
name: first
1718

1819
- id: second
1920
type:
@@ -25,6 +26,7 @@ configs:
2526

2627
config:
2728
template: url-sampling.json
29+
name: second
2830
parameters:
2931
phantom:
3032
type: reference

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-not-set/url-sampling.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"enabled": true,
33
"ignore": false,
44
"factor": "6",
5-
"path": "test",
5+
"path": "{{ .name }}",
66
"pathComparisonType": "EQUALS",
77
"queryParameters": [],
88
"httpMethodAny": true

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-set-to-back/config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ configs:
77
- id: first
88
config:
99
template: url-sampling.json
10+
name: first
1011
type:
1112
settings:
1213
schema: builtin:url-based-sampling
@@ -16,6 +17,7 @@ configs:
1617
- id: second
1718
config:
1819
template: url-sampling.json
20+
name: second
1921
parameters:
2022
phantom:
2123
type: reference

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-set-to-back/url-sampling.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"enabled": true,
33
"ignore": false,
44
"factor": "6",
5-
"path": "test",
5+
"path": "{{ .name }}",
66
"pathComparisonType": "EQUALS",
77
"queryParameters": [],
88
"httpMethodAny": true

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-set-to-front/config.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ configs:
1313
name: MONACO_TARGET_ENTITY_SCOPE
1414
config:
1515
template: url-sampling.json
16+
name: first
1617

1718
- id: second
1819
type:
@@ -24,6 +25,7 @@ configs:
2425
insertAfter: FRONT
2526
config:
2627
template: url-sampling.json
28+
name: second
2729
parameters:
2830
phantom-to-first:
2931
type: reference
@@ -43,5 +45,6 @@ configs:
4345
property: id
4446
config:
4547
template: url-sampling.json
48+
name: third
4649

4750

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/insert-after-set-to-front/url-sampling.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"enabled": true,
33
"ignore": false,
44
"factor": "6",
5-
"path": "test",
5+
"path": "{{ .name }}",
66
"pathComparisonType": "EQUALS",
77
"queryParameters": [],
88
"httpMethodAny": true

cmd/monaco/integrationtest/v2/test-resources/settings-ordered/insert-position/manifest.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
manifestVersion: 1.0
22

33
projects:
4-
- name: both-back-and-front-are-set
4+
- name: both-back-and-front-are-set-with-initial
5+
- name: both-back-and-front-are-set-deploy-twice
56
- name: insert-after-not-set
67
- name: insert-after-set-to-back
78
- name: insert-after-set-to-front

pkg/client/dtclient/settings_client.go

+5
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ func (d *SettingsClient) Upsert(ctx context.Context, obj SettingsObject, upsertO
627627
}
628628

629629
log.WithCtxFields(ctx).Debug("Created/Updated object %s (%s) with externalId %s", obj.Coordinate.ConfigId, obj.SchemaId, externalID)
630+
insertAfterForLogging := "<nil>"
631+
if upsertOptions.InsertAfter != nil {
632+
insertAfterForLogging = *upsertOptions.InsertAfter
633+
}
634+
log.WithCtxFields(ctx).Debug("Created/Updated object %s (schemaID: %s, Scope: %s, insertAfter: %s) with externalId %s", obj.Coordinate.ConfigId, obj.SchemaId, obj.Scope, insertAfterForLogging, externalID)
630635
return entity, nil
631636
}
632637

0 commit comments

Comments
 (0)