-
Notifications
You must be signed in to change notification settings - Fork 22
Support back-shift using e.g. "bshift_1_days" #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ const units = [ | |
'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'quarter', | ||
'y', 'M', 'w', 'd', 'h', 'm', 's', 'ms', 'Q', | ||
]; | ||
const shift_re = new RegExp(`[Aa][Ss]\\s+"shift_([0-9]+)_(${units.join('|')})"`); | ||
const shift_re = new RegExp(`[Aa][Ss]\\s+"(b|)shift_([0-9]+)_(${units.join('|')})"`); | ||
const from = /(time\s*>=?\s*)([0-9]+)(ms)/; | ||
const to = /(time\s*<=?\s*)([0-9]+)(ms)/; | ||
const from_rel = /(time\s*>=?\s*)(now\(\)\s*-\s*)([0-9]+)([usmhdw])/; | ||
|
@@ -26,7 +26,8 @@ function fix_query_time(q, reg, count, unit) { | |
const match = q.match(reg); | ||
if (match) { | ||
const time = moment(parseInt(match[2], 10)); | ||
time.subtract(count, unit); | ||
//time.subtract(count, unit); | ||
time.add(count, unit); | ||
return q.replace(reg, match[1] + time.valueOf() + match[3]); | ||
} | ||
return q; | ||
|
@@ -121,8 +122,9 @@ function forward(path, req, res) { | |
req.proxyShift = {}; | ||
} | ||
req.proxyShift[idx] = { | ||
back: (match.splice(1,1)[0] == "b"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not like this match.splice approach, it's is much better to just change all match indexes rather then manipulate match array in place |
||
count: parseInt(match[1], 10), | ||
unit: match[2] | ||
unit: match[2], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coma will brake node 6 compatibility |
||
}; | ||
deb_rewrite("<-- " + q); | ||
let select = fix_query_time(q, from, parseInt(match[1], 10), match[2]); | ||
|
@@ -168,7 +170,11 @@ function intercept(rsp, data, req, res) { | |
series: result.series.map(serie => { | ||
return Object.assign({}, serie, { values: serie.values.map(item => { | ||
const time = moment(item[0]); | ||
time.add(req.proxyShift[idx].count, req.proxyShift[idx].unit); | ||
if(req.proxyShift[idx].back) { | ||
time.subtract(req.proxyShift[idx].count, req.proxyShift[idx].unit); | ||
} else { | ||
time.add(req.proxyShift[idx].count, req.proxyShift[idx].unit); | ||
} | ||
return [ time.valueOf(), item[1]]; | ||
})}); | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Unit] | ||
Description=Add timeshift feature to influxdb for grafana users with mathematics between metrics feature | ||
Documentation=https://github.com/maxsivanov/influxdb-timeshift-proxy | ||
After=network-online.target | ||
Requires=influxdb.service | ||
|
||
[Service] | ||
User=influxdb | ||
Group=influxdb | ||
Environment=INFLUXDB=127.0.0.1:8086 | ||
EnvironmentFile=-/etc/default/influxdb-timeshift-proxy | ||
WorkingDirectory=/opt/influxdb-timeshift-proxy | ||
ExecStart=/usr/bin/npm run start | ||
|
||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
Alias=influxd.service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Why direction was changed here?