From efefbb4415078a4e59a2afa8b22cd76aa3f64a50 Mon Sep 17 00:00:00 2001 From: Cole Bailey Date: Sat, 30 Mar 2024 21:07:53 +0100 Subject: [PATCH 1/3] allow custom seed in fractional op Signed-off-by: Cole Bailey --- json/targeting.json | 34 ++++++++++++++++++++++++++++++ json/targeting.yaml | 17 +++++++++++++++ json/test/positive/custom-ops.json | 21 ++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/json/targeting.json b/json/targeting.json index 15d18f7..de14fee 100644 --- a/json/targeting.json +++ b/json/targeting.json @@ -506,6 +506,37 @@ "$ref": "#/$defs/fractionalWeightArg" } }, + "fractionalCustomSeedOp": { + "type": "array", + "minItems": 4, + "$comment": "there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case", + "items": [ + { + "description": "Bucketing value used in pseudorandom assignment; should be unique and stable for each subject of flag evaluation. Defaults to targetingKey.", + "$ref": "#/$defs/varRule" + }, + { + "description": "Seed used in pseudorandom assignment. Defaults to flagKey.", + "anyOf": [ + { + "$ref": "#/$defs/varRule" + }, + { + "type": "string" + } + ] + }, + { + "$ref": "#/$defs/fractionalWeightArg" + }, + { + "$ref": "#/$defs/fractionalWeightArg" + } + ], + "additionalItems": { + "$ref": "#/$defs/fractionalWeightArg" + } + }, "fractionalRule": { "type": "object", "additionalProperties": false, @@ -514,6 +545,9 @@ "title": "Fractional Operation", "description": "Deterministic, pseudorandom fractional distribution.", "oneOf": [ + { + "$ref": "#/$defs/fractionalCustomSeedOp" + }, { "$ref": "#/$defs/fractionalOp" }, diff --git a/json/targeting.yaml b/json/targeting.yaml index 8ff119c..07201f2 100644 --- a/json/targeting.yaml +++ b/json/targeting.yaml @@ -399,6 +399,22 @@ type: object minItems: 2 items: $ref: "#/$defs/fractionalWeightArg" + fractionalCustomSeedOp: + type: array + minItems: 4 + $comment: there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case + items: + - description: Bucketing value used in pseudorandom assignment; should be unique + and stable for each subject of flag evaluation. Defaults to targetingKey. + $ref: "#/$defs/varRule" + - description: Seed used in pseudorandom assignment. Defaults to flagKey. + anyOf: + - $ref: "#/$defs/varRule" + - type: string + - $ref: "#/$defs/fractionalWeightArg" + - $ref: "#/$defs/fractionalWeightArg" + additionalItems: + $ref: "#/$defs/fractionalWeightArg" fractionalRule: type: object additionalProperties: false @@ -407,6 +423,7 @@ type: object title: Fractional Operation description: Deterministic, pseudorandom fractional distribution. oneOf: + - $ref: "#/$defs/fractionalCustomSeedOp" - $ref: "#/$defs/fractionalOp" - $ref: "#/$defs/fractionalShorthandOp" reference: diff --git a/json/test/positive/custom-ops.json b/json/test/positive/custom-ops.json index 52c2b42..4777724 100644 --- a/json/test/positive/custom-ops.json +++ b/json/test/positive/custom-ops.json @@ -41,6 +41,27 @@ ] } }, + "custom-seed-fractional-flag": { + "state": "ENABLED", + "variants": { + "clubs": "clubs", + "diamonds": "diamonds", + "hearts": "hearts", + "spades": "spades", + "wild": "wild" + }, + "defaultVariant": "wild", + "targeting": { + "fractional": [ + { "var": "user.name" }, + "my-seed", + ["clubs", 25], + ["diamonds", 25], + ["hearts", 25], + ["spades", 25] + ] + } + }, "starts-ends-flag": { "state": "ENABLED", "variants": { From 7e074936585057e0960b2e5146fbf94103238fb6 Mon Sep 17 00:00:00 2001 From: Cole Bailey Date: Mon, 1 Apr 2024 22:39:27 +0200 Subject: [PATCH 2/3] update to single allow cat with custom seeds Signed-off-by: Cole Bailey --- json/targeting.json | 36 +----------------------------- json/targeting.yaml | 19 +--------------- json/test/positive/custom-ops.json | 26 ++++----------------- 3 files changed, 6 insertions(+), 75 deletions(-) diff --git a/json/targeting.json b/json/targeting.json index de14fee..9d392f7 100644 --- a/json/targeting.json +++ b/json/targeting.json @@ -486,7 +486,7 @@ "items": [ { "description": "Bucketing value used in pseudorandom assignment; should be unique and stable for each subject of flag evaluation. Defaults to a concatenation of the flagKey and targetingKey.", - "$ref": "#/$defs/varRule" + "$ref": "#/$defs/anyRule" }, { "$ref": "#/$defs/fractionalWeightArg" @@ -506,37 +506,6 @@ "$ref": "#/$defs/fractionalWeightArg" } }, - "fractionalCustomSeedOp": { - "type": "array", - "minItems": 4, - "$comment": "there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case", - "items": [ - { - "description": "Bucketing value used in pseudorandom assignment; should be unique and stable for each subject of flag evaluation. Defaults to targetingKey.", - "$ref": "#/$defs/varRule" - }, - { - "description": "Seed used in pseudorandom assignment. Defaults to flagKey.", - "anyOf": [ - { - "$ref": "#/$defs/varRule" - }, - { - "type": "string" - } - ] - }, - { - "$ref": "#/$defs/fractionalWeightArg" - }, - { - "$ref": "#/$defs/fractionalWeightArg" - } - ], - "additionalItems": { - "$ref": "#/$defs/fractionalWeightArg" - } - }, "fractionalRule": { "type": "object", "additionalProperties": false, @@ -545,9 +514,6 @@ "title": "Fractional Operation", "description": "Deterministic, pseudorandom fractional distribution.", "oneOf": [ - { - "$ref": "#/$defs/fractionalCustomSeedOp" - }, { "$ref": "#/$defs/fractionalOp" }, diff --git a/json/targeting.yaml b/json/targeting.yaml index 07201f2..571dd13 100644 --- a/json/targeting.yaml +++ b/json/targeting.yaml @@ -389,7 +389,7 @@ type: object - description: Bucketing value used in pseudorandom assignment; should be unique and stable for each subject of flag evaluation. Defaults to a concatenation of the flagKey and targetingKey. - $ref: "#/$defs/varRule" + $ref: "#/$defs/anyRule" - $ref: "#/$defs/fractionalWeightArg" - $ref: "#/$defs/fractionalWeightArg" additionalItems: @@ -399,22 +399,6 @@ type: object minItems: 2 items: $ref: "#/$defs/fractionalWeightArg" - fractionalCustomSeedOp: - type: array - minItems: 4 - $comment: there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case - items: - - description: Bucketing value used in pseudorandom assignment; should be unique - and stable for each subject of flag evaluation. Defaults to targetingKey. - $ref: "#/$defs/varRule" - - description: Seed used in pseudorandom assignment. Defaults to flagKey. - anyOf: - - $ref: "#/$defs/varRule" - - type: string - - $ref: "#/$defs/fractionalWeightArg" - - $ref: "#/$defs/fractionalWeightArg" - additionalItems: - $ref: "#/$defs/fractionalWeightArg" fractionalRule: type: object additionalProperties: false @@ -423,7 +407,6 @@ type: object title: Fractional Operation description: Deterministic, pseudorandom fractional distribution. oneOf: - - $ref: "#/$defs/fractionalCustomSeedOp" - $ref: "#/$defs/fractionalOp" - $ref: "#/$defs/fractionalShorthandOp" reference: diff --git a/json/test/positive/custom-ops.json b/json/test/positive/custom-ops.json index 4777724..eae7ad8 100644 --- a/json/test/positive/custom-ops.json +++ b/json/test/positive/custom-ops.json @@ -14,7 +14,10 @@ "defaultVariant": "wild", "targeting": { "fractional": [ - { "var": "user.name" }, + { "cat": [ + { "var": "$flagd.flagKey" }, + { "var": "user.name" } + ]}, ["clubs", 25], ["diamonds", 25], ["hearts", 25], @@ -41,27 +44,6 @@ ] } }, - "custom-seed-fractional-flag": { - "state": "ENABLED", - "variants": { - "clubs": "clubs", - "diamonds": "diamonds", - "hearts": "hearts", - "spades": "spades", - "wild": "wild" - }, - "defaultVariant": "wild", - "targeting": { - "fractional": [ - { "var": "user.name" }, - "my-seed", - ["clubs", 25], - ["diamonds", 25], - ["hearts", 25], - ["spades", 25] - ] - } - }, "starts-ends-flag": { "state": "ENABLED", "variants": { From f4a0fd306a1bcd741e59489c01d9381238114f0c Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Mon, 8 Apr 2024 10:35:12 -0700 Subject: [PATCH 3/3] update go version in CI Signed-off-by: Kavindu Dodanduwa --- .github/workflows/pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 8fdaec8..597ac01 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -7,7 +7,7 @@ permissions: contents: read env: - GO_VERSION: 1.20.7 + GO_VERSION: 1.22 jobs: lint-protos: