1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+network-ingresses/ingress-charts.tsx
Jari Kolehmainen a03da3c572
Remove lingui (#1874)
* remove lingui

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* babelless

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* tweak ts-loader options

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* tweak renderer webpack config

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-12-29 14:53:34 +02:00

97 lines
2.8 KiB
TypeScript

import React, { useContext } from "react";
import { observer } from "mobx-react";
import { ChartOptions, ChartPoint } from "chart.js";
import { IIngressMetrics, Ingress } from "../../api/endpoints";
import { BarChart, memoryOptions } from "../chart";
import { normalizeMetrics, isMetricsEmpty } from "../../api/endpoints/metrics.api";
import { NoMetrics } from "../resource-metrics/no-metrics";
import { ResourceMetricsContext, IResourceMetricsValue } from "../resource-metrics";
type IContext = IResourceMetricsValue<Ingress, { metrics: IIngressMetrics }>;
export const IngressCharts = observer(() => {
const { params: { metrics }, tabId, object } = useContext<IContext>(ResourceMetricsContext);
const id = object.getId();
if (!metrics) return null;
if (isMetricsEmpty(metrics)) return <NoMetrics/>;
const values = Object.values(metrics)
.map(normalizeMetrics)
.map(({ data }) => data.result[0].values);
const [
bytesSentSuccess,
bytesSentFailure,
requestDurationSeconds,
responseDurationSeconds
] = values;
const datasets = [
// Network
[
{
id: `${id}-bytesSentSuccess`,
label: `Bytes sent, status 2xx`,
tooltip: `Bytes sent by Ingress controller with successful status`,
borderColor: "#46cd9e",
data: bytesSentSuccess.map(([x, y]) => ({ x, y }))
},
{
id: `${id}-bytesSentFailure`,
label: `Bytes sent, status 5xx`,
tooltip: `Bytes sent by Ingress controller with error status`,
borderColor: "#cd465a",
data: bytesSentFailure.map(([x, y]) => ({ x, y }))
},
],
// Duration
[
{
id: `${id}-requestDurationSeconds`,
label: `Request`,
tooltip: `Request duration in seconds`,
borderColor: "#48b18d",
data: requestDurationSeconds.map(([x, y]) => ({ x, y }))
},
{
id: `${id}-responseDurationSeconds`,
label: `Response`,
tooltip: `Response duration in seconds`,
borderColor: "#73ba3c",
data: responseDurationSeconds.map(([x, y]) => ({ x, y }))
},
]
];
const durationOptions: ChartOptions = {
scales: {
yAxes: [{
ticks: {
callback: value => value
}
}]
},
tooltips: {
callbacks: {
label: ({ datasetIndex, index }, { datasets }) => {
const { label, data } = datasets[datasetIndex];
const value = data[index] as ChartPoint;
const chartTooltipSec = `sec`;
return `${label}: ${parseFloat(value.y as string).toFixed(3)} ${chartTooltipSec}`;
}
}
}
};
const options = [memoryOptions, durationOptions];
return (
<BarChart
name={`${object.getName()}-metric-${tabId}`}
options={options[tabId]}
data={{ datasets: datasets[tabId] }}
/>
);
});