-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Add four decimal places float validation for transaction_sample…
…_rate (#188555) Closes #183840 ## Summary This PR adds four decimal places float validation for `transaction_sample_rate` and keeps the three decimal places float validation for all other fields ![image](https://github.com/user-attachments/assets/359136b8-6a3a-4a51-ab51-085cd03a0371) ## Testing - Open APM -> Settings -> Agent Configuration and go to the next time where `transaction_sample_rate` and check the validation -> Up to 4 decimal places should be allowed: https://github.com/user-attachments/assets/0c596277-11b2-40d3-991e-d04f97a4ac5f
- Loading branch information
1 parent
6dade93
commit db5d8db
Showing
7 changed files
with
121 additions
and
48 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...olution/apm/common/agent_configuration/runtime_types/float_four_decimal_places_rt.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { floatFourDecimalPlacesRt } from './float_four_decimal_places_rt'; | ||
import { isRight } from 'fp-ts/lib/Either'; | ||
|
||
describe('floatFourDecimalPlacesRt', () => { | ||
it('does not accept empty values', () => { | ||
expect(isRight(floatFourDecimalPlacesRt.decode(undefined))).toBe(false); | ||
expect(isRight(floatFourDecimalPlacesRt.decode(null))).toBe(false); | ||
expect(isRight(floatFourDecimalPlacesRt.decode(''))).toBe(false); | ||
}); | ||
|
||
it('should only accept stringified numbers', () => { | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.5'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode(0.5))).toBe(false); | ||
}); | ||
|
||
it('checks if the number falls within 0, 1', () => { | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.5'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('-0.1'))).toBe(false); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('1.1'))).toBe(false); | ||
expect(isRight(floatFourDecimalPlacesRt.decode(NaN))).toBe(false); | ||
}); | ||
|
||
it('checks whether the number of decimals is 4', () => { | ||
expect(isRight(floatFourDecimalPlacesRt.decode('1'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.9'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.99'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.999'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.9999'))).toBe(true); | ||
expect(isRight(floatFourDecimalPlacesRt.decode('0.99999'))).toBe(false); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
...ity_solution/apm/common/agent_configuration/runtime_types/float_four_decimal_places_rt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
import { either } from 'fp-ts/lib/Either'; | ||
|
||
export const floatFourDecimalPlacesRt = new t.Type<string, string, unknown>( | ||
'floatFourDecimalPlacesRt', | ||
t.string.is, | ||
(input, context) => { | ||
return either.chain(t.string.validate(input, context), (inputAsString) => { | ||
const inputAsFloat = parseFloat(inputAsString); | ||
const maxFourDecimals = parseFloat(inputAsFloat.toFixed(4)) === inputAsFloat; | ||
|
||
const isValid = inputAsFloat >= 0 && inputAsFloat <= 1 && maxFourDecimals; | ||
|
||
return isValid | ||
? t.success(inputAsString) | ||
: t.failure(input, context, 'Must be a number between 0.0000 and 1'); | ||
}); | ||
}, | ||
t.identity | ||
); |
38 changes: 0 additions & 38 deletions
38
...gins/observability_solution/apm/common/agent_configuration/runtime_types/float_rt.test.ts
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
...lution/apm/common/agent_configuration/runtime_types/float_three_decimal_places_rt.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { floatThreeDecimalPlacesRt } from './float_three_decimal_places_rt'; | ||
import { isRight } from 'fp-ts/lib/Either'; | ||
|
||
describe('floatThreeDecimalPlacesRt', () => { | ||
it('does not accept empty values', () => { | ||
expect(isRight(floatThreeDecimalPlacesRt.decode(undefined))).toBe(false); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode(null))).toBe(false); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode(''))).toBe(false); | ||
}); | ||
|
||
it('should only accept stringified numbers', () => { | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.5'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode(0.5))).toBe(false); | ||
}); | ||
|
||
it('checks if the number falls within 0, 1', () => { | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.5'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('-0.1'))).toBe(false); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('1.1'))).toBe(false); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode(NaN))).toBe(false); | ||
}); | ||
|
||
it('checks whether the number of decimals is 3', () => { | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('1'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.9'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.99'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.999'))).toBe(true); | ||
expect(isRight(floatThreeDecimalPlacesRt.decode('0.9999'))).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...ution/apm/common/agent_configuration/setting_definitions/__snapshots__/index.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters