Update for consolidating naming around infinite scroll
parent
37e3092b14
commit
04e72e679f
|
@ -9,10 +9,10 @@ import {
|
||||||
buildHistogramQueryConfig,
|
buildHistogramQueryConfig,
|
||||||
buildTableQueryConfig,
|
buildTableQueryConfig,
|
||||||
buildLogQuery,
|
buildLogQuery,
|
||||||
buildInfiniteLogQuery,
|
buildInfiniteScrollLogQuery,
|
||||||
parseHistogramQueryResponse,
|
parseHistogramQueryResponse,
|
||||||
findBackwardLower,
|
findOlderLowerTimeBounds,
|
||||||
findForwardUpper,
|
findNewerUpperTimeBounds,
|
||||||
} from 'src/logs/utils'
|
} from 'src/logs/utils'
|
||||||
import {logConfigServerToUI, logConfigUIToServer} from 'src/logs/utils/config'
|
import {logConfigServerToUI, logConfigUIToServer} from 'src/logs/utils/config'
|
||||||
import {getDeep} from 'src/utils/wrappers'
|
import {getDeep} from 'src/utils/wrappers'
|
||||||
|
@ -348,28 +348,28 @@ export const setTimeBounds = (timeBounds: TimeBounds): SetTimeBoundsAction => ({
|
||||||
payload: {timeBounds},
|
payload: {timeBounds},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const executeTableForwardQueryAsync = () => async (
|
export const executeTableNewerQueryAsync = () => async (
|
||||||
dispatch,
|
dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
) => {
|
) => {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
|
|
||||||
const time = getTableSelectedTime(state)
|
const startTime = getTableSelectedTime(state)
|
||||||
const queryConfig = getTableQueryConfig(state)
|
const queryConfig = getTableQueryConfig(state)
|
||||||
const namespace = getNamespace(state)
|
const namespace = getNamespace(state)
|
||||||
const proxyLink = getProxyLink(state)
|
const proxyLink = getProxyLink(state)
|
||||||
const searchTerm = getSearchTerm(state)
|
const searchTerm = getSearchTerm(state)
|
||||||
const filters = getFilters(state)
|
const filters = getFilters(state)
|
||||||
|
|
||||||
if (!_.every([queryConfig, time, namespace, proxyLink])) {
|
if (!_.every([queryConfig, startTime, namespace, proxyLink])) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dispatch(incrementQueryCount())
|
dispatch(incrementQueryCount())
|
||||||
|
|
||||||
const upper = await findForwardUpper(
|
const endTime = await findNewerUpperTimeBounds(
|
||||||
time,
|
startTime,
|
||||||
queryConfig,
|
queryConfig,
|
||||||
filters,
|
filters,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
|
@ -377,9 +377,9 @@ export const executeTableForwardQueryAsync = () => async (
|
||||||
namespace
|
namespace
|
||||||
)
|
)
|
||||||
|
|
||||||
const query: string = await buildInfiniteLogQuery(
|
const query: string = await buildInfiniteScrollLogQuery(
|
||||||
time,
|
startTime,
|
||||||
upper,
|
endTime,
|
||||||
queryConfig,
|
queryConfig,
|
||||||
filters,
|
filters,
|
||||||
searchTerm
|
searchTerm
|
||||||
|
@ -404,7 +404,7 @@ export const executeTableForwardQueryAsync = () => async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const executeTableBackwardQueryAsync = () => async (
|
export const executeTableOlderQueryAsync = () => async (
|
||||||
dispatch,
|
dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
) => {
|
) => {
|
||||||
|
@ -424,7 +424,7 @@ export const executeTableBackwardQueryAsync = () => async (
|
||||||
try {
|
try {
|
||||||
dispatch(incrementQueryCount())
|
dispatch(incrementQueryCount())
|
||||||
|
|
||||||
const lower: string = await findBackwardLower(
|
const lower: string = await findOlderLowerTimeBounds(
|
||||||
time,
|
time,
|
||||||
queryConfig,
|
queryConfig,
|
||||||
filters,
|
filters,
|
||||||
|
@ -433,7 +433,7 @@ export const executeTableBackwardQueryAsync = () => async (
|
||||||
namespace
|
namespace
|
||||||
)
|
)
|
||||||
|
|
||||||
const query: string = await buildInfiniteLogQuery(
|
const query: string = await buildInfiniteScrollLogQuery(
|
||||||
lower,
|
lower,
|
||||||
time,
|
time,
|
||||||
queryConfig,
|
queryConfig,
|
||||||
|
@ -522,8 +522,8 @@ export const executeHistogramQueryAsync = () => async (
|
||||||
|
|
||||||
export const executeTableQueryAsync = () => async (dispatch): Promise<void> => {
|
export const executeTableQueryAsync = () => async (dispatch): Promise<void> => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
dispatch(executeTableForwardQueryAsync()),
|
dispatch(executeTableNewerQueryAsync()),
|
||||||
dispatch(executeTableBackwardQueryAsync()),
|
dispatch(executeTableOlderQueryAsync()),
|
||||||
dispatch(clearRowsAdded()),
|
dispatch(clearRowsAdded()),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -628,7 +628,7 @@ export const fetchOlderLogsAsync = (queryTimeEnd: string) => async (
|
||||||
const params = [namespace, proxyLink, tableQueryConfig]
|
const params = [namespace, proxyLink, tableQueryConfig]
|
||||||
|
|
||||||
if (_.every(params)) {
|
if (_.every(params)) {
|
||||||
const lower = await findBackwardLower(
|
const queryTimeStart = await findOlderLowerTimeBounds(
|
||||||
queryTimeEnd,
|
queryTimeEnd,
|
||||||
newQueryConfig,
|
newQueryConfig,
|
||||||
filters,
|
filters,
|
||||||
|
@ -637,8 +637,8 @@ export const fetchOlderLogsAsync = (queryTimeEnd: string) => async (
|
||||||
namespace
|
namespace
|
||||||
)
|
)
|
||||||
|
|
||||||
const query = await buildInfiniteLogQuery(
|
const query = await buildInfiniteScrollLogQuery(
|
||||||
lower,
|
queryTimeStart,
|
||||||
queryTimeEnd,
|
queryTimeEnd,
|
||||||
newQueryConfig,
|
newQueryConfig,
|
||||||
filters,
|
filters,
|
||||||
|
@ -674,7 +674,7 @@ export const fetchNewerLogsAsync = (queryTimeStart: string) => async (
|
||||||
const params = [namespace, proxyLink, tableQueryConfig]
|
const params = [namespace, proxyLink, tableQueryConfig]
|
||||||
|
|
||||||
if (_.every(params)) {
|
if (_.every(params)) {
|
||||||
const upper = await findForwardUpper(
|
const queryTimeEnd = await findNewerUpperTimeBounds(
|
||||||
queryTimeStart,
|
queryTimeStart,
|
||||||
newQueryConfig,
|
newQueryConfig,
|
||||||
filters,
|
filters,
|
||||||
|
@ -683,9 +683,9 @@ export const fetchNewerLogsAsync = (queryTimeStart: string) => async (
|
||||||
namespace
|
namespace
|
||||||
)
|
)
|
||||||
|
|
||||||
const query: string = await buildInfiniteLogQuery(
|
const query: string = await buildInfiniteScrollLogQuery(
|
||||||
queryTimeStart,
|
queryTimeStart,
|
||||||
upper,
|
queryTimeEnd,
|
||||||
newQueryConfig,
|
newQueryConfig,
|
||||||
filters,
|
filters,
|
||||||
searchTerm
|
searchTerm
|
||||||
|
|
|
@ -117,7 +117,7 @@ export const filtersClause = (filters: Filter[]): string => {
|
||||||
).join(' AND ')
|
).join(' AND ')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildInfiniteWhereClause({
|
export function buildInfiniteScrollWhereClause({
|
||||||
lower,
|
lower,
|
||||||
upper,
|
upper,
|
||||||
tags,
|
tags,
|
||||||
|
@ -176,17 +176,22 @@ export function buildGeneralLogQuery(
|
||||||
return `${select}${condition}${dimensions}${fillClause}`
|
return `${select}${condition}${dimensions}${fillClause}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function queryCount(
|
export async function getQueryCountForBounds(
|
||||||
lower,
|
lower: string,
|
||||||
upper,
|
upper: string,
|
||||||
config,
|
config: QueryConfig,
|
||||||
filters,
|
filters: Filter[],
|
||||||
searchTerm,
|
searchTerm: string,
|
||||||
proxyLink,
|
proxyLink: string,
|
||||||
namespace
|
namespace: Namespace
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const {database, retentionPolicy, measurement} = config
|
const {database, retentionPolicy, measurement} = config
|
||||||
const rpSegment = retentionPolicy ? `"${retentionPolicy}"` : ''
|
|
||||||
|
let rpSegment = ''
|
||||||
|
if (retentionPolicy) {
|
||||||
|
rpSegment = `"${retentionPolicy}"`
|
||||||
|
}
|
||||||
|
|
||||||
const fullyQualifiedMeasurement = `"${database}".${rpSegment}."${measurement}"`
|
const fullyQualifiedMeasurement = `"${database}".${rpSegment}."${measurement}"`
|
||||||
const select = `SELECT count(message) FROM ${fullyQualifiedMeasurement}`
|
const select = `SELECT count(message) FROM ${fullyQualifiedMeasurement}`
|
||||||
let condition = `WHERE time >= '${lower}' AND time <='${upper}'`
|
let condition = `WHERE time >= '${lower}' AND time <='${upper}'`
|
||||||
|
@ -204,7 +209,7 @@ export async function queryCount(
|
||||||
return getDeep<number>(result, 'results.0.series.0.values.0.1', 0)
|
return getDeep<number>(result, 'results.0.series.0.values.0.1', 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findBackwardLower(
|
export async function findOlderLowerTimeBounds(
|
||||||
upper: string,
|
upper: string,
|
||||||
config: QueryConfig,
|
config: QueryConfig,
|
||||||
filters: Filter[],
|
filters: Filter[],
|
||||||
|
@ -219,11 +224,10 @@ export async function findBackwardLower(
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (secondsBack > SECONDS_AWAY_LIMIT) {
|
if (secondsBack > SECONDS_AWAY_LIMIT) {
|
||||||
// One day
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await queryCount(
|
const count = await getQueryCountForBounds(
|
||||||
currentLower.toISOString(),
|
currentLower.toISOString(),
|
||||||
upper,
|
upper,
|
||||||
config,
|
config,
|
||||||
|
@ -237,14 +241,14 @@ export async function findBackwardLower(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
secondsBack *= secondsBack
|
secondsBack *= secondsBack // exponential backoff
|
||||||
currentLower = parsedUpper.subtract(secondsBack, 'seconds')
|
currentLower = parsedUpper.subtract(secondsBack, 'seconds')
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentLower.toISOString()
|
return currentLower.toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findForwardUpper(
|
export async function findNewerUpperTimeBounds(
|
||||||
lower: string,
|
lower: string,
|
||||||
config: QueryConfig,
|
config: QueryConfig,
|
||||||
filters: Filter[],
|
filters: Filter[],
|
||||||
|
@ -262,7 +266,7 @@ export async function findForwardUpper(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await queryCount(
|
const count = await getQueryCountForBounds(
|
||||||
lower,
|
lower,
|
||||||
currentUpper.toISOString(),
|
currentUpper.toISOString(),
|
||||||
config,
|
config,
|
||||||
|
@ -276,14 +280,14 @@ export async function findForwardUpper(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
secondsForward *= secondsForward
|
secondsForward *= secondsForward // exponential backoff
|
||||||
currentUpper = parsedLower.add(secondsForward, 'seconds')
|
currentUpper = parsedLower.add(secondsForward, 'seconds')
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentUpper.toISOString()
|
return currentUpper.toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildInfiniteLogQuery(
|
export async function buildInfiniteScrollLogQuery(
|
||||||
lower: string,
|
lower: string,
|
||||||
upper: string,
|
upper: string,
|
||||||
config: QueryConfig,
|
config: QueryConfig,
|
||||||
|
@ -292,7 +296,7 @@ export async function buildInfiniteLogQuery(
|
||||||
) {
|
) {
|
||||||
const {tags, areTagsAccepted} = config
|
const {tags, areTagsAccepted} = config
|
||||||
|
|
||||||
const condition = buildInfiniteWhereClause({
|
const condition = buildInfiniteScrollWhereClause({
|
||||||
lower,
|
lower,
|
||||||
upper,
|
upper,
|
||||||
tags,
|
tags,
|
||||||
|
|
Loading…
Reference in New Issue