@jambonz/time-series 0.2.17 → 0.2.19
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/index.js +53 -0
- package/package.json +1 -1
- package/test/docker_start.js +1 -1
- package/test/docker_stop.js +1 -1
- package/test/unit-tests.js +17 -0
package/index.js
CHANGED
|
@@ -8,8 +8,10 @@ const AlertType = {
|
|
|
8
8
|
INVALID_APP_PAYLOAD: 'invalid-app-payload',
|
|
9
9
|
TTS_NOT_PROVISIONED: 'no-tts',
|
|
10
10
|
STT_NOT_PROVISIONED: 'no-stt',
|
|
11
|
+
LLM_NOT_PROVISIONED: 'no-llm',
|
|
11
12
|
TTS_FAILURE: 'tts-failure',
|
|
12
13
|
STT_FAILURE: 'stt-failure',
|
|
14
|
+
LLM_FAILURE: 'llm-failure',
|
|
13
15
|
CARRIER_NOT_PROVISIONED: 'no-carrier',
|
|
14
16
|
ACCOUNT_CALL_LIMIT: 'account-call-limit',
|
|
15
17
|
ACCOUNT_DEVICE_LIMIT: 'account-device-limit',
|
|
@@ -103,6 +105,17 @@ const schemas = {
|
|
|
103
105
|
'system_component',
|
|
104
106
|
'state'
|
|
105
107
|
]
|
|
108
|
+
},
|
|
109
|
+
krisp_usage: {
|
|
110
|
+
measurement: 'krisp_usage',
|
|
111
|
+
fields: {
|
|
112
|
+
usage_seconds: Influx.FieldType.INTEGER
|
|
113
|
+
},
|
|
114
|
+
tags: [
|
|
115
|
+
'service_provider_sid',
|
|
116
|
+
'account_sid',
|
|
117
|
+
'feature'
|
|
118
|
+
]
|
|
106
119
|
}
|
|
107
120
|
};
|
|
108
121
|
|
|
@@ -528,6 +541,26 @@ const writeSystemAlerts = async(client, systemAlerts) => {
|
|
|
528
541
|
await writeData(client);
|
|
529
542
|
return;
|
|
530
543
|
};
|
|
544
|
+
|
|
545
|
+
const writeKrispUsage = async(client, usage) => {
|
|
546
|
+
if (!client.locals.initialized) await initDatabase(client, 'krisp_usage');
|
|
547
|
+
const {service_provider_sid, account_sid, feature, ...fields} = usage;
|
|
548
|
+
const data = {
|
|
549
|
+
measurement: 'krisp_usage',
|
|
550
|
+
timestamp: new Date(),
|
|
551
|
+
fields,
|
|
552
|
+
tags: {
|
|
553
|
+
service_provider_sid,
|
|
554
|
+
account_sid,
|
|
555
|
+
feature
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
client.locals.data = [...client.locals.data, ...[data]];
|
|
559
|
+
if (client.locals.data.length >= client.locals.commitSize) {
|
|
560
|
+
await writeData(client);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
|
|
531
564
|
const queryCdrsSP = async(client, opts) => {
|
|
532
565
|
if (!client.locals.initialized) await initDatabase(client, 'cdrs');
|
|
533
566
|
const response = {
|
|
@@ -648,6 +681,14 @@ const writeAlerts = async(client, alerts) => {
|
|
|
648
681
|
// eslint-disable-next-line max-len
|
|
649
682
|
message = `speech to text request to ${vendor} (label: ${label || 'none'}) failed; please check your speech credentials`;
|
|
650
683
|
break;
|
|
684
|
+
case AlertType.LLM_NOT_PROVISIONED:
|
|
685
|
+
// eslint-disable-next-line max-len
|
|
686
|
+
message = `large language model credentials for ${vendor} (label: ${label || 'none'}) have not been provisioned`;
|
|
687
|
+
break;
|
|
688
|
+
case AlertType.LLM_FAILURE:
|
|
689
|
+
// eslint-disable-next-line max-len
|
|
690
|
+
message = `large language model request to ${vendor} (label: ${label || 'none'}) failed; please check your LLM credentials`;
|
|
691
|
+
break;
|
|
651
692
|
case AlertType.CARRIER_NOT_PROVISIONED:
|
|
652
693
|
message = 'outbound call failure: no carriers have been provisioned';
|
|
653
694
|
break;
|
|
@@ -784,6 +825,8 @@ module.exports = (logger, opts) => {
|
|
|
784
825
|
// eslint-disable-next-line max-len
|
|
785
826
|
const callCountAppClient = new Influx.InfluxDB({database: 'app_call_counts', schemas: schemas.app_call_counts, ...opts});
|
|
786
827
|
const systemAlertClient = new Influx.InfluxDB({database: 'system_alerts', schemas: schemas.system_alerts, ...opts});
|
|
828
|
+
// eslint-disable-next-line max-len
|
|
829
|
+
const krispUsageClient = new Influx.InfluxDB({database: 'krisp_usage', schemas: schemas.krisp_usage, ...opts});
|
|
787
830
|
|
|
788
831
|
cdrClient.locals = {
|
|
789
832
|
db: 'cdrs',
|
|
@@ -833,6 +876,14 @@ module.exports = (logger, opts) => {
|
|
|
833
876
|
commitInterval: opts.commitInterval || 10,
|
|
834
877
|
data: []
|
|
835
878
|
};
|
|
879
|
+
krispUsageClient.locals = {
|
|
880
|
+
db: 'krisp_usage',
|
|
881
|
+
initialized: false,
|
|
882
|
+
writing: false,
|
|
883
|
+
commitSize: opts.commitSize || 1,
|
|
884
|
+
commitInterval: opts.commitInterval || 10,
|
|
885
|
+
data: []
|
|
886
|
+
};
|
|
836
887
|
|
|
837
888
|
if (opts.commitSize > 1 && opts.commitInterval && opts.commitInterval > 2) {
|
|
838
889
|
setInterval(writeData.bind(null, callCountClient), opts.commitInterval * 1000);
|
|
@@ -840,6 +891,7 @@ module.exports = (logger, opts) => {
|
|
|
840
891
|
setInterval(writeData.bind(null, callCountAppClient), opts.commitInterval * 1000);
|
|
841
892
|
setInterval(writeData.bind(null, cdrClient), opts.commitInterval * 1000);
|
|
842
893
|
setInterval(writeData.bind(null, alertClient), opts.commitInterval * 1000);
|
|
894
|
+
setInterval(writeData.bind(null, krispUsageClient), opts.commitInterval * 1000);
|
|
843
895
|
}
|
|
844
896
|
|
|
845
897
|
return {
|
|
@@ -856,6 +908,7 @@ module.exports = (logger, opts) => {
|
|
|
856
908
|
queryAlerts: queryAlerts.bind(null, alertClient),
|
|
857
909
|
queryAlertsSP: queryAlertsSP.bind(null, alertClient),
|
|
858
910
|
writeSystemAlerts: writeSystemAlerts.bind(null, systemAlertClient),
|
|
911
|
+
writeKrispUsage: writeKrispUsage.bind(null, krispUsageClient),
|
|
859
912
|
AlertType: { ...AlertType }
|
|
860
913
|
};
|
|
861
914
|
};
|
package/package.json
CHANGED
package/test/docker_start.js
CHANGED
|
@@ -2,7 +2,7 @@ const test = require('tape');
|
|
|
2
2
|
const exec = require('child_process').exec ;
|
|
3
3
|
|
|
4
4
|
test('starting docker network..', (t) => {
|
|
5
|
-
exec(`docker
|
|
5
|
+
exec(`docker compose -f "${__dirname}/docker-compose-testbed.yaml" up -d`, (err, stdout, stderr) => {
|
|
6
6
|
setTimeout(() => {
|
|
7
7
|
t.pass('docker started');
|
|
8
8
|
t.end(err);
|
package/test/docker_stop.js
CHANGED
|
@@ -3,7 +3,7 @@ const exec = require('child_process').exec ;
|
|
|
3
3
|
|
|
4
4
|
test('stopping docker network..', (t) => {
|
|
5
5
|
t.timeoutAfter(10000);
|
|
6
|
-
exec(`docker
|
|
6
|
+
exec(`docker compose -f "${__dirname}/docker-compose-testbed.yaml" down`, (err, stdout, stderr) => {
|
|
7
7
|
//console.log(`stderr: ${stderr}`);
|
|
8
8
|
process.exit(0);
|
|
9
9
|
});
|
package/test/unit-tests.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
writeAlerts,
|
|
16
16
|
queryAlerts,
|
|
17
17
|
queryAlertsSP,
|
|
18
|
+
writeKrispUsage,
|
|
18
19
|
AlertType
|
|
19
20
|
} = require('..')(consoleLogger, '127.0.0.1', {commitSize: 1});
|
|
20
21
|
|
|
@@ -266,4 +267,20 @@ test('write timeseries data', async(t) => {
|
|
|
266
267
|
//console.log(JSON.stringify(result));
|
|
267
268
|
t.ok(result.data.length === 2 && result.data[0].calls_in_progress === 21, 'queried call counts by application_sid');
|
|
268
269
|
|
|
270
|
+
result = await writeKrispUsage({
|
|
271
|
+
service_provider_sid: 'zzzzz',
|
|
272
|
+
account_sid: 'yyyy',
|
|
273
|
+
feature: 'noise_cancellation',
|
|
274
|
+
usage_seconds: 120
|
|
275
|
+
});
|
|
276
|
+
t.pass('wrote krisp usage for noise cancellation');
|
|
277
|
+
|
|
278
|
+
result = await writeKrispUsage({
|
|
279
|
+
service_provider_sid: 'zzzzz',
|
|
280
|
+
account_sid: 'yyyy',
|
|
281
|
+
feature: 'turn_taking',
|
|
282
|
+
usage_seconds: 45
|
|
283
|
+
});
|
|
284
|
+
t.pass('wrote krisp usage for turn taking');
|
|
285
|
+
|
|
269
286
|
});
|