-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ClickHouse plugin only for logs (#150)
The ClickHouse plugin can now only be used as interface for the kobsio/fluent-bit-clickhouse plugin. To run raw SQL queries against a ClickHouse instance within kobs, the new SQL plugin from #149 can be used.
- Loading branch information
1 parent
568e2c4
commit 198d9a0
Showing
17 changed files
with
103 additions
and
629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,95 @@ | ||
import React from 'react'; | ||
import { PageSection, PageSectionVariants, Title } from '@patternfly/react-core'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
|
||
import { IOptions } from '../../utils/interfaces'; | ||
import { IPluginPageProps } from '@kobsio/plugin-core'; | ||
import LogsPage from './LogsPage'; | ||
import SQLPage from './SQLPage'; | ||
|
||
const Page: React.FunctionComponent<IPluginPageProps> = ({ | ||
name, | ||
displayName, | ||
description, | ||
options, | ||
}: IPluginPageProps) => { | ||
if (options && options.type && options.type === 'logs') { | ||
return <LogsPage name={name} displayName={displayName} description={description} />; | ||
} else if (options && options.type && options.type === 'sql') { | ||
return <SQLPage name={name} displayName={displayName} description={description} />; | ||
} | ||
|
||
return null; | ||
import Logs from './Logs'; | ||
import LogsToolbar from './LogsToolbar'; | ||
import { getOptionsFromSearch } from '../../utils/helpers'; | ||
|
||
const Page: React.FunctionComponent<IPluginPageProps> = ({ name, displayName, description }: IPluginPageProps) => { | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
const [options, setOptions] = useState<IOptions>(getOptionsFromSearch(location.search)); | ||
|
||
// changeOptions is used to change the options for an ClickHouse query. Instead of directly modifying the options | ||
// state we change the URL parameters. | ||
const changeOptions = (opts: IOptions): void => { | ||
const fields = opts.fields ? opts.fields.map((field) => `&field=${field}`) : []; | ||
|
||
history.push({ | ||
pathname: location.pathname, | ||
search: `?query=${opts.query}&order=${opts.order}&orderBy=${opts.orderBy}&maxDocuments=${ | ||
opts.maxDocuments | ||
}&time=${opts.times.time}&timeEnd=${opts.times.timeEnd}&timeStart=${opts.times.timeStart}${ | ||
fields.length > 0 ? fields.join('') : '' | ||
}`, | ||
}); | ||
}; | ||
|
||
// selectField is used to add a field as parameter, when it isn't present and to remove a fields from as parameter, | ||
// when it is already present via the changeOptions function. | ||
const selectField = (field: string): void => { | ||
let tmpFields: string[] = []; | ||
if (options.fields) { | ||
tmpFields = [...options.fields]; | ||
} | ||
|
||
if (tmpFields.includes(field)) { | ||
tmpFields = tmpFields.filter((f) => f !== field); | ||
} else { | ||
tmpFields.push(field); | ||
} | ||
|
||
changeOptions({ ...options, fields: tmpFields }); | ||
}; | ||
|
||
// useEffect is used to set the options every time the search location for the current URL changes. The URL is changed | ||
// via the changeOptions function. When the search location is changed we modify the options state. | ||
useEffect(() => { | ||
setOptions(getOptionsFromSearch(location.search)); | ||
}, [location.search]); | ||
|
||
return ( | ||
<React.Fragment> | ||
<PageSection variant={PageSectionVariants.light}> | ||
<Title headingLevel="h6" size="xl"> | ||
{displayName} | ||
<span className="pf-u-font-size-md pf-u-font-weight-normal" style={{ float: 'right' }}> | ||
<a href="https://kobs.io/plugins/clickhouse/" target="_blank" rel="noreferrer"> | ||
Documentation | ||
</a> | ||
</span> | ||
</Title> | ||
<p>{description}</p> | ||
<LogsToolbar | ||
query={options.query} | ||
order={options.order} | ||
orderBy={options.orderBy} | ||
maxDocuments={options.maxDocuments} | ||
fields={options.fields} | ||
times={options.times} | ||
setOptions={changeOptions} | ||
/> | ||
</PageSection> | ||
|
||
<PageSection style={{ minHeight: '100%' }} variant={PageSectionVariants.default}> | ||
{options.query.length > 0 ? ( | ||
<Logs | ||
name={name} | ||
fields={options.fields} | ||
query={options.query} | ||
order={options.order} | ||
orderBy={options.orderBy} | ||
maxDocuments={options.maxDocuments} | ||
selectField={selectField} | ||
times={options.times} | ||
/> | ||
) : null} | ||
</PageSection> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default Page; |
Oops, something went wrong.