Skip to content

Commit

Permalink
Merge branch 'main' into kg-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome authored Mar 9, 2024
2 parents 2d3235d + 0b3076f commit 5d1017b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 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
9 changes: 1 addition & 8 deletions src/config/smartapi_overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@
"conf": {
"only_overrides": false
},
"apis": {
"671b45c0301c8624abbd26ae78449ca2": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/orphanet-change/mydisease.info/smartapi.yaml",
"b772ebfbfa536bba37764d7fddb11d6f": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/orphanet-change/ncats_rare_source/smartapi.yaml",
"326eb1e437303bee27d3cef29227125d": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/orphanet-change/complexportal/smartapi.yaml",
"0212611d1c670f9107baf00b77f0889a": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/ctd-batch-query/CTD/smartapi.yaml",
"8f08d1446e0bb9c2b323713ce83e2bd3": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/mychem-fda-orphan-edit/mychem.info/openapi_full.yml",
"d22b657426375a5295e7da8a303b9893": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/v3-biolink-monarch/biolink/openapi.yml"
}
"apis": {}
}
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 @@ -63,6 +63,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 @@ -194,12 +210,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
12 changes: 10 additions & 2 deletions 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,8 +99,15 @@ 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 };
taskData.req.data.options = {...taskData.req.optoins, metakg: global.metakg?.ops};

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

const taskData = { req, route, traceparent, tracestate, port: toWorker };
taskData.req.data.options = {...taskData.req.data.options, metakg: global.metakg?.ops};

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 5d1017b

Please sign in to comment.