Skip to content

Commit

Permalink
Merge branch 'main' into biolink-4-update
Browse files Browse the repository at this point in the history
  • Loading branch information
colleenXu committed Mar 7, 2024
2 parents 3bba1fe + 0b3076f commit fd578fe
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/config/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ exports.API_LIST = {
// also accessible by v1/team/Service Provider/ endpoints and by api-specific endpoints
{
id: "d22b657426375a5295e7da8a303b9893",
name: "BioLink API",
// also known as Monarch: https://monarchinitiative.org/
// NOT the same as the Biolink-model
name: "Monarch API",
},
{
id: "0212611d1c670f9107baf00b77f0889a",
Expand Down Expand Up @@ -72,6 +70,14 @@ exports.API_LIST = {
id: "1f47552dabd67351d4c625adb0a10d00",
name: "BioThings EBIgene2phenotype API",
},
{
id: "f1b8f64c316a01d1722f0fb842499fe5",
name: "BioThings FooDB API",
},
{
id: "895ec14a3650ec7ad85959a2d1554e2f",
name: "BioThings FoodData Central API",
},
{
id: "cc857d5b7c8b7609b5bbb38ff990bfff",
name: "BioThings GO Biological Process API",
Expand Down Expand Up @@ -112,6 +118,10 @@ exports.API_LIST = {
id: "b772ebfbfa536bba37764d7fddb11d6f",
name: "BioThings RARe-SOURCE API",
},
{
id: "1138c3297e8e403b6ac10cff5609b319",
name: "BioThings repoDB API",
},
{
id: "03283cc2b21c077be6794e1704b1d230",
name: "BioThings Rhea API",
Expand Down
19 changes: 18 additions & 1 deletion src/controllers/cron/update_local_smartapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ const getServerFromSpec = spec => {
return sorted_servers[0].url;
};

const sortObject = object => {
if (Array.isArray(object)) {
return object.sort();
}

// apparently typeof null is object
if (typeof object === 'object' && object !== null) {
return Object.keys(object).sort().reduce((acc, key) => {
acc[key] = sortObject(object[key]);
return acc;
}, {});
}

return object;
}

const getTRAPIWithPredicatesEndpoint = specs => {
const trapi = [];
let excluded_list = config.EXCLUDE_LIST.map(api => api.id);
Expand Down Expand Up @@ -192,12 +208,13 @@ const getOpsFromEndpoint = async metadata => {

const getOpsFromPredicatesEndpoints = async specs => {
const metadatas = getTRAPIWithPredicatesEndpoint(specs);
metadatas.sort((a, b) => a.association.smartapi.id.localeCompare(b.association.smartapi.id));
let res = [];
debug(`Now caching predicates from ${metadatas.length} TRAPI APIs`);
await Promise.allSettled(metadatas.map(metadata => getOpsFromEndpoint(metadata))).then(results => {
results.map(rec => {
if (rec.status === "fulfilled" && rec.value) {
res.push(rec.value);
res.push(sortObject(rec.value));
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/threading/taskHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ try {
debug(error);
}

const runTask = async ({ req, route, port, job: { jobId, queueName } = {} }) => {
const runTask = async ({ req, route, traceparent, tracestate, port, job: { jobId, queueName } = {} }) => {
debug(`Worker thread ${threadId} beginning ${workerData.queue} task.`);

global.SCHEMA_VERSION = "1.4.0";
Expand Down Expand Up @@ -81,7 +81,7 @@ const runTask = async ({ req, route, port, job: { jobId, queueName } = {} }) =>
scope.setSpan(transaction);
});

span = opentelemetry.trace.getTracer('biothings-explorer-thread').startSpan(routeNames[route])
span = opentelemetry.trace.getTracer('biothings-explorer-thread').startSpan(routeNames[route], undefined, opentelemetry.propagation.extract(opentelemetry.context.active(), {traceparent, tracestate}))
span.setAttribute("bte.requestData", JSON.stringify(req.data.queryGraph));
Telemetry.setOtelSpan(span);
} catch (error) {
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/threading/threadHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { MessageChannel, threadId } = require("worker_threads");
const { context, propagation, trace } = require("@opentelemetry/api");
const debug = require("debug")("bte:biothings-explorer-trapi:threading");
const path = require("path");
// const taskHandler = require("./taskHandler");
Expand Down Expand Up @@ -98,7 +99,14 @@ const queueTaskToWorkers = async (pool, req, route, job) => {
let WorkerThreadID;
const abortController = new AbortController();
const { port1: toWorker, port2: fromWorker } = new MessageChannel();
const taskData = { req, route, port: toWorker };

// get otel context
const otelData = {};
propagation.inject(context.active(), otelData);
const { traceparent, tracestate } = otelData;


const taskData = { req, route, traceparent, tracestate, port: toWorker };
if (job) taskData.job = { jobId: job.id, queueName: job.queue.name };
const task = pool.run(taskData, { signal: abortController.signal, transferList: [toWorker] });
if (job) {
Expand Down

0 comments on commit fd578fe

Please sign in to comment.