-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* promql handler prototype Signed-off-by: Lorenzo Mangani <[email protected]> * Update qryn.js Signed-off-by: Lorenzo Mangani <[email protected]> * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * Create prom_query.js Signed-off-by: Lorenzo Mangani <[email protected]> * Update qryn.js Signed-off-by: Lorenzo Mangani <[email protected]> * update logql2promql library Signed-off-by: Lorenzo Mangani <[email protected]> * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * Update qryn.js Signed-off-by: Lorenzo Mangani <[email protected]> * Update prom_query.js Signed-off-by: Lorenzo Mangani <[email protected]> * resync * Update qryn.js Signed-off-by: Lorenzo Mangani <[email protected]> * start/end s -> ns conv * nodejs "standard" standard cleanup * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * labels and values prom support * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> * Update package.json Signed-off-by: Lorenzo Mangani <[email protected]> Signed-off-by: Lorenzo Mangani <[email protected]> Co-authored-by: akvlad <[email protected]>
- Loading branch information
Showing
8 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Emulated PromQL Query Handler */ | ||
|
||
async function handler (req, res) { | ||
req.log.debug('GET /api/v1/*') | ||
const resp = {"status": "success", "data": {}}; | ||
res.send(resp) | ||
return | ||
} | ||
|
||
module.exports = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Emulated PromQL Query Handler */ | ||
|
||
const { p2l } = require('@qxip/promql2logql'); | ||
const empty = '{"status" : "success", "data" : {"resultType" : "scalar", "result" : []}}'; // to be removed | ||
|
||
async function handler (req, res) { | ||
req.log.debug('GET /loki/api/v1/query') | ||
const resp = { streams: [] } | ||
if (!req.query.query) { | ||
res.send(resp) | ||
return | ||
} | ||
/* remove newlines */ | ||
req.query.query = req.query.query.replace(/\n/g, ' ') | ||
/* transpile to logql */ | ||
try { | ||
req.query.query = p2l(req.query.query); | ||
} catch(e) { | ||
req.log.error({ err }) | ||
res.send(empty) | ||
} | ||
/* scan fingerprints */ | ||
/* TODO: handle time tag + direction + limit to govern the query output */ | ||
try { | ||
await this.instantQueryScan( | ||
req.query, | ||
{ res: res.raw } | ||
) | ||
} catch (err) { | ||
req.log.error({ err }) | ||
res.send(empty) | ||
} | ||
} | ||
|
||
module.exports = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* Emulated PromQL Query Handler */ | ||
/* | ||
Converts PromQL to LogQL queries, accepts the following parameters in the query-string: | ||
query: a PromQL query | ||
limit: max number of entries to return | ||
start: the start time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) | ||
end: the end time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) | ||
direction: forward or backward, useful when specifying a limit | ||
regexp: a regex to filter the returned results, will eventually be rolled into the query language | ||
*/ | ||
|
||
const { p2l } = require('@qxip/promql2logql') | ||
|
||
async function handler (req, res) { | ||
req.log.debug('GET /api/v1/query_range') | ||
const resp = { streams: [] } | ||
if (!req.query.query) { | ||
res.send(resp) | ||
return | ||
} | ||
/* remove newlines */ | ||
req.query.query = req.query.query.replace(/\n/g, ' ') | ||
if (!req.query.query) { | ||
res.code(400).send('invalid query') | ||
return | ||
} | ||
// Convert PromQL to LogQL and execute | ||
try { | ||
req.query.query = p2l(req.query.query) | ||
await this.scanFingerprints( | ||
{ | ||
...req.query, | ||
start: parseInt(req.query.start) * 1e9, | ||
end: parseInt(req.query.end) * 1e9 | ||
}, | ||
{ res: res.raw } | ||
) | ||
res.sent = true | ||
} catch (err) { | ||
req.log.error({ err }) | ||
res.send(resp) | ||
} | ||
} | ||
|
||
module.exports = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Label Handler */ | ||
/* | ||
For retrieving the names of the labels one can query on. | ||
Responses looks like this: | ||
{ | ||
"values": [ | ||
"instance", | ||
"job", | ||
... | ||
] | ||
} | ||
*/ | ||
|
||
async function handler (req, res) { | ||
await require('./label.js')({ | ||
...req, | ||
query: { | ||
...req.query, | ||
start: req.query.start ? parseInt(req.query.start) * 1e9 : undefined, | ||
end: req.query.end ? parseInt(req.query.end) * 1e9 : undefined | ||
} | ||
}, res) | ||
} | ||
|
||
module.exports = handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Label Value Handler */ | ||
/* | ||
For retrieving the label values one can query on. | ||
Responses looks like this: | ||
{ | ||
"values": [ | ||
"default", | ||
"cortex-ops", | ||
... | ||
] | ||
} | ||
*/ | ||
|
||
async function handler (req, res) { | ||
await require('./label_values.js')({ | ||
...req, | ||
query: { | ||
...req.query, | ||
start: req.query.start ? parseInt(req.query.start) * 1e9 : undefined, | ||
end: req.query.end ? parseInt(req.query.end) * 1e9 : undefined | ||
} | ||
}, res) | ||
} | ||
|
||
module.exports = handler |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters