Skip to content

Commit

Permalink
custom duration (#42)
Browse files Browse the repository at this point in the history
* add duration in config

Signed-off-by: ashutosh16 <[email protected]>

* add metrics ui only to rollout

Signed-off-by: ashutosh16 <[email protected]>

* add metrics ui only to rollout

Signed-off-by: ashutosh16 <[email protected]>

* add custom intervals

Signed-off-by: ashutosh16 <[email protected]>

---------

Signed-off-by: ashutosh16 <[email protected]>
  • Loading branch information
ashutosh16 authored Jun 14, 2023
1 parent 2d48268 commit 60cb1dd
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 63 deletions.
24 changes: 23 additions & 1 deletion app/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
}
]
}
],
"intervals": [
"1h",
"2h",
"6h",
"12h",
"24h"
]
}
]
Expand All @@ -112,6 +119,13 @@
{
"groupKind": "pod",
"tabs": ["GoldenSignal"],
"intervals": [
"1h",
"2h",
"6h",
"12h",
"24h"
],
"rows": [
{
"name": "container",
Expand Down Expand Up @@ -195,7 +209,13 @@
},
{
"groupKind": "deployment",

"intervals": [
"1h",
"2h",
"6h",
"12h",
"24h"
],
"rows": [
{
"name": "httpaggrigatedanomaly",
Expand Down Expand Up @@ -301,10 +321,12 @@
]
}
]

}
]
}
],

"provider":
{
"Name": "default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Metrics = ({
setHasMetrics,
isLoading,
setIsLoading,
setIntervals
}: any) => {
const resourceName =
resource.kind === "Application" ? "" : resource?.metadata?.name;
Expand All @@ -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");
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Extension = (props: any) => {
const [duration, setDuration] = useState("1h");
const [hasMetrics, setHasMetrics] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [intervals, setIntervals] = useState([]);

const loc = window.location;
const { resource, application } = props;
Expand All @@ -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]);
Expand All @@ -41,61 +42,21 @@ export const Extension = (props: any) => {
{!isLoading && !hasMetrics && <p>No metrics to display</p>}
{!isLoading && hasMetrics && (
<div className="application-metrics__MetricsDurationSelector">
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === "24h" ? "active" : ""
}`}
onClick={(e) => {
updateDuration(e, "24h");
}}
>
1 day
</a>
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === "12h" ? "active" : ""
}`}
onClick={(e) => {
updateDuration(e, "12h");
}}
>
12 hrs
</a>
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === "6h" ? "active" : ""
}`}
onClick={(e) => {
updateDuration(e, "6h");
}}
>
6 hrs
</a>
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === "2h" ? "active" : ""
}`}
onClick={(e) => {
updateDuration(e, "2h");
}}
>
2 hrs
</a>
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === "1h" ? "active" : ""
}`}
onClick={(e) => {
updateDuration(e, "1h");
}}
>
1 hr
</a>
{intervals?.length > 0 &&
intervals?.map((hasDuration: string) => (
<a
href={`${loc}`}
className={`application-metrics__MetricsDuration ${
duration === hasDuration ? "active" : ""
}`}
key={hasDuration}
onClick={e => {
updateDuration(e, hasDuration);
}}
>
{hasDuration}
</a>
))}
</div>
)}
<Metrics
Expand All @@ -105,6 +66,7 @@ export const Extension = (props: any) => {
setHasMetrics={setHasMetrics}
isLoading={isLoading}
setIsLoading={setIsLoading}
setIntervals={setIntervals}
/>
</React.Fragment>
);
Expand All @@ -117,7 +79,7 @@ export const component = Extension;
window?.extensionsAPI?.registerResourceExtension(
component,
"*",
"*",
"Rollout",
"Metrics",
{ icon: "fa fa-chart-area" }
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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": []
}
1 change: 1 addition & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 60cb1dd

Please sign in to comment.