Skip to content

Commit

Permalink
Merge pull request #278 from solarwinds/NH-74055
Browse files Browse the repository at this point in the history
Token bucket and dice + test runner fixes
  • Loading branch information
raphael-theriault-swi authored Mar 8, 2024
2 parents 80129a7 + 438f7f0 commit 1ffd799
Show file tree
Hide file tree
Showing 28 changed files with 964 additions and 426 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ jobs:
- run: yarn build
- run: yarn lint
- run: yarn test
env:
TEST_SERVICE_KEY: ${{ secrets.TEST_SERVICE_KEY }}
TEST_COLLECTOR: ${{ secrets.TEST_COLLECTOR }}

# load bearing .root file
# actions/upload-artifact will make the archive root the topmost directory which contains all specified files
Expand Down Expand Up @@ -190,9 +187,6 @@ jobs:
- run: yarn install --immutable
- run: yarn test --only
env:
TEST_SERVICE_KEY: ${{ secrets.TEST_SERVICE_KEY }}
TEST_COLLECTOR: ${{ secrets.TEST_COLLECTOR }}

terminate-arm64:
if: always() && github.event_name == 'pull_request'
Expand Down
11 changes: 11 additions & 0 deletions .yarn/versions/e4447a5e.yml
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"
41 changes: 0 additions & 41 deletions packages/bindings/test/oboe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,6 @@ import { describe, expect, it } from "@solarwinds-apm/test"

import { oboe } from ".."

const INIT_TIMEOUT = 10_000

describe("Reporter", () => {
it("should initialise with service key and collector", () => {
const reporter = new oboe.Reporter({
service_key: process.env.TEST_SERVICE_KEY!,
host: process.env.TEST_COLLECTOR ?? "",
certificates: process.env.TEST_CERTIFICATES ?? "",

hostname_alias: "",
log_level: -2,
log_file_path: "",

max_transactions: -1,
max_flush_wait_time: -1,
events_flush_interval: -1,
max_request_size_bytes: -1,

reporter: "",

buffer_size: -1,
trace_metrics: 1,
histogram_precision: -1,
token_bucket_capacity: -1,
token_bucket_rate: -1,
file_single: 0,

ec2_metadata_timeout: -1,
grpc_proxy: "",
stdout_clear_nonblocking: 0,
metric_format: 0,

log_type: oboe.INIT_LOG_TYPE_NULL,
})
expect(reporter.init_status).to.equal(oboe.INIT_OK)

const ready = oboe.Context.isReady(INIT_TIMEOUT)
expect(ready).not.to.be.greaterThan(oboe.SERVER_RESPONSE_OK)
})
})

describe("Metadata", () => {
describe("makeRandom", () => {
it("should produce valid metadata", () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {
trace,
} from "@opentelemetry/api"

import packageJson from "../package.json"

interface InstrumentOptions {
enabled?: boolean
}
Expand All @@ -41,7 +39,7 @@ function startActiveSpan<T>(span: SpanOptions, f: (span: Span) => T): T {
const s = typeof span === "string" ? { name: span } : span()
const last = trace.getActiveSpan()

const tracer = trace.getTracer(packageJson.name, packageJson.version)
const tracer = trace.getTracer("solarwinds-apm")
return tracer.startActiveSpan(s.name, { attributes: s.kvpairs }, (span) => {
s.finalize?.(span, last)
return f(span)
Expand Down
11 changes: 8 additions & 3 deletions packages/dependencies/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ limitations under the License.
*/

import { expect, it } from "@solarwinds-apm/test"
import { readFile } from "fs/promises"

import { devDependencies } from "../package.json"
import { dependencies } from "../src/index.js"

const { devDependencies } = JSON.parse(
await readFile("package.json", { encoding: "utf-8" }),
) as { devDependencies: Record<string, string> }

const deps = await dependencies()

for (const name of Object.keys(devDependencies)) {
it(`detects ${name}`, async () => {
const deps = await dependencies()
it(`detects ${name}`, () => {
expect(deps.has(name)).to.be.true
})
}
3 changes: 3 additions & 0 deletions packages/proto/README.md
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).
3 changes: 3 additions & 0 deletions packages/proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
"eslint": "^8.50.0",
"prettier": "^3.0.3",
"protobufjs-cli": "^1.1.2"
},
"engines": {
"node": ">=16.13.0"
}
}
1 change: 1 addition & 0 deletions packages/sampling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
3 changes: 3 additions & 0 deletions packages/sampling/README.md
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.
19 changes: 19 additions & 0 deletions packages/sampling/eslint.config.js
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]
51 changes: 51 additions & 0 deletions packages/sampling/package.json
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"
}
}
19 changes: 19 additions & 0 deletions packages/sampling/rollup.config.js
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()
48 changes: 48 additions & 0 deletions packages/sampling/src/dice.ts
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
}
}
Loading

0 comments on commit 1ffd799

Please sign in to comment.