Skip to content

Commit

Permalink
feat(slo): timeslice target value between 0 and 100% included (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Apr 17, 2024
1 parent 7871110 commit 873d48c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1740,11 +1740,17 @@
"target": {
"description": "the target objective between 0 and 1 excluded",
"type": "number",
"minimum": 0,
"maximum": 100,
"exclusiveMinimum": true,
"exclusiveMaximum": true,
"example": 0.99
},
"timesliceTarget": {
"description": "the target objective for each slice when using a timeslices budgeting method",
"type": "number",
"minimum": 0,
"maximum": 100,
"example": 0.995
},
"timesliceWindow": {
Expand Down Expand Up @@ -2472,4 +2478,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,16 @@ components:
target:
description: the target objective between 0 and 1 excluded
type: number
minimum: 0
maximum: 100
exclusiveMinimum: true
exclusiveMaximum: true
example: 0.99
timesliceTarget:
description: the target objective for each slice when using a timeslices budgeting method
type: number
minimum: 0
maximum: 100
example: 0.995
timesliceWindow:
description: the duration of each slice when using a timeslices budgeting method, as {duraton}{unit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ properties:
target:
description: the target objective between 0 and 1 excluded
type: number
minimum: 0
maximum: 100
exclusiveMinimum: true
exclusiveMaximum: true
example: 0.99
timesliceTarget:
description: the target objective for each slice when using a timeslices budgeting method
type: number
minimum: 0
maximum: 100
example: 0.995
timesliceWindow:
description: the duration of each slice when using a timeslices budgeting method, as {duraton}{unit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function SloEditFormObjectiveSectionTimeslices() {
defaultValue={95}
rules={{
required: true,
min: 0.001,
max: 99.999,
min: 0,
max: 100,
}}
render={({ field: { ref, onChange, ...field }, fieldState }) => (
<EuiFieldNumber
Expand All @@ -52,8 +52,8 @@ export function SloEditFormObjectiveSectionTimeslices() {
isInvalid={fieldState.invalid}
value={field.value}
data-test-subj="sloFormObjectiveTimesliceTargetInput"
min={0.001}
max={99.999}
min={0}
max={100}
step={0.001}
onChange={(event) => onChange(event.target.value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ describe('validateSLO', () => {
expect(() => validateSLO(slo)).toThrowError('Invalid objective.timeslice_target');
});

it("throws when 'objective.timeslice_target' is lte 0", () => {
it("throws when 'objective.timeslice_target' is lt 0", () => {
const slo = createSLO({
budgetingMethod: 'timeslices',
objective: {
target: 0.95,
timesliceTarget: 0,
timesliceTarget: -0.00001,
timesliceWindow: new Duration(1, DurationUnit.Minute),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function validateSLO(slo: SLODefinition) {
throw new IllegalArgumentError('Invalid id');
}

if (!isValidTargetNumber(slo.objective.target)) {
if (!isValidObjectiveTarget(slo.objective.target)) {
throw new IllegalArgumentError('Invalid objective.target');
}

Expand All @@ -48,7 +48,7 @@ export function validateSLO(slo: SLODefinition) {
if (timeslicesBudgetingMethodSchema.is(slo.budgetingMethod)) {
if (
slo.objective.timesliceTarget === undefined ||
!isValidTargetNumber(slo.objective.timesliceTarget)
!isValidTimesliceTarget(slo.objective.timesliceTarget)
) {
throw new IllegalArgumentError('Invalid objective.timeslice_target');
}
Expand Down Expand Up @@ -80,10 +80,14 @@ function isValidId(id: string): boolean {
return MIN_ID_LENGTH <= id.length && id.length <= MAX_ID_LENGTH;
}

function isValidTargetNumber(value: number): boolean {
function isValidObjectiveTarget(value: number): boolean {
return value > 0 && value < 1;
}

function isValidTimesliceTarget(value: number): boolean {
return value >= 0 && value <= 1;
}

function isValidRollingTimeWindowDuration(duration: Duration): boolean {
// 7, 30 or 90days accepted
return duration.unit === DurationUnit.Day && [7, 30, 90].includes(duration.value);
Expand Down

0 comments on commit 873d48c

Please sign in to comment.