/usr/share/grafana/public/app/plugins/datasource/loki
// every timestamp in this file is a number which contains an unix-timestamp-in-millisecond format, // like returned by `new Date().getTime()`. this is needed because the "math" // has to be done on integer numbers. // the way loki handles logs-range-queries is that if you specify start & end, // one of those will be included, but the other will not. this allows us to // make it easy to split ranges. // for example, if the time-range is 100<>150, // we can split it into: // - 100<>120 // - 120<>140 // - 140<>150 // and no log-line will be skipped or duplicated // (NOTE: we do these calculations in milliseconds. at the end, Loki receives // nanoseconds, but it will be OK, because it's simply a matter to adding `000000`, // to the end, so if we do it right in milliseconds, it should be OK in // nanoseconds too export function splitTimeRange( startTime: number, endTime: number, idealRangeDuration: number ): Array<[number, number]> { if (endTime - startTime <= idealRangeDuration) { return [[startTime, endTime]]; } const result: Array<[number, number]> = []; // we walk backward, because we need want the potentially smaller "last" chunk // to be at the oldest timestamp. for (let chunkEndTime = endTime; chunkEndTime > startTime; chunkEndTime -= idealRangeDuration) { // when we get close to the start of the time range, we need to be sure not // to cross over the startTime const chunkStartTime = Math.max(chunkEndTime - idealRangeDuration, startTime); result.push([chunkStartTime, chunkEndTime]); } // because we walked backwards, we need to reverse the array result.reverse(); return result; }
.
Edit
..
Edit
CHANGELOG.md
Edit
LanguageProvider.test.ts
Edit
LanguageProvider.ts
Edit
LiveStreams.test.ts
Edit
LiveStreams.ts
Edit
LogContextProvider.test.ts
Edit
LogContextProvider.ts
Edit
LokiVariableSupport.test.ts
Edit
LokiVariableSupport.ts
Edit
README.md
Edit
backendResultTransformer.test.ts
Edit
backendResultTransformer.ts
Edit
components
Edit
configuration
Edit
dataquery.cue
Edit
dataquery.gen.ts
Edit
datasource.test.ts
Edit
datasource.ts
Edit
dist
Edit
docs
Edit
getDerivedFields.test.ts
Edit
getDerivedFields.ts
Edit
img
Edit
jest-setup.js
Edit
jest.config.js
Edit
languageUtils.test.ts
Edit
languageUtils.ts
Edit
language_utils.test.ts
Edit
lineParser.test.ts
Edit
lineParser.ts
Edit
liveStreamsResultTransformer.test.ts
Edit
liveStreamsResultTransformer.ts
Edit
logsTimeSplitting.test.ts
Edit
logsTimeSplitting.ts
Edit
makeTableFrames.test.ts
Edit
makeTableFrames.ts
Edit
mergeResponses.test.ts
Edit
mergeResponses.ts
Edit
metricTimeSplitting.test.ts
Edit
metricTimeSplitting.ts
Edit
migrations
Edit
mocks
Edit
modifyQuery.test.ts
Edit
modifyQuery.ts
Edit
module.test.ts
Edit
module.ts
Edit
package.json
Edit
plugin.json
Edit
project.json
Edit
queryHints.test.ts
Edit
queryHints.ts
Edit
querySplitting.test.ts
Edit
querySplitting.ts
Edit
queryUtils.test.ts
Edit
queryUtils.ts
Edit
querybuilder
Edit
responseUtils.test.ts
Edit
responseUtils.ts
Edit
shardQuerySplitting.test.ts
Edit
shardQuerySplitting.ts
Edit
sortDataFrame.test.ts
Edit
sortDataFrame.ts
Edit
streaming.test.ts
Edit
streaming.ts
Edit
syntax.test.ts
Edit
syntax.ts
Edit
tracking.test.ts
Edit
tracking.ts
Edit
tsconfig.json
Edit
types.ts
Edit
webpack.config.ts
Edit