Skip to content

Commit

Permalink
chore: Remove @influxdata/influx dependency (#3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalem1 authored Dec 28, 2021
1 parent 17eb3d3 commit a2bd1f3
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 75 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
"@influxdata/clockface": "^3.1.8",
"@influxdata/flux-lsp-browser": "^0.8.0",
"@influxdata/giraffe": "^2.20.3",
"@influxdata/influx": "0.5.5",
"@influxdata/influxdb-templates": "0.9.0",
"@influxdata/react-custom-scrollbars": "4.3.8",
"abortcontroller-polyfill": "^1.3.0",
Expand Down
41 changes: 29 additions & 12 deletions src/dataLoaders/actions/dataLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {get} from 'lodash'
import {normalize} from 'normalizr'

// APIs
import {client} from 'src/utils/api'
import {ScraperTargetRequest} from '@influxdata/influx'
import {createAuthorization} from 'src/authorizations/apis'

// Schemas
Expand Down Expand Up @@ -42,7 +40,6 @@ import {
TelegrafEntities,
Telegraf,
} from 'src/types'
import {TelegrafRequest} from '@influxdata/influx'
import {Dispatch} from 'redux'

// Actions
Expand All @@ -55,6 +52,15 @@ import {
TokenCreationError,
} from 'src/shared/copy/notifications'
import {postTelegraf, putTelegraf} from 'src/client'
import {CLOUD} from 'src/shared/constants'

let postScraper
let patchScraper

if (!CLOUD) {
postScraper = require('src/client').postScraper
patchScraper = require('src/client').patchScraper
}

const DEFAULT_COLLECTION_INTERVAL = 10000

Expand Down Expand Up @@ -520,7 +526,7 @@ const createTelegraf = async (dispatch, getState: GetState, plugins) => {
bucketName = bucket
const org = getOrg(getState())

const telegrafRequest: TelegrafRequest = {
const telegrafRequest = {
name: telegrafConfigName,
description: telegrafConfigDescription,
agent: {collectionInterval: DEFAULT_COLLECTION_INTERVAL},
Expand Down Expand Up @@ -637,16 +643,27 @@ export const saveScraperTarget = () => async (

try {
if (id) {
await client.scrapers.update(id, {url, bucketID})
await patchScraper({
scraperTargetID: id,
data: {url, bucketID},
})
} else {
const newTarget = await client.scrapers.create({
name,
type: ScraperTargetRequest.TypeEnum.Prometheus,
url,
bucketID,
orgID,
const resp = await postScraper({
data: {
name,
type: 'prometheus',
url,
bucketID,
orgID,
},
})
dispatch(setScraperTargetID(newTarget.id))

if (resp.status !== 201) {
throw new Error(resp.data.message)
}

const scraper = resp.data
dispatch(setScraperTargetID(scraper.id))
}
} catch (error) {
console.error()
Expand Down
23 changes: 15 additions & 8 deletions src/onboarding/components/CompletionStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {ossMetricsTemplate} from 'src/templates/constants/defaultTemplates'

// APIs
import {getDashboards} from 'src/organizations/apis'
import {client} from 'src/utils/api'
import {createDashboardFromTemplate as createDashboardFromTemplateAJAX} from 'src/templates/api'

// Types
Expand All @@ -31,9 +30,15 @@ import {
DapperScrollbars,
} from '@influxdata/clockface'
import {Dashboard} from 'src/types'
import {ScraperTargetRequest} from '@influxdata/influx'
import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard'
import {QUICKSTART_SCRAPER_TARGET_URL} from 'src/dataLoaders/constants/pluginConfigs'
import {CLOUD} from 'src/shared/constants'

let postScraper

if (!CLOUD) {
postScraper = require('src/client').postScraper
}

interface Props extends OnboardingStepProps {
orgID: string
Expand Down Expand Up @@ -134,12 +139,14 @@ class CompletionStep extends PureComponent<Props> {

private handleQuickStart = async () => {
try {
await client.scrapers.create({
name: 'new target',
type: ScraperTargetRequest.TypeEnum.Prometheus,
url: QUICKSTART_SCRAPER_TARGET_URL,
bucketID: this.props.bucketID,
orgID: this.props.orgID,
await postScraper({
data: {
name: 'new target',
type: 'prometheus',
url: QUICKSTART_SCRAPER_TARGET_URL,
bucketID: this.props.bucketID,
orgID: this.props.orgID,
},
})
this.props.notify(QuickstartScraperCreationSuccess)
} catch (err) {
Expand Down
53 changes: 42 additions & 11 deletions src/scrapers/actions/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Libraries
import {normalize} from 'normalizr'

// API
import {client} from 'src/utils/api'

// Schemas
import {arrayOfScrapers, scraperSchema} from 'src/schemas'

Expand Down Expand Up @@ -39,6 +36,19 @@ import {
// Selectors
import {getOrg} from 'src/organizations/selectors'
import {getStatus} from 'src/resources/selectors'
import {CLOUD} from 'src/shared/constants'

let getScrapersApi
let deleteScraperApi
let postScraper
let patchScraper

if (!CLOUD) {
getScrapersApi = require('src/client').getScrapers
deleteScraperApi = require('src/client').deleteScraper
postScraper = require('src/client').postScraper
patchScraper = require('src/client').patchScraper
}

type Action = ScraperAction | NotifyAction

Expand All @@ -57,13 +67,17 @@ export const getScrapers = () => async (

dispatch(setScrapers(RemoteDataState.Loading))

const resp = await client.scrapers.getAll(org.id)
const resp = await getScrapersApi({query: {orgID: org.id}})
if (resp.status !== 200) {
throw new Error(resp.data.message)
}

const scrapers = resp.data.configurations

const normalized = normalize<Scraper, ScraperEntities, string[]>(
resp,
scrapers,
arrayOfScrapers
)

dispatch(setScrapers(RemoteDataState.Done, normalized))
} catch (error) {
console.error(error)
Expand All @@ -75,10 +89,18 @@ export const createScraper = (scraper: Scraper) => async (
dispatch: Dispatch<Action>
) => {
try {
const resp = await client.scrapers.create(scraper)
const resp = await postScraper({
data: scraper,
})

if (resp.status !== 201) {
throw new Error(resp.data.message)
}

const {data} = resp

const normalized = normalize<Scraper, ScraperEntities, string>(
resp,
data,
scraperSchema
)

Expand All @@ -94,9 +116,18 @@ export const updateScraper = (scraper: Scraper) => async (
dispatch: Dispatch<Action>
) => {
try {
const resp = await client.scrapers.update(scraper.id, scraper)
const resp = await patchScraper({
scraperTargetID: scraper.id,
data: scraper,
})

if (resp.status !== 200) {
throw new Error(resp.data.message)
}

const {data} = resp
const normalized = normalize<Scraper, ScraperEntities, string>(
resp,
data,
scraperSchema
)

Expand All @@ -112,7 +143,7 @@ export const deleteScraper = (scraper: Scraper) => async (
dispatch: Dispatch<Action>
) => {
try {
await client.scrapers.delete(scraper.id)
await deleteScraperApi({scraperTargetID: scraper.id})

dispatch(removeScraper(scraper.id))
dispatch(notify(scraperDeleteSuccess(scraper.name)))
Expand Down
5 changes: 2 additions & 3 deletions src/scrapers/components/CreateScraperOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import CreateScraperForm from 'src/scrapers/components/CreateScraperForm'
import {createScraper} from 'src/scrapers/actions/thunks'

// Types
import {ScraperTargetRequest} from '@influxdata/influx'
import {AppState, Bucket, ResourceType} from 'src/types'
import {AppState, Bucket, ResourceType, ScraperTargetRequest} from 'src/types'

// Selectors
import {getAll} from 'src/resources/selectors'
Expand Down Expand Up @@ -48,7 +47,7 @@ class CreateScraperOverlay extends PureComponent<Props, State> {
this.state = {
scraper: {
name: 'Name this Scraper',
type: ScraperTargetRequest.TypeEnum.Prometheus,
type: 'prometheus',
url: `${this.origin}/metrics`,
orgID,
bucketID: bucketID ? bucketID : firstBucketID,
Expand Down
3 changes: 1 addition & 2 deletions src/shared/components/ExportOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import CopyButton from 'src/shared/components/CopyButton'
import {downloadTextFile} from 'src/shared/utils/download'

// Types
import {DocumentCreate} from '@influxdata/influx'
import {ComponentColor, ComponentSize} from '@influxdata/clockface'
import {RemoteDataState} from 'src/types'
import {DocumentCreate, RemoteDataState} from 'src/types'

interface Props {
onDismissOverlay: () => void
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/resourceToTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
Label,
Dashboard,
DashboardQuery,
DocumentCreate,
Cell,
View,
Variable,
LabelRelationship,
LabelIncluded,
TemplateType,
} from 'src/types'
import {DocumentCreate} from '@influxdata/influx'

const CURRENT_TEMPLATE_VERSION = '1'

Expand Down
2 changes: 1 addition & 1 deletion src/templates/actions/creators.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Types
import {
CommunityTemplate,
DocumentCreate,
RemoteDataState,
TemplateSummaryEntities,
} from 'src/types'
import {DocumentCreate} from '@influxdata/influx'
import {NormalizedSchema} from 'normalizr'

import {InstalledStack} from 'src/types'
Expand Down
37 changes: 37 additions & 0 deletions src/types/documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {Label} from 'src/types'

export interface DocumentCreate {
meta: DocumentMeta
content: any
org?: string
orgID?: string
labels?: Array<string>
}

export interface DocumentMeta {
name: string
type?: string
description?: string
version: string
createdAt?: Date
updatedAt?: Date
}

export interface Document {
id: string
meta: DocumentMeta
content: any
labels?: Array<Label>
links?: DocumentLinks
}

export interface DocumentLinks {
self?: string
}

export interface DocumentListEntry {
id: string
meta: DocumentMeta
labels?: Array<Label>
links?: DocumentLinks
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './colors'
export * from './dashboards'
export * from './dataExplorer'
export * from './dataLoaders'
export * from './documents'
export * from './eventViewer'
export * from './flux'
export * from './form'
Expand Down
15 changes: 13 additions & 2 deletions src/types/scrapers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import {ScraperTargetResponse} from '@influxdata/influx'
export interface Scraper extends ScraperTargetRequest {
id?: string
org?: string
bucket?: string
links?: any
}

export interface Scraper extends ScraperTargetResponse {}
export interface ScraperTargetRequest {
name?: string
type?: 'prometheus'
url?: string
orgID?: string
bucketID?: string
}
10 changes: 4 additions & 6 deletions src/types/templates.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
Cell,
Dashboard,
Document,
DocumentCreate,
DocumentListEntry,
DocumentMeta,
TemplateSummary as GenTemplateSummary,
} from '@influxdata/influx'
import {
Cell,
Dashboard,
NormalizedState,
RemoteDataState,
Variable,
Expand Down Expand Up @@ -34,7 +32,7 @@ export interface InstalledStack extends Stack {
sources: string[]
}

export interface TemplateSummary extends Omit<GenTemplateSummary, 'labels'> {
export interface TemplateSummary extends Omit<DocumentListEntry, 'labels'> {
labels: string[]
status: RemoteDataState
}
Expand Down
6 changes: 0 additions & 6 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Libraries
import {Client} from '@influxdata/influx'
import {get} from 'lodash'
import {getAPIBasepath} from 'src/utils/basepath'

const basePath = `${getAPIBasepath()}/api/v2`

export const getErrorMessage = (e: any) => {
let message = get(e, 'response.data.error.message')
Expand Down Expand Up @@ -35,5 +31,3 @@ export const getErrorMessage = (e: any) => {

return message
}

export const client = new Client(basePath)
Loading

0 comments on commit a2bd1f3

Please sign in to comment.