-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from solarwinds/NH-74055
Token bucket and dice + test runner fixes
- Loading branch information
Showing
28 changed files
with
964 additions
and
426 deletions.
There are no files selected for viewing
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
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,11 @@ | ||
releases: | ||
"@solarwinds-apm/compat": patch | ||
"@solarwinds-apm/proto": patch | ||
"@solarwinds-apm/sampling": major | ||
"@solarwinds-apm/test": minor | ||
solarwinds-apm: minor | ||
|
||
declined: | ||
- "@solarwinds-apm/bindings" | ||
- "@solarwinds-apm/dependencies" | ||
- "@solarwinds-apm/sdk" |
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
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
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
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,3 @@ | ||
# @solarwinds-apm/proto | ||
|
||
JavaScript bindings to [`@solarwimnds/apm-proto`](https://github.com/solarwinds/apm-proto). |
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 |
---|---|---|
|
@@ -42,5 +42,8 @@ | |
"eslint": "^8.50.0", | ||
"prettier": "^3.0.3", | ||
"protobufjs-cli": "^1.1.2" | ||
}, | ||
"engines": { | ||
"node": ">=16.13.0" | ||
} | ||
} |
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 @@ | ||
dist/ |
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,3 @@ | ||
# @solarwinds-apm/sampling | ||
|
||
Core SolarWinds sampling logic. Not meant for use outside `@solarwinds-apm` packages. |
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,19 @@ | ||
/* | ||
Copyright 2023-2024 SolarWinds Worldwide, LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import base from "@solarwinds-apm/eslint-config" | ||
|
||
export default [...base] |
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,51 @@ | ||
{ | ||
"name": "@solarwinds-apm/sampling", | ||
"version": "0.0.0", | ||
"license": "Apache-2.0", | ||
"contributors": [ | ||
"Raphaël Thériault <[email protected]>" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/solarwinds/apm-js.git", | ||
"directory": "packages/sampling" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/solarwinds/apm-js/issues" | ||
}, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./dist/es/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"main": "./dist/cjs/index.js", | ||
"files": [ | ||
"./src/", | ||
"./dist/" | ||
], | ||
"publishConfig": { | ||
"provenance": true | ||
}, | ||
"scripts": { | ||
"build": "rollup -c --forceExit", | ||
"lint": "prettier --check . && eslint . --max-warnings=0", | ||
"lint:fix": "eslint --fix . && prettier --write .", | ||
"publish": "node ../../scripts/publish.js", | ||
"test": "swtest -p test/tsconfig.json -c src" | ||
}, | ||
"devDependencies": { | ||
"@solarwinds-apm/eslint-config": "workspace:^", | ||
"@solarwinds-apm/rollup-config": "workspace:^", | ||
"@solarwinds-apm/test": "workspace:^", | ||
"@types/node": "^16.13.0", | ||
"eslint": "^8.50.0", | ||
"prettier": "^3.0.3", | ||
"rollup": "^4.3.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"engines": { | ||
"node": ">=16.13.0" | ||
} | ||
} |
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,19 @@ | ||
/* | ||
Copyright 2023-2024 SolarWinds Worldwide, LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import config from "@solarwinds-apm/rollup-config" | ||
|
||
export default config() |
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,48 @@ | ||
/* | ||
Copyright 2023-2024 SolarWinds Worldwide, LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
export interface DiceSettings { | ||
/** Scale of the dice */ | ||
scale: number | ||
/** Rate of rolls over the current scale that should be successful */ | ||
rate?: number | ||
} | ||
|
||
export class Dice { | ||
#scale: number | ||
|
||
#r = 0 | ||
get #rate(): number { | ||
return this.#r | ||
} | ||
set #rate(n: number) { | ||
this.#r = Math.max(0, Math.min(this.#scale, n)) | ||
} | ||
|
||
constructor(settings: DiceSettings) { | ||
this.#scale = settings.scale | ||
this.#rate = settings.rate ?? 0 | ||
} | ||
|
||
update(settings: Partial<DiceSettings>) { | ||
this.#scale = settings.scale ?? this.#scale | ||
this.#rate = settings.rate ?? this.#rate | ||
} | ||
|
||
roll(): boolean { | ||
return Math.random() * this.#scale < this.#rate | ||
} | ||
} |
Oops, something went wrong.