Skip to content

Commit

Permalink
Merge pull request #172 from openmhz/stats-display
Browse files Browse the repository at this point in the history
fixes for slow
  • Loading branch information
robotastic authored Sep 15, 2024
2 parents 1b6563c + d0ffb84 commit 8411efa
Show file tree
Hide file tree
Showing 18 changed files with 3,001 additions and 3,033 deletions.
14 changes: 11 additions & 3 deletions account/server/config/secrets.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/** Important **/
/** You should not be committing this file to GitHub **/
/** Repeat: DO! NOT! COMMIT! THIS! FILE! TO! YOUR! REPO! **/
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : 27017;
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
const mongo_host = typeof process.env['MONGO_HOST'] !== 'undefined' ? process.env['MONGO_HOST'] : 'mongo';
const mongo_port = typeof process.env['MONGO_PORT'] !== 'undefined' ? process.env['MONGO_PORT'] : 27017;
const mongo_user = process.env['MONGO_USER'];
const mongo_password = process.env['MONGO_PASSWORD'];

let mongoUrl;

if ((typeof mongo_user !== 'undefined') && (typeof mongo_password !== 'undefined')) {
console.log("Using authentication for MongoDB - user: " + mongo_user);
mongoUrl = 'mongodb://' + mongo_user + ':' + mongo_password + '@' + mongo_host + ':' + mongo_port + '/scanner';
} else {
mongoUrl = 'mongodb://' + mongo_host + ':' + mongo_port + '/scanner';
}

