Change multiple to quantity in shift + misc cleanup
parent
6093ddc52f
commit
b9b40a1659
|
@ -478,7 +478,7 @@ describe('Chronograf.Reducers.DataExplorer.queryConfigs', () => {
|
|||
[queryID]: buildInitialState(queryID),
|
||||
}
|
||||
|
||||
const shift = {multiple: 1, unit: 'd', duration: '1d'}
|
||||
const shift = {quantity: 1, unit: 'd', duration: '1d'}
|
||||
const action = timeShift(queryID, shift)
|
||||
const nextState = reducer(initialState, action)
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import reducer from 'src/kapacitor/reducers/queryConfigs'
|
||||
import defaultQueryConfig from 'src/utils/defaultQueryConfig'
|
||||
import {
|
||||
chooseTag,
|
||||
timeShift,
|
||||
groupByTag,
|
||||
toggleField,
|
||||
groupByTime,
|
||||
chooseNamespace,
|
||||
chooseMeasurement,
|
||||
chooseTag,
|
||||
groupByTag,
|
||||
toggleTagAcceptance,
|
||||
toggleField,
|
||||
applyFuncsToField,
|
||||
groupByTime,
|
||||
toggleTagAcceptance,
|
||||
} from 'src/kapacitor/actions/queryConfigs'
|
||||
|
||||
const fakeAddQueryAction = (panelID, queryID) => {
|
||||
|
|
|
@ -55,7 +55,7 @@ describe('Shared.Query.Helpers', () => {
|
|||
const upper = Date.now()
|
||||
const oneMinute = 60000
|
||||
const lower = Date.now() - oneMinute
|
||||
const shift = {multiple: 7, unit: 'd'}
|
||||
const shift = {quantity: 7, unit: 'd'}
|
||||
const timeRange = {upper, lower}
|
||||
|
||||
const type = timeRangeType(timeRange)
|
||||
|
@ -71,7 +71,7 @@ describe('Shared.Query.Helpers', () => {
|
|||
})
|
||||
|
||||
it('can calculate the shift for relative lower timeRanges', () => {
|
||||
const shift = {multiple: 7, unit: 'd'}
|
||||
const shift = {quantity: 7, unit: 'd'}
|
||||
const lower = 'now() - 15m'
|
||||
const timeRange = {lower, upper: null}
|
||||
|
||||
|
@ -91,7 +91,7 @@ describe('Shared.Query.Helpers', () => {
|
|||
const upper = Date.now()
|
||||
const oneMinute = 60000
|
||||
const lower = Date.now() - oneMinute
|
||||
const shift = {multiple: 7, unit: 'd'}
|
||||
const shift = {quantity: 7, unit: 'd'}
|
||||
const timeRange = {upper, lower}
|
||||
|
||||
const type = timeRangeType(timeRange)
|
||||
|
|
|
@ -66,7 +66,7 @@ export const getRule = (kapacitor, ruleID) => async dispatch => {
|
|||
}
|
||||
}
|
||||
|
||||
export function loadDefaultRule() {
|
||||
export const loadDefaultRule = () => {
|
||||
return dispatch => {
|
||||
const queryID = uuid.v4()
|
||||
dispatch({
|
||||
|
@ -88,15 +88,13 @@ export const fetchRules = kapacitor => async dispatch => {
|
|||
}
|
||||
}
|
||||
|
||||
export function chooseTrigger(ruleID, trigger) {
|
||||
return {
|
||||
type: 'CHOOSE_TRIGGER',
|
||||
payload: {
|
||||
ruleID,
|
||||
trigger,
|
||||
},
|
||||
}
|
||||
}
|
||||
export const chooseTrigger = (ruleID, trigger) => ({
|
||||
type: 'CHOOSE_TRIGGER',
|
||||
payload: {
|
||||
ruleID,
|
||||
trigger,
|
||||
},
|
||||
})
|
||||
|
||||
export const addEvery = (ruleID, frequency) => ({
|
||||
type: 'ADD_EVERY',
|
||||
|
@ -113,36 +111,30 @@ export const removeEvery = ruleID => ({
|
|||
},
|
||||
})
|
||||
|
||||
export function updateRuleValues(ruleID, trigger, values) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_VALUES',
|
||||
payload: {
|
||||
ruleID,
|
||||
trigger,
|
||||
values,
|
||||
},
|
||||
}
|
||||
}
|
||||
export const updateRuleValues = (ruleID, trigger, values) => ({
|
||||
type: 'UPDATE_RULE_VALUES',
|
||||
payload: {
|
||||
ruleID,
|
||||
trigger,
|
||||
values,
|
||||
},
|
||||
})
|
||||
|
||||
export function updateMessage(ruleID, message) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_MESSAGE',
|
||||
payload: {
|
||||
ruleID,
|
||||
message,
|
||||
},
|
||||
}
|
||||
}
|
||||
export const updateMessage = (ruleID, message) => ({
|
||||
type: 'UPDATE_RULE_MESSAGE',
|
||||
payload: {
|
||||
ruleID,
|
||||
message,
|
||||
},
|
||||
})
|
||||
|
||||
export function updateDetails(ruleID, details) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_DETAILS',
|
||||
payload: {
|
||||
ruleID,
|
||||
details,
|
||||
},
|
||||
}
|
||||
}
|
||||
export const updateDetails = (ruleID, details) => ({
|
||||
type: 'UPDATE_RULE_DETAILS',
|
||||
payload: {
|
||||
ruleID,
|
||||
details,
|
||||
},
|
||||
})
|
||||
|
||||
export const updateAlertProperty = (ruleID, alertNodeName, alertProperty) => ({
|
||||
type: 'UPDATE_RULE_ALERT_PROPERTY',
|
||||
|
@ -153,87 +145,73 @@ export const updateAlertProperty = (ruleID, alertNodeName, alertProperty) => ({
|
|||
},
|
||||
})
|
||||
|
||||
export function updateAlerts(ruleID, alerts) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_ALERTS',
|
||||
payload: {
|
||||
ruleID,
|
||||
alerts,
|
||||
},
|
||||
}
|
||||
export const updateAlerts = (ruleID, alerts) => ({
|
||||
type: 'UPDATE_RULE_ALERTS',
|
||||
payload: {
|
||||
ruleID,
|
||||
alerts,
|
||||
},
|
||||
})
|
||||
|
||||
export const updateAlertNodes = (ruleID, alertNodeName, alertNodesText) => ({
|
||||
type: 'UPDATE_RULE_ALERT_NODES',
|
||||
payload: {
|
||||
ruleID,
|
||||
alertNodeName,
|
||||
alertNodesText,
|
||||
},
|
||||
})
|
||||
|
||||
export const updateRuleName = (ruleID, name) => ({
|
||||
type: 'UPDATE_RULE_NAME',
|
||||
payload: {
|
||||
ruleID,
|
||||
name,
|
||||
},
|
||||
})
|
||||
|
||||
export const deleteRuleSuccess = ruleID => ({
|
||||
type: 'DELETE_RULE_SUCCESS',
|
||||
payload: {
|
||||
ruleID,
|
||||
},
|
||||
})
|
||||
|
||||
export const updateRuleStatusSuccess = (ruleID, status) => ({
|
||||
type: 'UPDATE_RULE_STATUS_SUCCESS',
|
||||
payload: {
|
||||
ruleID,
|
||||
status,
|
||||
},
|
||||
})
|
||||
|
||||
export const deleteRule = rule => dispatch => {
|
||||
deleteRuleAPI(rule)
|
||||
.then(() => {
|
||||
dispatch(deleteRuleSuccess(rule.id))
|
||||
dispatch(
|
||||
publishNotification('success', `${rule.name} deleted successfully`)
|
||||
)
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch(
|
||||
publishNotification('error', `${rule.name} could not be deleted`)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function updateAlertNodes(ruleID, alertNodeName, alertNodesText) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_ALERT_NODES',
|
||||
payload: {
|
||||
ruleID,
|
||||
alertNodeName,
|
||||
alertNodesText,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function updateRuleName(ruleID, name) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_NAME',
|
||||
payload: {
|
||||
ruleID,
|
||||
name,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteRuleSuccess(ruleID) {
|
||||
return {
|
||||
type: 'DELETE_RULE_SUCCESS',
|
||||
payload: {
|
||||
ruleID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function updateRuleStatusSuccess(ruleID, status) {
|
||||
return {
|
||||
type: 'UPDATE_RULE_STATUS_SUCCESS',
|
||||
payload: {
|
||||
ruleID,
|
||||
status,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteRule(rule) {
|
||||
return dispatch => {
|
||||
deleteRuleAPI(rule)
|
||||
.then(() => {
|
||||
dispatch(deleteRuleSuccess(rule.id))
|
||||
dispatch(
|
||||
publishNotification('success', `${rule.name} deleted successfully`)
|
||||
)
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch(
|
||||
publishNotification('error', `${rule.name} could not be deleted`)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function updateRuleStatus(rule, status) {
|
||||
return dispatch => {
|
||||
updateRuleStatusAPI(rule, status)
|
||||
.then(() => {
|
||||
dispatch(
|
||||
publishNotification('success', `${rule.name} ${status} successfully`)
|
||||
)
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch(
|
||||
publishNotification('error', `${rule.name} could not be ${status}`)
|
||||
)
|
||||
})
|
||||
}
|
||||
export const updateRuleStatus = (rule, status) => dispatch => {
|
||||
updateRuleStatusAPI(rule, status)
|
||||
.then(() => {
|
||||
dispatch(
|
||||
publishNotification('success', `${rule.name} ${status} successfully`)
|
||||
)
|
||||
})
|
||||
.catch(() => {
|
||||
dispatch(
|
||||
publishNotification('error', `${rule.name} could not be ${status}`)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export const createTask = (
|
||||
|
|
|
@ -61,13 +61,13 @@ class KapacitorRulePage extends Component {
|
|||
render() {
|
||||
const {
|
||||
rules,
|
||||
queryConfigs,
|
||||
params,
|
||||
ruleActions,
|
||||
source,
|
||||
queryConfigActions,
|
||||
addFlashMessage,
|
||||
router,
|
||||
ruleActions,
|
||||
queryConfigs,
|
||||
addFlashMessage,
|
||||
queryConfigActions,
|
||||
} = this.props
|
||||
const {enabledAlerts, kapacitor} = this.state
|
||||
const rule = this.isEditing()
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import defaultQueryConfig from 'src/utils/defaultQueryConfig'
|
||||
import {
|
||||
applyFuncsToField,
|
||||
chooseMeasurement,
|
||||
chooseNamespace,
|
||||
timeShift,
|
||||
chooseTag,
|
||||
groupByTag,
|
||||
groupByTime,
|
||||
removeFuncs,
|
||||
chooseNamespace,
|
||||
toggleKapaField,
|
||||
applyFuncsToField,
|
||||
chooseMeasurement,
|
||||
toggleTagAcceptance,
|
||||
} from 'src/utils/queryTransitions'
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class FieldList extends Component {
|
|||
|
||||
render() {
|
||||
const {
|
||||
query: {database, measurement, fields = [], groupBy, fill, shift},
|
||||
query: {database, measurement, fields = [], groupBy, fill, shifts},
|
||||
isKapacitorRule,
|
||||
} = this.props
|
||||
|
||||
|
@ -146,7 +146,7 @@ class FieldList extends Component {
|
|||
{hasAggregates
|
||||
? <QueryOptions
|
||||
fill={fill}
|
||||
shift={_.first(shift)}
|
||||
shift={_.first(shifts)}
|
||||
groupBy={groupBy}
|
||||
onFill={this.handleFill}
|
||||
isKapacitorRule={isKapacitorRule}
|
||||
|
@ -193,7 +193,7 @@ class FieldList extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
const {arrayOf, bool, func, number, shape, string} = PropTypes
|
||||
const {arrayOf, bool, func, shape, string} = PropTypes
|
||||
|
||||
FieldList.defaultProps = {
|
||||
isKapacitorRule: false,
|
||||
|
@ -213,11 +213,11 @@ FieldList.propTypes = {
|
|||
database: string,
|
||||
retentionPolicy: string,
|
||||
measurement: string,
|
||||
shift: arrayOf(
|
||||
shifts: arrayOf(
|
||||
shape({
|
||||
label: string,
|
||||
unit: string,
|
||||
multiple: number,
|
||||
quantity: string,
|
||||
})
|
||||
),
|
||||
}).isRequired,
|
||||
|
|
|
@ -33,7 +33,7 @@ QueryOptions.propTypes = {
|
|||
time: string,
|
||||
}).isRequired,
|
||||
shift: shape({
|
||||
duration: string,
|
||||
label: string,
|
||||
}),
|
||||
onGroupByTime: func.isRequired,
|
||||
isKapacitorRule: bool.isRequired,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
export const TIME_SHIFTS = [
|
||||
{label: 'none', text: 'none', multiple: 0, unit: null},
|
||||
{label: '1m', text: '1m', multiple: 1, unit: 'm'},
|
||||
{label: '1h', text: '1h', multiple: 1, unit: 'h'},
|
||||
{label: '12h', text: '12h', multiple: 12, unit: 'h'},
|
||||
{label: '1d', text: '1d', multiple: 1, unit: 'd'},
|
||||
{label: '7d', text: '7d', multiple: 7, unit: 'd'},
|
||||
{label: '30d', text: '30d', multiple: 30, unit: 'd'},
|
||||
{label: '365d', text: '365d', multiple: 365, unit: 'd'},
|
||||
{label: 'none', text: 'none', quantity: null, unit: null},
|
||||
{label: '1m', text: '1m', quantity: '1', unit: 'm'},
|
||||
{label: '1h', text: '1h', quantity: '1', unit: 'h'},
|
||||
{label: '12h', text: '12h', quantity: '12', unit: 'h'},
|
||||
{label: '1d', text: '1d', quantity: '1', unit: 'd'},
|
||||
{label: '7d', text: '7d', quantity: '7', unit: 'd'},
|
||||
{label: '30d', text: '30d', quantity: '30', unit: 'd'},
|
||||
{label: '365d', text: '365d', quantity: '365', unit: 'd'},
|
||||
]
|
||||
|
|
|
@ -40,9 +40,9 @@ export const timeRangeType = ({upper, lower, type}) => {
|
|||
|
||||
export const shiftTimeRange = (timeRange, shift) => {
|
||||
const {upper, lower} = timeRange
|
||||
const {multiple, unit} = shift
|
||||
const {quantity, unit} = shift
|
||||
const trType = timeRangeType(timeRange)
|
||||
const duration = `${multiple}${unit}`
|
||||
const duration = `${quantity}${unit}`
|
||||
const type = 'shifted'
|
||||
|
||||
switch (trType) {
|
||||
|
@ -101,10 +101,10 @@ const getMomentUnit = unit => {
|
|||
}
|
||||
}
|
||||
|
||||
export const shiftDate = (date, multiple, unit) => {
|
||||
if (!date && !multiple && !unit) {
|
||||
export const shiftDate = (date, quantity, unit) => {
|
||||
if (!date && !quantity && !unit) {
|
||||
return moment(date)
|
||||
}
|
||||
|
||||
return moment(date).add(multiple, getMomentUnit(unit))
|
||||
return moment(date).add(quantity, getMomentUnit(unit))
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ import {TYPE_QUERY_CONFIG, TYPE_SHIFTED} from 'src/dashboards/constants'
|
|||
|
||||
const buildQueries = (proxy, queryConfigs, tR) => {
|
||||
const statements = queryConfigs.map(query => {
|
||||
const {rawText, range, id, shift, database, measurement, fields} = query
|
||||
const {rawText, range, id, shifts, database, measurement, fields} = query
|
||||
const timeRange = range || tR
|
||||
const text = rawText || buildQuery(TYPE_QUERY_CONFIG, timeRange, query)
|
||||
const isParsable = database && measurement && fields.length
|
||||
|
||||
if (shift && shift.length && isParsable) {
|
||||
const shiftedQueries = shift
|
||||
if (shifts && shifts.length && isParsable) {
|
||||
const shiftedQueries = shifts
|
||||
.filter(s => s.unit)
|
||||
.map(s => buildQuery(TYPE_SHIFTED, timeRange, query, s))
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ const defaultQueryConfig = ({id, isKapacitorRule = false}) => {
|
|||
areTagsAccepted: true,
|
||||
rawText: null,
|
||||
status: null,
|
||||
shift: [],
|
||||
shifts: [],
|
||||
}
|
||||
|
||||
return isKapacitorRule ? queryConfig : {...queryConfig, fill: NULL_STRING}
|
||||
|
|
|
@ -60,11 +60,11 @@ export const buildQuery = (type, timeRange, config, shift) => {
|
|||
}
|
||||
|
||||
case TYPE_SHIFTED: {
|
||||
const {multiple, unit} = shift
|
||||
const {quantity, unit} = shift
|
||||
return buildInfluxQLQuery(
|
||||
shiftTimeRange(timeRange, shift),
|
||||
config,
|
||||
`_shifted__${multiple}__${unit}`
|
||||
`_shifted__${quantity}__${unit}`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -243,4 +243,4 @@ export const chooseTag = (query, tag) => {
|
|||
return updateTagValues(query.tags[tag.key].concat(tag.value))
|
||||
}
|
||||
|
||||
export const timeShift = (query, shift) => ({...query, shift: [shift]})
|
||||
export const timeShift = (query, shift) => ({...query, shifts: [shift]})
|
||||
|
|
|
@ -117,8 +117,8 @@ export default function timeSeriesToDygraph(raw = [], isInDataExplorer) {
|
|||
const seriesIndex = cells.seriesIndex[i]
|
||||
|
||||
if (label.includes('_shifted__')) {
|
||||
const [, multiple, duration] = label.split('__')
|
||||
time = +shiftDate(time, multiple, duration).format('x')
|
||||
const [, quantity, duration] = label.split('__')
|
||||
time = +shiftDate(time, quantity, duration).format('x')
|
||||
}
|
||||
|
||||
let existingRowIndex = tsMemo[time]
|
||||
|
|
Loading…
Reference in New Issue