Move telegraf configs api to client library
parent
d4ce72d33a
commit
1aa5c471ee
|
@ -829,9 +829,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"@influxdata/influx": {
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.5.tgz",
|
||||
"integrity": "sha512-fU9kcNCjPv1fY7CzLcNgPmh2iV1I56pN5H5v9aqDA5jEgw2mf4vQM9rPi1TAhk1xZw/CdsYKatI9hAbh7BbWKw==",
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.6.tgz",
|
||||
"integrity": "sha512-741E/MphkxvZF5DJqnQLBMkbmtqb5ghJadHoCUIEUZwfgjuy5+N8nOcJk0Nfb5E+FlblkDqsz4T/511yiIrE5Q==",
|
||||
"requires": {
|
||||
"axios": "^0.18.0"
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
"typescript": "^3.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@influxdata/influx": "^0.1.5",
|
||||
"@influxdata/influx": "^0.1.6",
|
||||
"axios": "^0.18.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"bignumber.js": "^4.0.2",
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
import _ from 'lodash'
|
||||
|
||||
// Apis
|
||||
import {
|
||||
createTelegrafConfig,
|
||||
updateTelegrafConfig,
|
||||
getTelegrafConfig,
|
||||
} from 'src/onboarding/apis/index'
|
||||
import {client} from 'src/utils/api'
|
||||
import {ScraperTargetRequest} from 'src/api'
|
||||
|
||||
|
@ -310,23 +305,23 @@ export const createOrUpdateTelegrafConfigAsync = (authToken: string) => async (
|
|||
},
|
||||
}
|
||||
|
||||
let plugins: Plugin[] = [influxDB2Out]
|
||||
telegrafPlugins.forEach(tp => {
|
||||
if (tp.configured === ConfigurationState.Configured) {
|
||||
plugins = [...plugins, tp.plugin || createNewPlugin(tp.name)]
|
||||
}
|
||||
})
|
||||
const plugins = telegrafPlugins.reduce(
|
||||
(acc, tp) => {
|
||||
if (tp.configured === ConfigurationState.Configured) {
|
||||
return [...acc, tp.plugin || createNewPlugin(tp.name)]
|
||||
}
|
||||
|
||||
return acc
|
||||
},
|
||||
[influxDB2Out]
|
||||
)
|
||||
|
||||
if (telegrafConfigID) {
|
||||
const telegrafConfig = await getTelegrafConfig(telegrafConfigID)
|
||||
const id = _.get(telegrafConfig, 'id', '')
|
||||
|
||||
await updateTelegrafConfig(id, {
|
||||
...telegrafConfig,
|
||||
await client.telegrafConfigs.update(telegrafConfigID, {
|
||||
name: telegrafConfigName,
|
||||
plugins,
|
||||
})
|
||||
dispatch(setTelegrafConfigID(id))
|
||||
dispatch(setTelegrafConfigID(telegrafConfigID))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -337,7 +332,7 @@ export const createOrUpdateTelegrafConfigAsync = (authToken: string) => async (
|
|||
plugins,
|
||||
}
|
||||
|
||||
const created = await createTelegrafConfig(telegrafRequest)
|
||||
const created = await client.telegrafConfigs.create(telegrafRequest)
|
||||
dispatch(setTelegrafConfigID(created.id))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
import _ from 'lodash'
|
||||
|
||||
// Utils
|
||||
import {telegrafsAPI, setupAPI, sourcesAPI} from 'src/utils/api'
|
||||
import {setupAPI, sourcesAPI} from 'src/utils/api'
|
||||
|
||||
import {Telegraf, TelegrafRequest, OnboardingResponse} from 'src/api'
|
||||
|
||||
import {getDeep} from 'src/utils/wrappers'
|
||||
import {OnboardingResponse} from 'src/api'
|
||||
|
||||
export const getSetupStatus = async (): Promise<boolean> => {
|
||||
try {
|
||||
|
@ -19,23 +17,6 @@ export const getSetupStatus = async (): Promise<boolean> => {
|
|||
}
|
||||
}
|
||||
|
||||
export const getTelegrafConfigTOML = async (
|
||||
telegrafID: string
|
||||
): Promise<string> => {
|
||||
const options = {
|
||||
headers: {
|
||||
Accept: 'application/toml',
|
||||
},
|
||||
}
|
||||
|
||||
const response = await telegrafsAPI.telegrafsTelegrafIDGet(
|
||||
telegrafID,
|
||||
options
|
||||
)
|
||||
|
||||
return response.data as string // response.data is string with 'application/toml' header
|
||||
}
|
||||
|
||||
export interface SetupParams {
|
||||
username: string
|
||||
password: string
|
||||
|
@ -64,53 +45,3 @@ export const trySources = async (): Promise<boolean> => {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const getTelegrafConfig = async (
|
||||
telegrafConfigID
|
||||
): Promise<Telegraf> => {
|
||||
try {
|
||||
const response = await telegrafsAPI.telegrafsTelegrafIDGet(telegrafConfigID)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const getTelegrafConfigs = async (org: string): Promise<Telegraf[]> => {
|
||||
try {
|
||||
const data = await telegrafsAPI.telegrafsGet(org)
|
||||
|
||||
return getDeep<Telegraf[]>(data, 'data.configurations', [])
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const createTelegrafConfig = async (
|
||||
telegrafConfig: TelegrafRequest
|
||||
): Promise<Telegraf> => {
|
||||
try {
|
||||
const {data} = await telegrafsAPI.telegrafsPost(telegrafConfig)
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const updateTelegrafConfig = async (
|
||||
telegrafID: string,
|
||||
telegrafConfig: TelegrafRequest
|
||||
): Promise<Telegraf> => {
|
||||
try {
|
||||
const {data} = await telegrafsAPI.telegrafsTelegrafIDPut(
|
||||
telegrafID,
|
||||
telegrafConfig
|
||||
)
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import {
|
|||
setSetupParamsResponse,
|
||||
} from 'mocks/dummyData'
|
||||
|
||||
const telegrafsGet = jest.fn(() => Promise.resolve(getTelegrafConfigsResponse))
|
||||
const telegrafsGet = jest.fn(() =>
|
||||
Promise.resolve(getTelegrafConfigsResponse.data)
|
||||
)
|
||||
const telegrafsPost = jest.fn(() =>
|
||||
Promise.resolve(createTelegrafConfigResponse)
|
||||
Promise.resolve(createTelegrafConfigResponse.data)
|
||||
)
|
||||
const telegrafsTelegrafIDPut = jest.fn(() =>
|
||||
Promise.resolve(createTelegrafConfigResponse)
|
||||
Promise.resolve(createTelegrafConfigResponse.data)
|
||||
)
|
||||
const setupPost = jest.fn(() => Promise.resolve(setSetupParamsResponse))
|
||||
const setupGet = jest.fn(() => Promise.resolve({data: {allowed: true}}))
|
||||
|
@ -20,6 +22,14 @@ export const telegrafsAPI = {
|
|||
telegrafsTelegrafIDPut,
|
||||
}
|
||||
|
||||
export const client = {
|
||||
telegrafConfigs: {
|
||||
getAll: telegrafsGet,
|
||||
getAllByOrg: telegrafsGet,
|
||||
create: telegrafsPost,
|
||||
},
|
||||
}
|
||||
|
||||
export const setupAPI = {
|
||||
setupPost,
|
||||
setupGet,
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
import {
|
||||
getSetupStatus,
|
||||
setSetupParams,
|
||||
SetupParams,
|
||||
getTelegrafConfigs,
|
||||
createTelegrafConfig,
|
||||
} from 'src/onboarding/apis'
|
||||
import {getSetupStatus, setSetupParams, SetupParams} from 'src/onboarding/apis'
|
||||
|
||||
import {telegrafConfig} from 'mocks/dummyData'
|
||||
import {telegrafsAPI, setupAPI} from 'src/onboarding/apis/mocks'
|
||||
import {setupAPI} from 'src/onboarding/apis/mocks'
|
||||
|
||||
jest.mock('src/utils/api', () => require('src/onboarding/apis/mocks'))
|
||||
|
||||
|
@ -35,22 +28,4 @@ describe('Onboarding.Apis', () => {
|
|||
expect(setupAPI.setupPost).toHaveBeenCalledWith(setupParams)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTelegrafConfigs', () => {
|
||||
it('should return an array of configs', async () => {
|
||||
const org = 'default'
|
||||
const result = await getTelegrafConfigs(org)
|
||||
|
||||
expect(result).toEqual([telegrafConfig])
|
||||
expect(telegrafsAPI.telegrafsGet).toBeCalledWith(org)
|
||||
})
|
||||
})
|
||||
|
||||
describe('createTelegrafConfig', () => {
|
||||
it('should return the newly created config', async () => {
|
||||
const result = await createTelegrafConfig(telegrafConfig)
|
||||
|
||||
expect(result).toEqual(telegrafConfig)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
// Libraries
|
||||
import _ from 'lodash'
|
||||
|
||||
// Utils
|
||||
import {getDeep} from 'src/utils/wrappers'
|
||||
|
||||
import {dashboardsAPI, telegrafsAPI} from 'src/utils/api'
|
||||
import {dashboardsAPI} from 'src/utils/api'
|
||||
|
||||
// Types
|
||||
import {Organization, Telegraf} from 'src/api'
|
||||
import {Organization} from 'src/api'
|
||||
import {Dashboard} from 'src/types/v2'
|
||||
|
||||
// CRUD APIs for Organizations and Organization resources
|
||||
|
@ -32,42 +29,3 @@ export const getDashboards = async (
|
|||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const getCollectors = async (org: Organization): Promise<Telegraf[]> => {
|
||||
try {
|
||||
const data = await telegrafsAPI.telegrafsGet(org.id)
|
||||
|
||||
return getDeep<Telegraf[]>(data, 'data.configurations', [])
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const getTelegrafConfigTOML = async (
|
||||
telegrafID: string
|
||||
): Promise<string> => {
|
||||
const options = {
|
||||
headers: {
|
||||
Accept: 'application/toml',
|
||||
},
|
||||
}
|
||||
|
||||
const response = await telegrafsAPI.telegrafsTelegrafIDGet(
|
||||
telegrafID,
|
||||
options
|
||||
)
|
||||
|
||||
return response.data as string // response.data is string with 'application/toml' header
|
||||
}
|
||||
|
||||
export const deleteTelegrafConfig = async (
|
||||
telegrafID: string
|
||||
): Promise<Telegraf> => {
|
||||
try {
|
||||
const response = await telegrafsAPI.telegrafsTelegrafIDDelete(telegrafID)
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,7 @@ import DataLoadersWizard from 'src/dataLoaders/components/DataLoadersWizard'
|
|||
import FilterList from 'src/shared/components/Filter'
|
||||
|
||||
// APIS
|
||||
import {
|
||||
getTelegrafConfigTOML,
|
||||
deleteTelegrafConfig,
|
||||
} from 'src/organizations/apis/index'
|
||||
import {client} from 'src/utils/api'
|
||||
|
||||
// Actions
|
||||
import * as NotificationsActions from 'src/types/actions/notifications'
|
||||
|
@ -178,14 +175,14 @@ export default class Collectors extends PureComponent<Props, State> {
|
|||
telegrafName: string
|
||||
) => {
|
||||
try {
|
||||
const config = await getTelegrafConfigTOML(telegrafID)
|
||||
const config = await client.telegrafConfigs.getTOML(telegrafID)
|
||||
downloadTextFile(config, `${telegrafName || 'config'}.toml`)
|
||||
} catch (error) {
|
||||
notify(getTelegrafConfigFailed())
|
||||
}
|
||||
}
|
||||
private handleDeleteTelegraf = async (telegrafID: string) => {
|
||||
await deleteTelegrafConfig(telegrafID)
|
||||
await client.telegrafConfigs.delete(telegrafID)
|
||||
this.props.onChange()
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ export default class Scrapers extends PureComponent<Props, State> {
|
|||
}
|
||||
|
||||
private handleDeleteScraper = async (scraper: ScraperTargetResponse) => {
|
||||
await client.scrapers.deleteScraper(scraper.id)
|
||||
await client.scrapers.delete(scraper.id)
|
||||
this.props.onChange()
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,13 @@ import {connect} from 'react-redux'
|
|||
import _ from 'lodash'
|
||||
|
||||
// APIs
|
||||
import {getDashboards, getCollectors} from 'src/organizations/apis'
|
||||
import {getDashboards} from 'src/organizations/apis'
|
||||
import {client} from 'src/utils/api'
|
||||
|
||||
const getCollectors = async (org: Organization) => {
|
||||
return client.telegrafConfigs.getAllByOrg(org)
|
||||
}
|
||||
|
||||
const getScrapers = async () => {
|
||||
return await client.scrapers.getAll()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
DashboardsApi,
|
||||
CellsApi,
|
||||
TelegrafsApi,
|
||||
ViewsApi,
|
||||
SourcesApi,
|
||||
QueryApi,
|
||||
|
@ -18,7 +17,6 @@ export const client = new Client(basePath)
|
|||
export const viewsAPI = new ViewsApi({basePath})
|
||||
export const dashboardsAPI = new DashboardsApi({basePath})
|
||||
export const cellsAPI = new CellsApi({basePath})
|
||||
export const telegrafsAPI = new TelegrafsApi({basePath})
|
||||
export const sourcesAPI = new SourcesApi({basePath})
|
||||
export const queryAPI = new QueryApi({basePath})
|
||||
export const setupAPI = new SetupApi({basePath})
|
||||
|
|
Loading…
Reference in New Issue