const secrets = {
db: mongoUrl,
Expand Down
5 changes: 3 additions & 2 deletions account/src/User/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ const Login = (props) => {
const loginSubmit = async (event) => {
event.preventDefault();
const result = await dispatch(loginUser({ email, password })).unwrap();
const user = result.user;
if (result.success) {
if ((pathname != "/terms") && (terms != 1.1)) {
if ((pathname != "/terms") && (user.terms != 1.1)) {
navigate("/terms")
} else if (nextLocation) {
switch (nextLocation) {
Expand Down Expand Up @@ -130,7 +131,7 @@ const Login = (props) => {
href="mailto:{process.env.REACT_APP_ADMIN_EMAIL}?Subject={process.env.REACT_APP_SITE_NAME}"
target="_top"
>
[email protected]
{process.env.REACT_APP_ADMIN_EMAIL}
</a>{" "}
</p>
</Grid.Column>
Expand Down
14 changes: 11 additions & 3 deletions admin/server/config/secrets.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/** Important **/
/** You should not be committing this file to GitHub **/
/** Repeat: DO! NOT! COMMIT! THIS! FILE! TO! YOUR! REPO! **/
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : 27017;
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
const mongo_host = typeof process.env['MONGO_HOST'] !== 'undefined' ? process.env['MONGO_HOST'] : 'mongo';
const mongo_port = typeof process.env['MONGO_PORT'] !== 'undefined' ? process.env['MONGO_PORT'] : 27017;
const mongo_user = process.env['MONGO_USER'];
const mongo_password = process.env['MONGO_PASSWORD'];

let mongoUrl;

if ((typeof mongo_user !== 'undefined') && (typeof mongo_password !== 'undefined')) {
console.log("Using authentication for MongoDB - user: " + mongo_user);
mongoUrl = 'mongodb://' + mongo_user + ':' + mongo_password + '@' + mongo_host + ':' + mongo_port + '/scanner';
} else {
mongoUrl = 'mongodb://' + mongo_host + ':' + mongo_port + '/scanner';
}

module.exports = secrets = {
db: mongoUrl,
Expand Down
5 changes: 3 additions & 2 deletions admin/server/controllers/talkgroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports.exportTalkgroups = function (req, res, next) {

async function csv_import(shortName, filename, callback) {
var talkgroups = [];
const count = await Talkgroup.deleteMany({ shortName: shortName });


var parser = parse(
{
Expand All @@ -90,14 +90,15 @@ async function csv_import(shortName, filename, callback) {
console.error("Error: csv import 2: " + err);
callback(err, null);
} else {
const count = await Talkgroup.deleteMany({ shortName: shortName });
var response = [];

for (var i = 0; i < data.length; i++) {
var row = data[i];
if (!( "Decimal" in row) || !("Description" in row) || !("Alpha Tag" in row)) {
console.error("Error: csv import column header error");
console.error(row)
callback("Column Headers are required - Required Columns: 'Decimal' 'Decscription' 'Alpha Tag' Optional Column: 'Priority' ", null);
callback("Column Headers are required - Required Columns: 'Decimal' 'Description' 'Alpha Tag' Optional Column: 'Priority' ", null);
return
}

Expand Down
1 change: 1 addition & 0 deletions admin/src/System/System.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ const System = () => {
<em>
The Talkgroup file is a .CSV file that has infromation about the different talkgroups on the system. Headers are required for the columns, and should be the first
line of the file. The columns can be in any order, but the headers must match exactly.<br/>
<p>If you export the file from Excel, make sure to use "Comma Separated Values" and NOT "CSV UTF-8" for the File Format.</p>
An example header line is: <br />
<code>Decimal,Alpha Tag,Description</code><br/>
<p>There can be additional columns so you can use the same Talkgroup CSV file from Trunk Recorder.</p>
Expand Down
28 changes: 27 additions & 1 deletion backend/agents/otel-tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

const opentelemetry = require('@opentelemetry/sdk-node');
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');

const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
const {
Detector,
DetectorSync,
IResource,
ResourceDetectionConfig,
envDetectorSync,
hostDetectorSync,
processDetectorSync,
} = require("@opentelemetry/resources")
// const {
// dockerCGroupV1Detector,
// } = require('@opentelemetry/resource-detector-docker');
Expand All @@ -20,6 +28,19 @@ console.log("OTEL_EXPORTER_OTLP_HEADERS: " + process.env.OTEL_EXPORTER_OTLP_HEAD
console.log("OTEL_SERVICE_NAME: " + process.env.OTEL_SERVICE_NAME);


// from https://github.com/open-telemetry/opentelemetry-js/issues/4638
// this is a workaround to wait for async attributes to be resolved
function awaitAttributes(detector){
return {
async detect(config) {
const resource = detector.detect(config)
await resource.waitForAsyncAttributes()

return resource
},
}
}

const samplePercentage = 0.05;

const sdk = new opentelemetry.NodeSDK({
Expand All @@ -37,6 +58,11 @@ const sdk = new opentelemetry.NodeSDK({
},
}),
],
resourceDetectors: [
awaitAttributes(envDetectorSync),
awaitAttributes(processDetectorSync),
awaitAttributes(hostDetectorSync),
],
//resourceDetectors: [dockerCGroupV1Detector],
});

Expand Down
84 changes: 45 additions & 39 deletions backend/controllers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var fs = require('fs');

const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3");
const { fromIni } = require("@aws-sdk/credential-providers");
const e = require('express');

var s3_endpoint = process.env['S3_ENDPOINT'] != null ? process.env['S3_ENDPOINT'] : 'https://s3.us-west-1.wasabisys.com';
var s3_region = process.env['S3_REGION'] != null ? process.env['S3_REGION'] : 'us-west-1';
Expand Down Expand Up @@ -177,43 +178,47 @@ const createPodcast = async (tmpEventFolder, podcastFile, event) => {
inputs.forEach((value, i) => {
concat = concat + "file '" + value + "'\n";
});
const concatFile = tmpEventFolder + "/FILES.txt"
fs.writeFileSync(concatFile, concat, "utf8");
// https://video.stackexchange.com/questions/21315/concatenating-split-media-files-using-concat-protocol
//ffmpeg -f concat -safe 0 -i mylist.txt -c copy output
command.push("-hide_banner");
command.push("-loglevel");
command.push("error");
command.push("-f");
command.push("concat");
command.push("-safe");
command.push("0");
command.push("-i");
command.push(concatFile);
command.push("-acodec");
command.push("aac");
command.push(tmpFile);
await ffmpeg(command);


const chapters = createChapters(event);
const chaptersFile = tmpEventFolder + "/CHAPTERS.txt"
fs.writeFileSync(chaptersFile, chapters, "utf8");
command = [];
command.push("-hide_banner");
command.push("-loglevel");
command.push("error");
command.push("-i");
command.push(tmpFile)
command.push("-i");
command.push(chaptersFile)
command.push("-map_metadata")
command.push("1")
command.push("-codec");
command.push("copy");
command.push(podcastFile)
//console.log("Running command: " + command);
await ffmpeg(command);
try {
const concatFile = tmpEventFolder + "/FILES.txt"
fs.writeFileSync(concatFile, concat, "utf8");
// https://video.stackexchange.com/questions/21315/concatenating-split-media-files-using-concat-protocol
//ffmpeg -f concat -safe 0 -i mylist.txt -c copy output
command.push("-hide_banner");
command.push("-loglevel");
command.push("error");
command.push("-f");
command.push("concat");
command.push("-safe");
command.push("0");
command.push("-i");
command.push(concatFile);
command.push("-acodec");
command.push("aac");
command.push(tmpFile);
await ffmpeg(command);


const chapters = createChapters(event);
const chaptersFile = tmpEventFolder + "/CHAPTERS.txt"
fs.writeFileSync(chaptersFile, chapters, "utf8");
command = [];
command.push("-hide_banner");
command.push("-loglevel");
command.push("error");
command.push("-i");
command.push(tmpFile)
command.push("-i");
command.push(chaptersFile)
command.push("-map_metadata")
command.push("1")
command.push("-codec");
command.push("copy");
command.push(podcastFile)
//console.log("Running command: " + command);
await ffmpeg(command);
} catch (e) {
console.error("Error creating podcast " + e);
}
}

const cleanupEvent = (folder, filename) => {
Expand Down Expand Up @@ -382,11 +387,12 @@ exports.addNewEvent = async function (req, res, next) {
const savedEvent = await event.save();
//console.log("Event ID " + savedEvent._id);
const url = "/events/" + event._id;
res.contentType('json');
res.send(JSON.stringify({ url: url }));

await packageEvent(savedEvent._id);

res.contentType('json');
res.send(JSON.stringify({ url: url }));

}
catch (err) {
console.error("Error creating event" + err);
Expand Down
12 changes: 0 additions & 12 deletions backend/controllers/groups.js
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
const Group = require("../models/group");

exports.get_groups = async function (req, res) {
const grp_results = await Group.find({ shortName: req.params.shortName.toLowerCase()}).sort("position").catch(err => {
console.error(err);
res.status(500);
res.json({ success: false, message: err });
return;
});

res.contentType('json');
res.send(JSON.stringify(grp_results));
}
47 changes: 40 additions & 7 deletions backend/controllers/talkgroups.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
const Talkgroup = require("../models/talkgroup");
const Group = require("../models/group");

exports.get_talkgroups = async function (req, res) {
const tg_results = await Talkgroup.find({ 'shortName': req.params.shortName.toLowerCase()}).catch(err => {
let groups = {};
let talkgroups = {};

async function load_talkgroups(shortName) {
const tg_results = await Talkgroup.find({ 'shortName': shortName }).catch(err => {
console.error(err);
res.status(500);
res.json({ success: false, message: err });
return;
});
var talkgroups = {};
});

let temp = {}
for (var tg in tg_results) {
var talkgroup = {_id: tg_results[tg]._id, num: tg_results[tg].num, alpha: tg_results[tg].alpha, description: tg_results[tg].description}
talkgroups[tg_results[tg].num] = talkgroup;
var talkgroup = { _id: tg_results[tg]._id, num: tg_results[tg].num, alpha: tg_results[tg].alpha, description: tg_results[tg].description }
temp[tg_results[tg].num] = talkgroup;
}

return temp;
}

exports.get_talkgroups = async function (req, res) {
const shortName = req.params.shortName.toLowerCase();
/*
if (talkgroups.hasOwnProperty(shortName)) {
talkgroups = talkgroups[shortName];
} else {
}*/

let talkgroups = await load_talkgroups(shortName);

res.contentType('json');
res.send(JSON.stringify({
talkgroups: talkgroups
}));
}


exports.get_groups = async function (req, res) {
const shortName = req.params.shortName.toLowerCase();

const grp_results = await Group.find({ shortName: req.params.shortName.toLowerCase() }).sort("position").catch(err => {
console.error(err);
res.status(500);
res.json({ success: false, message: err });
return;
});

res.contentType('json');
res.send(JSON.stringify(grp_results));
}
Loading

0 comments on commit 8411efa

Please sign in to comment.