Skip to content

Commit 6e8e352

Browse files
committed
test
2 parents a49766e + 258959c commit 6e8e352

36 files changed

+4113
-111
lines changed

app/charts/EventChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ const EventChart: React.FC<EventChartProps> = React.memo(props => {
5050

5151
// removes underscores from metric names to improve their look in the graph
5252
const prettyMetricName = (metricName: string): string => {
53-
const newName = metricName.replace(/kubernetes-cadvisor\/docker-desktop\//g, '');
53+
const newName = metricName.replace(/.*\/.*\//g, '');
5454
return newName.replace(/_/g, ' ');
5555
};
5656

5757
const createChart = () => {
5858
const prettyName = prettyMetricName(metricName);
5959
const prettyTime = prettyTimeInReverse(chartData.time);
60-
60+
6161
const plotlyDataObject: PlotlyData = {
6262
name: prettyName,
6363
x: prettyTime,

app/charts/GrafanaEventChart.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React, { useState } from 'react';
2+
import { all, solo as soloStyle } from './sizeSwitch';
3+
4+
interface EventChartProps {
5+
metricName: string;
6+
token: string;
7+
}
8+
9+
// interface SoloStyles {
10+
// height: number;
11+
// width: number;
12+
// }
13+
14+
15+
16+
/**
17+
* @params {EventChartProps} props - the props object containing relevant data.
18+
* @desc Handles k8s metrics. Memoized component to generate event chart with formatted data
19+
* @returns {JSX.Element} The JSX element with the event chart.
20+
*/
21+
const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
22+
const { metricName, token } = props;
23+
const [graphType, setGraphType] = useState<string>("timeseries");
24+
// const [solo, setSolo] = useState<SoloStyles | null>(null);
25+
console.log("inside GrafanaEventChart")
26+
27+
// setInterval(() => {
28+
// if (solo !== soloStyle) {
29+
// setSolo(soloStyle);
30+
// }
31+
// }, 20);
32+
console.log("metricName: ", metricName)
33+
let uid = metricName.replace(/.*\/.*\//g, '')
34+
if (uid.length >= 40) {
35+
uid = metricName.slice(metricName.length - 39);
36+
}
37+
38+
let parsedName = metricName.replace(/.*\/.*\//g, '')
39+
console.log("uid: ", uid)
40+
console.log("parsedName: ", parsedName)
41+
42+
const handleSelectionChange = async (event) => {
43+
setGraphType(event.target.value);
44+
await fetch('http://localhost:1111/api/updateDashboard', {
45+
method: 'POST',
46+
headers: {
47+
'Content-Type': 'application/json',
48+
},
49+
body: JSON.stringify({ graphType: event.target.value, metric: metricName, token: token }),
50+
})
51+
52+
}
53+
54+
return (
55+
<div className="chart" data-testid="Grafana Event Chart">
56+
<h2>{parsedName}</h2>
57+
{/* create chart using grafana iframe tag*/}
58+
<iframe src={`http://localhost:32000/d-solo/${uid}/${parsedName}?orgId=1&refresh=10s&from=now-5m&to=now&panelId=1`} width="650" height="400" ></iframe>
59+
<select name="graphType" id="graphType" value={graphType} onChange={handleSelectionChange}>
60+
<option value="timeseries">Time Series</option>
61+
<option value="barchart">Bar Chart</option>
62+
<option value="stat">Stat</option>
63+
<option value="gauge">Gauge</option>
64+
<option value="table">Table</option>
65+
<option value="histogram">Histogram</option>
66+
</select>
67+
</div>
68+
);
69+
});
70+
71+
export default GrafanaEventChart;

app/components/TransferColumns.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ const TransferColumns = React.memo(() => {
141141
temp.push(newCategory);
142142
}
143143
}
144+
console.log('temp', temp)
144145
setSelectedMetrics(temp);
145146
};
146147

@@ -167,7 +168,7 @@ const TransferColumns = React.memo(() => {
167168
const row = {
168169
id: index,
169170
tag: el.tag,
170-
title: el.title.split(' | ')[1].replace('kubernetes-cadvisor/docker-desktop/', ''),
171+
title: el.title.split(' | ')[1].replace(/.*\/.*\//g, ''),
171172
}; // gets rid of the full path
172173
rows.push(row);
173174
});

0 commit comments

Comments
 (0)