Skip to content

Commit cef3610

Browse files
authored
Merge pull request #65 from oslabs-beta/ms/settingsSidebar_cardsDisplay
Ms/settings sidebar cards display
2 parents 9ddf5f5 + 8e822c9 commit cef3610

File tree

14 files changed

+5844
-586
lines changed

14 files changed

+5844
-586
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: 75 additions & 6 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----------------
@@ -48,14 +49,82 @@ const RootQueryType = new GraphQLObjectType({
4849
metric: { type: GraphQLNonNull(GraphQLString)},
4950
start: { type: GraphQLNonNull(GraphQLInt)},
5051
end: { type: GraphQLNonNull(GraphQLInt)},
51-
resolution: { type: GraphQLNonNull(GraphQLInt)}
52+
resolution: { type: GraphQLNonNull(GraphQLInt)},
53+
prometheusURL: { type: GraphQLNonNull(GraphQLString)}
5254
},
53-
resolve: (parent, {start, end, resolution, metric}) => {
54-
return axios.get(`http://localhost:9090/api/v1/query_range?step=${resolution}s&end=${end}&start=${start}&query=${queryTypes[metric]}`)
55-
.then(res => res.data.data.result[0].values)
55+
resolve: (parent, {start, end, resolution, metric, prometheusURL}) => {
56+
if (prometheusURL[prometheusURL.length] === '/') prometheusURL = prometheusURL.slice(0, prometheusURL.length);
57+
58+
return axios.get(`${prometheusURL}/api/v1/query_range?step=${resolution}s&end=${end}&start=${start}&query=${queryTypes[metric]}`)
59+
.then(res => {
60+
return res.data.data.result[0].values})
5661
.catch(error => error);
5762
}
58-
}
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+
},
59128
})
60129
});
61130

@@ -68,4 +137,4 @@ app.use('/graphql', graphqlHTTP({
68137
graphiql: true
69138
}));
70139

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

0 commit comments

Comments
 (0)