Skip to content

Commit

Permalink
closer to passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dletta committed Nov 9, 2021
1 parent 5ea20e5 commit b5dc7bd
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 163,478 deletions.
12 changes: 6 additions & 6 deletions lib/db/clickhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const axios = require('axios')
const protocol = process.env.CLICKHOUSE_PROTO || 'http'

// External Storage Policy for Tables (S3, MINIO)
const storagePolicy = process.env.storagePolicy || false
const storagePolicy = process.env.STORAGE_POLICY || false

const { StringStream, DataStream } = require('scramjet')

Expand Down Expand Up @@ -476,15 +476,15 @@ const scanMetricFingerprints = function (settings, client, params) {
if (!settings.timefield) settings.timefield = process.env.CLICKHOUSE_TIMEFIELD || 'record_datetime'

const tags = settings.tag.split(',')
let template = 'SELECT ' + tags.join(', ') + ', groupArray((toUnixTimestamp(timestampMs)*1000, toString(value))) AS groupArr FROM (SELECT '
let template = 'SELECT ' + tags.join(', ') + ', groupArray((toUnixTimestamp(timestamp_ms)*1000, toString(value))) AS groupArr FROM (SELECT '
if (tags) {
tags.forEach(function (tag) {
tag = tag.trim()
template += " visitParamExtractString(labels, '" + tag + "') as " + tag + ','
})
}
// if(settings.interval > 0){
template += ' toStartOfInterval(toDateTime(timestampMs/1000), INTERVAL ' + settings.interval + ' second) as timestampMs, value' +
template += ' toStartOfInterval(toDateTime(timestamp_ms/1000), INTERVAL ' + settings.interval + ' second) as timestamp_ms, value' +
// } else {
// template += " timestampMs, value"
// }
Expand All @@ -504,7 +504,7 @@ const scanMetricFingerprints = function (settings, client, params) {
if (settings.where) {
template += ' AND ' + settings.where
}
template += ' AND value > 0 ORDER BY timestampMs) GROUP BY ' + tags.join(', ')
template += ' AND value > 0 ORDER BY timestamp_ms) GROUP BY ' + tags.join(', ')

if (debug) console.log('CLICKHOUSE METRICS SEARCH QUERY', template)

Expand Down Expand Up @@ -686,7 +686,7 @@ const ping = async () => {
* @param request {string}
* @param options {{db : string | undefined, timeout_sec: number | undefined}}
*/
module.exports.create_live_view = (name, request, options) => {
module.exports.createLiveView = (name, request, options) => {
const db = options.db || clickhouseOptions.queryOptions.database
const timeout = options.timeout_sec ? `WITH TIMEOUT ${options.timeout_sec}` : ''
return axios.post(`${getClickhouseUrl()}/?allow_experimental_live_view=1`,
Expand All @@ -704,7 +704,7 @@ module.exports.create_live_view = (name, request, options) => {
* }}
* @returns Promise<[Promise<void>, CancelTokenSource]>
*/
module.exports.watch_live_view = async (name, db, res, options) => {
module.exports.watchLiveView = async (name, db, res, options) => {
db = db || clickhouseOptions.queryOptions.database
const cancel = axios.CancelToken.source()
const stream = await axios.post(`${getClickhouseUrl()}/?allow_experimental_live_view=1`,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const clickParser = function (query) {
/* Example cQL format */
/* clickhouse({db="mydb", table="mytable", tag="key", metric="avg(value)", interval=60}) */
const regx = /clickhouse\((.*)\)/g
const clickQuery = regx.exec(query.query)[1] || false
const clickQuery = regx.exec(req.query.query)[1] || false // TODO: req. correct?
return labelParser(clickQuery)
}

Expand Down
74 changes: 37 additions & 37 deletions parser/registry/unwrap_registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,52 @@ module.exports = {
return reg.rate.viaRequest(token, query)
},
/**
* sum_over_time(unwrapped-range): the sum of all values in the specified interval.
* sumOverTime(unwrapped-range): the sum of all values in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
sum_over_time: (token, query) => {
sumOverTime: (token, query) => {
if (query.stream) {
return reg.sum_over_time.viaStream(token, query)
return reg.sumOverTime.viaStream(token, query)
}
return reg.sum_over_time.viaRequest(token, query)
return reg.sumOverTime.viaRequest(token, query)
},
/**
* avg_over_time(unwrapped-range): the average value of all points in the specified interval.
* avgOverTime(unwrapped-range): the average value of all points in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
avg_over_time: (token, query) => {
avgOverTime: (token, query) => {
if (query.stream) {
return reg.avg_over_time.viaStream(token, query)
return reg.avgOverTime.viaStream(token, query)
}
return reg.avg_over_time.viaRequest(token, query)
return reg.avgOverTime.viaRequest(token, query)
},
/**
* max_over_time(unwrapped-range): the maximum value of all points in the specified interval.
* maxOverTime(unwrapped-range): the maximum value of all points in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
max_over_time: (token, query) => {
maxOverTime: (token, query) => {
if (query.stream) {
return reg.max_over_time.viaStream(token, query)
return reg.maxOverTime.viaStream(token, query)
}
return reg.max_over_time.viaRequest(token, query)
return reg.maxOverTime.viaRequest(token, query)
},
/**
* min_over_time(unwrapped-range): the minimum value of all points in the specified interval
* minOverTime(unwrapped-range): the minimum value of all points in the specified interval
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
min_over_time: (token, query) => {
minOverTime: (token, query) => {
if (query.stream) {
return reg.min_over_time.viaStream(token, query)
return reg.minOverTime.viaStream(token, query)
}
return reg.min_over_time.viaRequest(token, query)
return reg.minOverTime.viaRequest(token, query)
},
/**
* first_over_time(unwrapped-range): the first value of all points in the specified interval
Expand All @@ -75,69 +75,69 @@ module.exports = {
return reg.first_over_time.viaRequest(token, query)
},
/**
* last_over_time(unwrapped-range): the last value of all points in the specified interval
* lastOverTime(unwrapped-range): the last value of all points in the specified interval
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
last_over_time: (token, query) => {
lastOverTime: (token, query) => {
if (query.stream) {
return reg.last_over_time.viaStream(token, query)
return reg.lastOverTime.viaStream(token, query)
}
return reg.last_over_time.viaRequest(token, query)
return reg.lastOverTime.viaRequest(token, query)
},
/**
* stdvar_over_time(unwrapped-range): the population standard variance of the values in the specified interval.
* stdvarOverTime(unwrapped-range): the population standard variance of the values in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
stdvar_over_time: (token, query) => {
stdvarOverTime: (token, query) => {
if (query.stream) {
return reg.stdvar_over_time.viaStream(token, query)
return reg.stdvarOverTime.viaStream(token, query)
}
return reg.stdvar_over_time.viaRequest(token, query)
return reg.stdvarOverTime.viaRequest(token, query)
},
/**
* stddev_over_time(unwrapped-range): the population standard deviation of the values in the specified interval.
* stddevOverTime(unwrapped-range): the population standard deviation of the values in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
stddev_over_time: (token, query) => {
stddevOverTime: (token, query) => {
if (query.stream) {
return reg.stddev_over_time.viaStream(token, query)
return reg.stddevOverTime.viaStream(token, query)
}
return reg.stddev_over_time.viaRequest(token, query)
return reg.stddevOverTime.viaRequest(token, query)
},
/**
* quantile_over_time(scalar,unwrapped-range): the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.
* quantileOverTime(scalar,unwrapped-range): the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
quantile_over_time: (token, query) => {
quantileOverTime: (token, query) => {
if (query.stream) {
return reg.quantile_over_time.viaStream(token, query)
return reg.quantileOverTime.viaStream(token, query)
}
return reg.quantile_over_time.viaRequest(token, query)
return reg.quantileOverTime.viaRequest(token, query)
},
/**
* absent_over_time(unwrapped-range): returns an empty vector if the range vector passed to it has any elements and a 1-element vector with the value 1 if the range vector passed to it has no elements. (absent_over_time is useful for alerting on when no time series and logs stream exist for label combination for a certain amount of time.)
* absentOverTime(unwrapped-range): returns an empty vector if the range vector passed to it has any elements and a 1-element vector with the value 1 if the range vector passed to it has no elements. (absentOverTime is useful for alerting on when no time series and logs stream exist for label combination for a certain amount of time.)
* @param token {Token}
* @param query {registry_types.Request}
* @returns {registry_types.Request}
*/
absent_over_time: (token, query) => {
absentOverTime: (token, query) => {
if (query.stream) {
return reg.absent_over_time.viaStream(token, query)
return reg.absentOverTime.viaStream(token, query)
}
return reg.absent_over_time.viaRequest(token, query)
return reg.absentOverTime.viaRequest(token, query)
},

...getPlugins('unwrap_registry', (plugin) => {
return (token, query) => {
return reg.apply_viaStream(
return reg.applyViaStream(
token,
query,
plugin.run,
Expand Down
2 changes: 1 addition & 1 deletion parser/registry/unwrap_registry/unwrap_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getDuration, concatLabels, applyViaStream } = require('../common')
*
* @param viaRequest {function(Token, registry_types.Request): registry_types.Request}
* @param viaStream {function(Token, registry_types.Request): registry_types.Request}
* @returns { {
* @returns {
* viaRequest: function(Token, registry_types.Request): registry_types.Request,
* viaStream: function(Token, registry_types.Request): registry_types.Request} }
*/
Expand Down
2 changes: 1 addition & 1 deletion parser/transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module.exports.transpile = (request) => {
*/
module.exports.transpileTail = (request) => {
const expression = compiler.ParseScript(request.query.trim())
const denied = ['user_macro', 'aggregation_operator', 'unwra_function', 'log_range_aggregation']
const denied = ['user_macro', 'aggregation_operator', 'unwrap_function', 'log_range_aggregation']
for (const d of denied) {
if (expression.rootToken.Child(d)) {
throw new Error(`${d} is not supported. Only raw logs are supported`)
Expand Down
Loading

0 comments on commit b5dc7bd

Please sign in to comment.