-
Notifications
You must be signed in to change notification settings - Fork 29
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 #59 from grafana/feature/event-refactor
Feature/event refactor
- Loading branch information
Showing
118 changed files
with
4,879 additions
and
2,791 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,95 @@ | ||
// helper for adding p(99) to existing chart | ||
function addP99 (chart) { | ||
chart.series = { | ||
...chart.series, | ||
'http_req_duration_trend_p(99)': { label: 'p(99)', format: 'duration' } | ||
//@ts-check | ||
/** | ||
* @typedef {import('./config').dashboard.Config} Config | ||
* @typedef {import('./config').dashboard.Tab} Tab | ||
* @typedef {import('./config').dashboard.Panel} Panel | ||
* @typedef {import('./config').dashboard.Chart} Chart | ||
*/ | ||
|
||
/** | ||
* Customize dashboard configuration. | ||
* @param {Config} config default dashboard configuration | ||
* @returns {Config} modified dashboard configuration | ||
*/ | ||
export default function (config) { | ||
/** | ||
* Search for an array element that has a given id property value. | ||
* @param {string} id the id for the search | ||
* @returns the first element whose id property matches or is undefined if there are no results | ||
*/ | ||
function getById(id) { | ||
return this.filter((/** @type {{ id: string; }} */ element) => element.id == id).at(0) | ||
} | ||
} | ||
|
||
// define request duration panel | ||
function durationPanel (suffix) { | ||
return { | ||
id: `http_req_duration_${suffix}`, | ||
title: `HTTP Request Duration ${suffix}`, | ||
metric: `http_req_duration_trend_${suffix}`, | ||
format: 'duration' | ||
// add getById method to all array | ||
Array.prototype["getById"] = getById | ||
|
||
/** | ||
* helper for adding p(99) to existing chart | ||
* @param {Chart} chart | ||
*/ | ||
function addP99 (chart) { | ||
chart.series = Object.assign({}, chart.series) | ||
chart.series['http_req_duration.p(99)'] = { label: 'p(99)', format: 'duration' } | ||
} | ||
} | ||
|
||
// copy vus and http_reqs panel from default config | ||
const overview = defaultConfig.tab('overview_snapshot') | ||
|
||
// define custom panels | ||
const customPanels = [ | ||
overview.panel('vus'), | ||
overview.panel('http_reqs'), | ||
durationPanel('avg'), | ||
durationPanel('p(90)'), | ||
durationPanel('p(95)'), | ||
durationPanel('p(99)') | ||
] | ||
|
||
// copy http_req_duration chart form default config... | ||
const durationChart = { ...overview.chart('http_req_duration') } | ||
|
||
// ... and add p(99) | ||
addP99(durationChart) | ||
|
||
// uncomment to add cumulative tabs | ||
// defaultConfig.tabs.push(defaultConfig.tabOverview('cumulative')) | ||
// defaultConfig.tabs.push(defaultConfig.tabTimings('cumulative')) | ||
|
||
// define custom tab | ||
const customTab = { | ||
id: 'custom', | ||
title: 'Custom', | ||
event: overview.event, | ||
panels: customPanels, | ||
charts: [overview.chart('http_reqs'), durationChart], | ||
description: 'Example of customizing the display of metrics.' | ||
} | ||
/** | ||
* define request duration panel | ||
* @param {string} suffix | ||
* @returns {Panel} panel | ||
*/ | ||
function durationPanel (suffix) { | ||
return { | ||
id: `http_req_duration_${suffix}`, | ||
title: `HTTP Request Duration ${suffix}`, | ||
metric: `http_req_duration_trend_${suffix}`, | ||
format: 'duration' | ||
} | ||
} | ||
|
||
/** | ||
* reference to overview tab from default config | ||
* @type {Tab} | ||
*/ | ||
const overview = config.tabs.getById('overview_snapshot') | ||
|
||
// add custom tab to configuration | ||
defaultConfig.tabs.push(customTab) | ||
/** | ||
* define custom panels | ||
* @type {Panel[]} | ||
*/ | ||
const customPanels = [ | ||
overview.panels.getById('vus'), | ||
overview.panels.getById('http_reqs'), | ||
durationPanel('avg'), | ||
durationPanel('p(90)'), | ||
durationPanel('p(95)'), | ||
durationPanel('p(99)') | ||
] | ||
|
||
export default defaultConfig | ||
/** | ||
* copy of the http_req_duration chart form default config | ||
* @type {Chart} | ||
*/ | ||
const durationChart = Object.assign({}, overview.charts.getById('http_req_duration')) | ||
|
||
// and add p(99) | ||
addP99(durationChart) | ||
|
||
/** | ||
* custom tab definition | ||
* @type {Tab} | ||
*/ | ||
const customTab = { | ||
id: 'custom', | ||
title: 'Custom', | ||
event: overview.event, | ||
panels: customPanels, | ||
charts: [overview.charts.getById('http_reqs'), durationChart], | ||
description: 'Example of customizing the display of metrics.' | ||
} | ||
|
||
// add custom tab to configuration | ||
config.tabs.push(customTab) | ||
|
||
return config | ||
} |
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
Oops, something went wrong.