Skip to content

Commit 8e822c9

Browse files
Altered server to have additional query types to feed each of the four card metrics at once. The metric card components were adjusted to make appropriate requests for and properly display data returned from the server
2 parents dc664ce + 3b364ef commit 8e822c9

File tree

13 files changed

+5636
-391
lines changed

13 files changed

+5636
-391
lines changed

ksqLight/package-lock.json

Lines changed: 56 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ksqLight/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
"concurrently": "^7.2.2",
2020
"cors": "^2.8.5",
2121
"cross-env": "^7.0.3",
22-
"electron": "^19.0.6",
22+
"electron": "^19.0.9",
2323
"express": "^4.18.1",
2424
"express-graphql": "^0.12.0",
2525
"graphql": "^15.8.0",
2626
"ksqldb-js": "^1.1.0",
27+
"livereload": "^0.9.3",
2728
"react": "^18.2.0",
2829
"react-dom": "^18.2.0",
2930
"react-router-dom": "^6.3.0",

ksqLight/server/server.js

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
GraphQLList,
1111
GraphQLInt,
1212
GraphQLNonNull,
13+
GraphQLBoolean,
1314
} = require('graphql');
1415

1516
//---------------Internal Module Imports----------------
@@ -55,10 +56,75 @@ const RootQueryType = new GraphQLObjectType({
5556
if (prometheusURL[prometheusURL.length] === '/') prometheusURL = prometheusURL.slice(0, prometheusURL.length);
5657

5758
return axios.get(`${prometheusURL}/api/v1/query_range?step=${resolution}s&end=${end}&start=${start}&query=${queryTypes[metric]}`)
58-
.then(res => res.data.data.result[0].values)
59+
.then(res => {
60+
return res.data.data.result[0].values})
5961
.catch(error => error);
6062
}
61-
}
63+
},
64+
livenessIndicator: {
65+
type: GraphQLBoolean,
66+
description: 'Boolean value representing whether the ksqlDB server up and emitting metrics.',
67+
args: {
68+
prometheusURL: { type: GraphQLNonNull(GraphQLString)}
69+
},
70+
resolve: async (parent, { prometheusURL }) => {
71+
try {
72+
return await axios.get(`${prometheusURL}/api/v1/query?query=ksql_ksql_engine_query_stats_liveness_indicator`)
73+
.then(res => res.data.data.result[0].value[1] === "1")
74+
.catch(error => {throw error});
75+
} catch (error) {
76+
return error;
77+
}
78+
}
79+
},
80+
errorRate: {
81+
type: GraphQLInt,
82+
description: 'The number of messages that were consumed but not processed.',
83+
args: {
84+
prometheusURL: { type: GraphQLNonNull(GraphQLString)}
85+
},
86+
resolve: async (parent, { prometheusURL }) => {
87+
try {
88+
return await axios.get(`${prometheusURL}/api/v1/query?query=ksql_ksql_engine_query_stats_error_rate`)
89+
.then(res => Number(res.data.data.result[0].value[1]))
90+
.catch(error => {throw error});
91+
} catch (error) {
92+
return error;
93+
}
94+
}
95+
},
96+
errorQueries: {
97+
type: GraphQLInt,
98+
description: 'The count of queries in ERROR state.',
99+
args: {
100+
prometheusURL: { type: GraphQLNonNull(GraphQLString)}
101+
},
102+
resolve: async (parent, { prometheusURL }) => {
103+
try {
104+
return await axios.get(`${prometheusURL}/api/v1/query?query=ksql_ksql_engine_query_stats_error_queries`)
105+
.then(res => Number(res.data.data.result[0].value[1]))
106+
.catch(error => {throw error});
107+
} catch (error) {
108+
return error;
109+
}
110+
}
111+
},
112+
bytesConsumed: {
113+
type: GraphQLInt,
114+
description: 'The total number of bytes consumed across all queries.',
115+
args: {
116+
prometheusURL: { type: GraphQLNonNull(GraphQLString)}
117+
},
118+
resolve: async (parent, { prometheusURL }) => {
119+
try {
120+
return await axios.get(`${prometheusURL}/api/v1/query?query=ksql_ksql_engine_query_stats_bytes_consumed_total`)
121+
.then(res => Number(res.data.data.result[0].value[1]))
122+
.catch(error => {throw error});
123+
} catch (error) {
124+
return error;
125+
}
126+
}
127+
},
62128
})
63129
});
64130

@@ -71,4 +137,4 @@ app.use('/graphql', graphqlHTTP({
71137
graphiql: true
72138
}));
73139

74-
app.listen(5000, () => console.log('Server Running...'));
140+
app.listen(5001, () => console.log('Server Running...'));

0 commit comments

Comments
 (0)