Refactor to use feature detection instead of version detection. Add logs upgrade message.

pull/2188/head
Hunter Trujillo 2017-11-21 14:46:54 -07:00
parent 9a72902fa3
commit 51e7e8fe3c
3 changed files with 22 additions and 36 deletions

View File

@ -102,27 +102,13 @@ export const updateTask = async (
}
export const getLogStream = kapacitor =>
fetch(`${kapacitor.links.proxy}?path=/kapacitor/v1/logs`, {
fetch(`${kapacitor.links.proxy}?path=/kapacitor/v1preview/logs`, {
method: 'GET',
headers: {'Content-Type': 'application/json'},
})
export const getLogStreamByRuleID = (kapacitor, ruleID) =>
fetch(`${kapacitor.links.proxy}?path=/kapacitor/v1/logs?task=${ruleID}`, {
fetch(`${kapacitor.links.proxy}?path=/kapacitor/v1preview/logs?task=${ruleID}`, {
method: 'GET',
headers: {'Content-Type': 'application/json'},
})
export const pingKapacitorVersion = async kapacitor => {
try {
const result = await AJAX({
method: 'GET',
url: `${kapacitor.links.proxy}?path=/kapacitor/v1/ping`,
})
const kapVersion = result.headers['x-kapacitor-version']
return kapVersion === '' ? null : kapVersion
} catch (error) {
console.error(error)
throw error
}
}

View File

@ -219,3 +219,5 @@ export const ALERT_NODES_ACCESSORS = {
)
.join('.'),
}
export const KAPACITOR_LOGS_NOT_FOUND = 404

View File

@ -7,7 +7,8 @@ import Tickscript from 'src/kapacitor/components/Tickscript'
import * as kapactiorActionCreators from 'src/kapacitor/actions/view'
import * as errorActionCreators from 'shared/actions/errors'
import {getActiveKapacitor} from 'src/shared/apis'
import {getLogStreamByRuleID, pingKapacitorVersion} from 'src/kapacitor/apis'
import {getLogStreamByRuleID} from 'src/kapacitor/apis'
import {KAPACITOR_LOGS_NOT_FOUND} from 'src/kapacitor/constants'
import {publishNotification} from 'shared/actions/notifications'
class TickscriptPage extends Component {
@ -39,6 +40,21 @@ class TickscriptPage extends Component {
try {
const response = await getLogStreamByRuleID(kapacitor, ruleID)
if (response.status === KAPACITOR_LOGS_NOT_FOUND) {
this.setState({
areLogsEnabled: false,
})
this.shouldFetch = false
notify('warning', 'Could not use logging, requires Kapacitor version 1.4')
return
}
else {
this.setState({
areLogsEnabled: true,
})
this.shouldFetch = true
}
const reader = await response.body.getReader()
const decoder = new TextDecoder()
@ -93,25 +109,7 @@ class TickscriptPage extends Component {
this.setState({task: {tickscript, dbrps, type, status, name, id}})
}
try {
const version = await pingKapacitorVersion(kapacitor)
// Check minor version number for Kapacitor 1.4
if (version && version.split('.')[1] === '4') {
this.shouldFetch = true
this.fetchChunkedLogs(kapacitor, ruleID)
this.setState({
areLogsEnabled: true,
})
} else {
this.setState({
areLogsEnabled: false,
})
}
} catch (err) {
console.error(err)
this.props.notify('error', err)
}
this.fetchChunkedLogs(kapacitor, ruleID)
this.setState({kapacitor})
}