-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prometheus: Add settings to prometheus plugin #87
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,49 @@ import { Box, useTheme } from '@mui/material'; | |
import { useEffect, useState } from 'react'; | ||
import { Area, AreaChart, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; | ||
|
||
/** | ||
* Calculates the time range based on the given interval. | ||
* @param {string} interval - The time interval (e.g., '10m', '1h', '24h', 'week'). | ||
* @returns {Object} An object containing the 'from' timestamp, 'to' timestamp, and 'step' in seconds. | ||
*/ | ||
export function getTimeRange(interval: string): { from: number; to: number; step: number } { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there somewhere this is specified? A URL to some docs or code perhaps? |
||
const now = Math.floor(Date.now() / 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function could use some tests. |
||
const day = 86400; // seconds in a day | ||
|
||
switch (interval) { | ||
case '10m': | ||
return { from: now - 600, to: now, step: 15 }; // 15 seconds step | ||
case '30m': | ||
return { from: now - 1800, to: now, step: 30 }; // 30 seconds step | ||
case '1h': | ||
return { from: now - 3600, to: now, step: 60 }; // 1 minute step | ||
case '3h': | ||
return { from: now - 10800, to: now, step: 180 }; // 3 minutes step | ||
case '6h': | ||
return { from: now - 21600, to: now, step: 360 }; // 6 minutes step | ||
case '12h': | ||
return { from: now - 43200, to: now, step: 720 }; // 12 minutes step | ||
case '24h': | ||
return { from: now - day, to: now, step: 300 }; // 5 minutes step | ||
case '48h': | ||
return { from: now - 2 * day, to: now, step: 600 }; // 10 minutes step | ||
case 'today': | ||
return { from: now - (now % day), to: now, step: 300 }; // 5 minutes step | ||
case 'yesterday': | ||
return { from: now - (now % day) - day, to: now - (now % day), step: 300 }; // 5 minutes step | ||
case 'week': | ||
return { from: now - 7 * day, to: now, step: 3600 }; // 1 hour step | ||
case 'lastweek': | ||
return { from: now - 14 * day, to: now - 7 * day, step: 3600 }; // 1 hour step | ||
case '7d': | ||
return { from: now - 7 * day, to: now, step: 3600 }; // 1 hour step | ||
case '14d': | ||
return { from: now - 14 * day, to: now, step: 7200 }; // 2 hours step | ||
default: | ||
return { from: now - 600, to: now, step: 15 }; // Default to 10 minutes with 15 seconds step | ||
} | ||
} | ||
|
||
export interface ChartProps { | ||
plots: Array<{ | ||
query: string; | ||
|
@@ -12,6 +55,7 @@ export interface ChartProps { | |
dataProcessor: (data: any) => any[]; | ||
}>; | ||
fetchMetrics: (query: object) => Promise<any>; | ||
interval: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please document these fields? |
||
prometheusPrefix: string; | ||
autoRefresh: boolean; | ||
xAxisProps: { | ||
|
@@ -40,9 +84,7 @@ export function Chart(props: ChartProps) { | |
plots: Array<{ query: string; name: string; dataProcessor: (data: any) => any }>, | ||
firstLoad: boolean = false | ||
) => { | ||
const currentTime = Date.now() / 1000; | ||
|
||
const tenMinutesBefore = currentTime - 10 * 60; | ||
const { from, to, step } = getTimeRange(props.interval); | ||
|
||
const fetchedMetrics: { | ||
[key: string]: { | ||
|
@@ -60,9 +102,9 @@ export function Chart(props: ChartProps) { | |
response = await fetchMetrics({ | ||
prefix: props.prometheusPrefix, | ||
query: plot.query, | ||
from: tenMinutesBefore, | ||
to: currentTime, | ||
step: 2, | ||
from: from, | ||
to: to, | ||
step: step, | ||
}); | ||
} catch (e) { | ||
fetchedMetrics[plot.name] = { data: [], state: ChartState.ERROR }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will affect how this is installed.
How to handle this? At minimum a note in the release notes (or in the README?) should warn people to remove their old prometheus plugin, what the old one is called and what the new folder name is called.
This could also affect settings/permissions for running plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the app/ bundling will need to be changed to get the new plugin name too?