@forge/metrics 0.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +23 -0
- package/out/index.d.ts +2 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +5 -0
- package/out/internal/data-types.d.ts +56 -0
- package/out/internal/data-types.d.ts.map +1 -0
- package/out/internal/data-types.js +77 -0
- package/out/internal/index.d.ts +14 -0
- package/out/internal/index.d.ts.map +1 -0
- package/out/internal/index.js +16 -0
- package/package.json +14 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Forge internal metrics
|
|
2
|
+
|
|
3
|
+
Internal metrics methods. Use it at your own risk.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
See [Set up Forge](https://developer.atlassian.com/platform/forge/set-up-forge/) for details of the software required to develop Forge apps.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
In your Forge app, include the following:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
import { internalMetrics } from '@forge/metrics';
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
See [Runtime API reference](https://developer.atlassian.com/platform/forge/runtime-api-reference/) for details of the methods available and how to use them.
|
|
20
|
+
|
|
21
|
+
## Support
|
|
22
|
+
|
|
23
|
+
See [Get help](https://developer.atlassian.com/platform/forge/get-help/) for how to get help and provide feedback.
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
package/out/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.internalMetrics = void 0;
|
|
4
|
+
var internal_1 = require("./internal");
|
|
5
|
+
Object.defineProperty(exports, "internalMetrics", { enumerable: true, get: function () { return internal_1.internalMetrics; } });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface RuntimeMetrics {
|
|
2
|
+
invokeCounter(method: 'incr' | 'decr', counterName: string, value: number): void;
|
|
3
|
+
invokeGauge(gaugeName: string, value: number): void;
|
|
4
|
+
invokeTimer(method: 'start', timerId: null, timerName: string): string;
|
|
5
|
+
invokeTimer(method: 'stop', timerId: string, timerName: string): void;
|
|
6
|
+
}
|
|
7
|
+
export interface Counter {
|
|
8
|
+
incr(): void;
|
|
9
|
+
incrBy(value: number): void;
|
|
10
|
+
decr(): void;
|
|
11
|
+
decrBy(value: number): void;
|
|
12
|
+
}
|
|
13
|
+
export interface Gauge {
|
|
14
|
+
set(value: number): void;
|
|
15
|
+
}
|
|
16
|
+
export interface TimerStop {
|
|
17
|
+
stop(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface Timer {
|
|
20
|
+
measure(): TimerStop;
|
|
21
|
+
}
|
|
22
|
+
export declare class TimerNotInitialisedError extends Error {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
25
|
+
export declare class TimerDeadError extends Error {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
28
|
+
export declare class ExperimentalCounter implements Counter {
|
|
29
|
+
private name;
|
|
30
|
+
private readonly runtimeMetrics;
|
|
31
|
+
constructor(name: string);
|
|
32
|
+
incrBy(value: number): void;
|
|
33
|
+
incr(): void;
|
|
34
|
+
decrBy(value: number): void;
|
|
35
|
+
decr(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class ExperimentalGauge implements Gauge {
|
|
38
|
+
private name;
|
|
39
|
+
private readonly runtimeMetrics;
|
|
40
|
+
constructor(name: string);
|
|
41
|
+
set(value: number): void;
|
|
42
|
+
}
|
|
43
|
+
export declare class ExperimentalTimerStop implements TimerStop {
|
|
44
|
+
private timerName;
|
|
45
|
+
private readonly runtimeMetrics;
|
|
46
|
+
private timerId;
|
|
47
|
+
private isAlive;
|
|
48
|
+
constructor(timerName: string);
|
|
49
|
+
stop(): void;
|
|
50
|
+
}
|
|
51
|
+
export declare class ExperimentalTimer implements Timer {
|
|
52
|
+
private name;
|
|
53
|
+
constructor(name: string);
|
|
54
|
+
measure(): ExperimentalTimerStop;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=data-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-types.d.ts","sourceRoot":"","sources":["../../src/internal/data-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjF,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpD,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACvE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,KAAK;IACpB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,IAAI,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,OAAO,IAAI,SAAS,CAAC;CACtB;AAMD,qBAAa,wBAAyB,SAAQ,KAAK;;CAIlD;AAED,qBAAa,cAAe,SAAQ,KAAK;;CAIxC;AAED,qBAAa,mBAAoB,YAAW,OAAO;IAGrC,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;gBAElC,IAAI,EAAE,MAAM;IAEhC,MAAM,CAAC,KAAK,EAAE,MAAM;IAIpB,IAAI;IAIJ,MAAM,CAAC,KAAK,EAAE,MAAM;IAIpB,IAAI;CAGL;AAED,qBAAa,iBAAkB,YAAW,KAAK;IAGjC,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;gBAElC,IAAI,EAAE,MAAM;IAEhC,GAAG,CAAC,KAAK,EAAE,MAAM;CAGlB;AAED,qBAAa,qBAAsB,YAAW,SAAS;IAKzC,OAAO,CAAC,SAAS;IAJ7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;IACtD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,OAAO,CAAS;gBAEJ,SAAS,EAAE,MAAM;IAKrC,IAAI;CAYL;AAED,qBAAa,iBAAkB,YAAW,KAAK;IACjC,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,MAAM;IAEhC,OAAO;CAGR"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExperimentalTimer = exports.ExperimentalTimerStop = exports.ExperimentalGauge = exports.ExperimentalCounter = exports.TimerDeadError = exports.TimerNotInitialisedError = void 0;
|
|
4
|
+
const getRuntimeMetrics = () => {
|
|
5
|
+
return global.api.internalMetrics;
|
|
6
|
+
};
|
|
7
|
+
class TimerNotInitialisedError extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('Timer is not initialised');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.TimerNotInitialisedError = TimerNotInitialisedError;
|
|
13
|
+
class TimerDeadError extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('Timer has not been started yet or has been stopped already');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TimerDeadError = TimerDeadError;
|
|
19
|
+
class ExperimentalCounter {
|
|
20
|
+
constructor(name) {
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.runtimeMetrics = getRuntimeMetrics();
|
|
23
|
+
}
|
|
24
|
+
incrBy(value) {
|
|
25
|
+
this.runtimeMetrics.invokeCounter('incr', this.name, value);
|
|
26
|
+
}
|
|
27
|
+
incr() {
|
|
28
|
+
this.incrBy(1);
|
|
29
|
+
}
|
|
30
|
+
decrBy(value) {
|
|
31
|
+
global.api.internalMetrics.invokeCounter('decr', this.name, value);
|
|
32
|
+
}
|
|
33
|
+
decr() {
|
|
34
|
+
this.decrBy(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ExperimentalCounter = ExperimentalCounter;
|
|
38
|
+
class ExperimentalGauge {
|
|
39
|
+
constructor(name) {
|
|
40
|
+
this.name = name;
|
|
41
|
+
this.runtimeMetrics = getRuntimeMetrics();
|
|
42
|
+
}
|
|
43
|
+
set(value) {
|
|
44
|
+
this.runtimeMetrics.invokeGauge(this.name, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ExperimentalGauge = ExperimentalGauge;
|
|
48
|
+
class ExperimentalTimerStop {
|
|
49
|
+
constructor(timerName) {
|
|
50
|
+
this.timerName = timerName;
|
|
51
|
+
this.runtimeMetrics = getRuntimeMetrics();
|
|
52
|
+
this.timerId = null;
|
|
53
|
+
this.isAlive = false;
|
|
54
|
+
this.timerId = this.runtimeMetrics.invokeTimer('start', null, this.timerName);
|
|
55
|
+
this.isAlive = true;
|
|
56
|
+
}
|
|
57
|
+
stop() {
|
|
58
|
+
if (!this.timerId) {
|
|
59
|
+
throw new TimerNotInitialisedError();
|
|
60
|
+
}
|
|
61
|
+
if (!this.isAlive) {
|
|
62
|
+
throw new TimerDeadError();
|
|
63
|
+
}
|
|
64
|
+
this.runtimeMetrics.invokeTimer('stop', this.timerId, this.timerName);
|
|
65
|
+
this.isAlive = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.ExperimentalTimerStop = ExperimentalTimerStop;
|
|
69
|
+
class ExperimentalTimer {
|
|
70
|
+
constructor(name) {
|
|
71
|
+
this.name = name;
|
|
72
|
+
}
|
|
73
|
+
measure() {
|
|
74
|
+
return new ExperimentalTimerStop(this.name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ExperimentalTimer = ExperimentalTimer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Counter, ExperimentalCounter, ExperimentalGauge, ExperimentalTimer, Gauge, Timer } from './data-types';
|
|
2
|
+
export interface Metrics {
|
|
3
|
+
counter(name: string): Counter;
|
|
4
|
+
gauge(name: string): Gauge;
|
|
5
|
+
timer(name: string): Timer;
|
|
6
|
+
}
|
|
7
|
+
declare class ExperimentalMetrics implements Metrics {
|
|
8
|
+
counter(name: string): ExperimentalCounter;
|
|
9
|
+
gauge(name: string): ExperimentalGauge;
|
|
10
|
+
timer(name: string): ExperimentalTimer;
|
|
11
|
+
}
|
|
12
|
+
export declare const internalMetrics: ExperimentalMetrics;
|
|
13
|
+
export { Counter, Gauge, Timer };
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAEhH,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAC3B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B;AAED,cAAM,mBAAoB,YAAW,OAAO;IAC1C,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB,KAAK,CAAC,IAAI,EAAE,MAAM;IAIlB,KAAK,CAAC,IAAI,EAAE,MAAM;CAGnB;AAED,eAAO,MAAM,eAAe,qBAA4B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.internalMetrics = void 0;
|
|
4
|
+
const data_types_1 = require("./data-types");
|
|
5
|
+
class ExperimentalMetrics {
|
|
6
|
+
counter(name) {
|
|
7
|
+
return new data_types_1.ExperimentalCounter(name);
|
|
8
|
+
}
|
|
9
|
+
gauge(name) {
|
|
10
|
+
return new data_types_1.ExperimentalGauge(name);
|
|
11
|
+
}
|
|
12
|
+
timer(name) {
|
|
13
|
+
return new data_types_1.ExperimentalTimer(name);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.internalMetrics = new ExperimentalMetrics();
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forge/metrics",
|
|
3
|
+
"version": "0.1.0-next.0",
|
|
4
|
+
"description": "Forge internal metrics",
|
|
5
|
+
"author": "Atlassian",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"main": "out/index.js",
|
|
8
|
+
"types": "out/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "yarn run clean && yarn run compile",
|
|
11
|
+
"clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo",
|
|
12
|
+
"compile": "tsc -b -v"
|
|
13
|
+
}
|
|
14
|
+
}
|