forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request grafana#12675 from grafana/davkal/logging-datasource
Datasource for Grafana logging platform
- Loading branch information
Showing
17 changed files
with
620 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
export default function({ value }) { | ||
return ( | ||
<div> | ||
<pre>{JSON.stringify(value, undefined, 2)}</pre> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { Fragment, PureComponent } from 'react'; | ||
|
||
import { LogsModel, LogRow } from 'app/core/logs_model'; | ||
|
||
interface LogsProps { | ||
className?: string; | ||
data: LogsModel; | ||
} | ||
|
||
const EXAMPLE_QUERY = '{job="default/prometheus"}'; | ||
|
||
const Entry: React.SFC<LogRow> = props => { | ||
const { entry, searchMatches } = props; | ||
if (searchMatches && searchMatches.length > 0) { | ||
let lastMatchEnd = 0; | ||
const spans = searchMatches.reduce((acc, match, i) => { | ||
// Insert non-match | ||
if (match.start !== lastMatchEnd) { | ||
acc.push(<>{entry.slice(lastMatchEnd, match.start)}</>); | ||
} | ||
// Match | ||
acc.push( | ||
<span className="logs-row-match-highlight" title={`Matching expression: ${match.text}`}> | ||
{entry.substr(match.start, match.length)} | ||
</span> | ||
); | ||
lastMatchEnd = match.start + match.length; | ||
// Non-matching end | ||
if (i === searchMatches.length - 1) { | ||
acc.push(<>{entry.slice(lastMatchEnd)}</>); | ||
} | ||
return acc; | ||
}, []); | ||
return <>{spans}</>; | ||
} | ||
return <>{props.entry}</>; | ||
}; | ||
|
||
export default class Logs extends PureComponent<LogsProps, any> { | ||
render() { | ||
const { className = '', data } = this.props; | ||
const hasData = data && data.rows && data.rows.length > 0; | ||
return ( | ||
<div className={`${className} logs`}> | ||
{hasData ? ( | ||
<div className="logs-entries panel-container"> | ||
{data.rows.map(row => ( | ||
<Fragment key={row.key}> | ||
<div className={row.logLevel ? `logs-row-level logs-row-level-${row.logLevel}` : ''} /> | ||
<div title={`${row.timestamp} (${row.timeFromNow})`}>{row.timeLocal}</div> | ||
<div> | ||
<Entry {...row} /> | ||
</div> | ||
</Fragment> | ||
))} | ||
</div> | ||
) : null} | ||
{!hasData ? ( | ||
<div className="panel-container"> | ||
Enter a query like <code>{EXAMPLE_QUERY}</code> | ||
</div> | ||
) : null} | ||
</div> | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export enum LogLevel { | ||
crit = 'crit', | ||
warn = 'warn', | ||
err = 'error', | ||
error = 'error', | ||
info = 'info', | ||
debug = 'debug', | ||
trace = 'trace', | ||
} | ||
|
||
export interface LogSearchMatch { | ||
start: number; | ||
length: number; | ||
text?: string; | ||
} | ||
|
||
export interface LogRow { | ||
key: string; | ||
entry: string; | ||
logLevel: LogLevel; | ||
timestamp: string; | ||
timeFromNow: string; | ||
timeLocal: string; | ||
searchMatches?: LogSearchMatch[]; | ||
} | ||
|
||
export interface LogsModel { | ||
rows: LogRow[]; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Grafana Logging Datasource - Native Plugin | ||
|
||
This is a **built in** datasource that allows you to connect to Grafana's logging service. |
Oops, something went wrong.