diff --git a/app/config.json b/app/config.json index bb347e1..86c89cb 100644 --- a/app/config.json +++ b/app/config.json @@ -101,6 +101,13 @@ } ] } + ], + "intervals": [ + "1h", + "2h", + "6h", + "12h", + "24h" ] } ] @@ -112,6 +119,13 @@ { "groupKind": "pod", "tabs": ["GoldenSignal"], + "intervals": [ + "1h", + "2h", + "6h", + "12h", + "24h" + ], "rows": [ { "name": "container", @@ -195,7 +209,13 @@ }, { "groupKind": "deployment", - + "intervals": [ + "1h", + "2h", + "6h", + "12h", + "24h" + ], "rows": [ { "name": "httpaggrigatedanomaly", @@ -301,10 +321,12 @@ ] } ] + } ] } ], + "provider": { "Name": "default", diff --git a/extensions/resource-metrics/resource-metrics-extention/ui/src/Metrics/Metrics.tsx b/extensions/resource-metrics/resource-metrics-extention/ui/src/Metrics/Metrics.tsx index 7d02d3d..bb2a71c 100644 --- a/extensions/resource-metrics/resource-metrics-extention/ui/src/Metrics/Metrics.tsx +++ b/extensions/resource-metrics/resource-metrics-extention/ui/src/Metrics/Metrics.tsx @@ -14,6 +14,7 @@ export const Metrics = ({ setHasMetrics, isLoading, setIsLoading, + setIntervals }: any) => { const resourceName = resource.kind === "Application" ? "" : resource?.metadata?.name; @@ -33,9 +34,9 @@ export const Metrics = ({ applicationName, applicationNamespace, resourceType: resource.kind, - project, + project }) - .then((response) => { + .then(response => { if (response.status > 399) { throw new Error("No metrics"); } @@ -45,11 +46,12 @@ export const Metrics = ({ setIsLoading(false); setHasMetrics(true); setDashboard(data); + setIntervals(data?.intervals || []); if (data?.tabs?.length) { setSelectedTab(data.tabs[0]); } }) - .catch((err) => { + .catch(err => { setHasMetrics(false); setIsLoading(false); console.error("res.data", err); diff --git a/extensions/resource-metrics/resource-metrics-extention/ui/src/index.tsx b/extensions/resource-metrics/resource-metrics-extention/ui/src/index.tsx index 4d7752f..bec6cb1 100644 --- a/extensions/resource-metrics/resource-metrics-extention/ui/src/index.tsx +++ b/extensions/resource-metrics/resource-metrics-extention/ui/src/index.tsx @@ -12,6 +12,7 @@ export const Extension = (props: any) => { const [duration, setDuration] = useState("1h"); const [hasMetrics, setHasMetrics] = useState(false); const [isLoading, setIsLoading] = useState(true); + const [intervals, setIntervals] = useState([]); const loc = window.location; const { resource, application } = props; @@ -27,11 +28,11 @@ export const Extension = (props: any) => { url = `/api/v1/applications/${application_name}/events`; } fetch(url) - .then((response) => response.json()) - .then((data) => { + .then(response => response.json()) + .then(data => { setEvents(data?.items || []); }) - .catch((err) => { + .catch(err => { console.error("res.data", err); }); }, [application_name, resource, duration]); @@ -41,61 +42,21 @@ export const Extension = (props: any) => { {!isLoading && !hasMetrics &&

No metrics to display

} {!isLoading && hasMetrics && (
- { - updateDuration(e, "24h"); - }} - > - 1 day - - { - updateDuration(e, "12h"); - }} - > - 12 hrs - - { - updateDuration(e, "6h"); - }} - > - 6 hrs - - { - updateDuration(e, "2h"); - }} - > - 2 hrs - - { - updateDuration(e, "1h"); - }} - > - 1 hr - + {intervals?.length > 0 && + intervals?.map((hasDuration: string) => ( + { + updateDuration(e, hasDuration); + }} + > + {hasDuration} + + ))}
)} { setHasMetrics={setHasMetrics} isLoading={isLoading} setIsLoading={setIsLoading} + setIntervals={setIntervals} /> ); @@ -117,7 +79,7 @@ export const component = Extension; window?.extensionsAPI?.registerResourceExtension( component, "*", - "*", + "Rollout", "Metrics", { icon: "fa fa-chart-area" } ); diff --git a/extensions/resource-metrics/resource-metrics-extention/ui/tslint.json b/extensions/resource-metrics/resource-metrics-extention/ui/tslint.json new file mode 100644 index 0000000..be51507 --- /dev/null +++ b/extensions/resource-metrics/resource-metrics-extention/ui/tslint.json @@ -0,0 +1,21 @@ +{ + "extends": [ + "tslint:recommended", "tslint-react", "tslint-plugin-prettier", "tslint-config-prettier" + ], + "jsRules": {}, + "rules": { + "prettier": true, + "quotemark": [true, "single"], + "no-var-requires": false, + "interface-name": false, + "jsx-no-multiline-js": false, + "object-literal-sort-keys": false, + "jsx-alignment": false, + "max-line-length": [true, 200], + "jsx-no-lambda": false, + "array-type": false, + "max-classes-per-file": false, + "newline-per-chained-call": false + }, + "rulesDirectory": [] +} diff --git a/server/config.go b/server/config.go index 43a3fe8..97cdfe0 100644 --- a/server/config.go +++ b/server/config.go @@ -48,6 +48,7 @@ type Dashboard struct { Tabs []string `json:"tabs"` Rows []*Row `json:"rows"` ProviderType string `json:"providerType"` + Intervals []string `json:"intervals"` } func (d *Dashboard) getRow(name string) *Row {