@@ -86,36 +86,15 @@ const getAlertManagerBaseURL = () => window.SERVER_FLAGS.alertManagerBaseURL;
86
86
export class ClusterOverview extends React . Component {
87
87
constructor ( props ) {
88
88
super ( props ) ;
89
- this . messages = { } ;
90
-
91
89
this . state = {
92
- openshiftClusterVersions : null ,
93
90
healthData : {
94
91
data : { } ,
95
92
loaded : false ,
96
93
} ,
97
- consumersData : { } ,
98
- capacityData : { } ,
99
- utilizationData : { } ,
100
- diskStats : { } ,
101
94
} ;
102
95
103
- this . setConsumersData = this . _setConsumersData . bind ( this ) ;
104
96
this . setHealthData = this . _setHealthData . bind ( this ) ;
105
- this . setDetailsOpenshiftResponse = this . _setDetailsOpenshiftResponse . bind ( this ) ;
106
- this . setCapacityData = this . _setCapacityData . bind ( this ) ;
107
- this . setUtilizationData = this . _setUtilizationData . bind ( this ) ;
108
97
this . getStorageMetrics = this . _getStorageMetrics . bind ( this ) ;
109
- this . setCephDiskStats = this . _setCephDiskStats . bind ( this ) ;
110
- }
111
-
112
- _setConsumersData ( key , response ) {
113
- this . setState ( state => ( {
114
- consumersData : {
115
- ...state . consumersData ,
116
- [ key ] : response ,
117
- } ,
118
- } ) ) ;
119
98
}
120
99
121
100
_setHealthData ( healthy , message ) {
@@ -130,40 +109,10 @@ export class ClusterOverview extends React.Component {
130
109
} ) ;
131
110
}
132
111
133
- _setDetailsOpenshiftResponse ( response ) {
134
- let openshiftClusterVersions = _ . get ( response , 'data.result' , [ ] ) ;
135
- if ( ! Array . isArray ( openshiftClusterVersions ) ) { // only one node
136
- openshiftClusterVersions = [ openshiftClusterVersions ] ;
137
- }
138
-
139
- this . setState ( {
140
- openshiftClusterVersions,
141
- } ) ;
142
- }
143
-
144
- _setCapacityData ( key , response ) {
145
- this . setState ( state => ( {
146
- capacityData : {
147
- ...state . capacityData ,
148
- [ key ] : response ,
149
- } ,
150
- } ) ) ;
151
- }
152
-
153
- _setUtilizationData ( key , response ) {
154
- this . setState ( state => ( {
155
- utilizationData : {
156
- ...state . utilizationData ,
157
- [ key ] : response ,
158
- } ,
159
- } ) ) ;
160
- }
161
-
162
112
async _getStorageMetrics ( ) {
113
+ let queryTotal = CAPACITY_STORAGE_TOTAL_DEFAULT_QUERY ;
114
+ let queryUsed = UTILIZATION_STORAGE_USED_DEFAULT_QUERY ;
163
115
try {
164
- let queryTotal = CAPACITY_STORAGE_TOTAL_DEFAULT_QUERY ;
165
- let queryUsed = UTILIZATION_STORAGE_USED_DEFAULT_QUERY ;
166
-
167
116
const metrics = await this . getPrometheusMetrics ( ) ;
168
117
if ( _ . get ( metrics , 'data' , [ ] ) . find ( metric => metric === CAPACITY_STORAGE_TOTAL_BASE_CEPH_METRIC ) ) {
169
118
const cephData = await this . getPrometheusQuery ( CAPACITY_STORAGE_TOTAL_QUERY ) ;
@@ -172,26 +121,12 @@ export class ClusterOverview extends React.Component {
172
121
queryUsed = UTILIZATION_STORAGE_USED_QUERY ;
173
122
}
174
123
}
175
-
176
- this . fetchPrometheusQuery ( queryTotal , response => this . setCapacityData ( 'storageTotal' , response ) ) ;
177
- this . fetchPrometheusQuery ( queryUsed , response => this . setUtilizationData ( 'storageUsed' , response ) ) ;
178
- } catch ( error ) {
179
- if ( this . _isMounted ) {
180
- this . setCapacityData ( 'storageTotal' , error ) ;
181
- this . setUtilizationData ( 'storageUsed' , error ) ;
182
- }
124
+ } finally {
125
+ this . fetchPrometheusQuery ( queryTotal , 'storageTotal' ) ;
126
+ this . fetchPrometheusQuery ( queryUsed , 'storageUsed' ) ;
183
127
}
184
128
}
185
129
186
- _setCephDiskStats ( key , response ) {
187
- this . setState ( state => ( {
188
- diskStats : {
189
- ...state . diskStats ,
190
- [ key ] : response ,
191
- } ,
192
- } ) ) ;
193
- }
194
-
195
130
async getPrometheusMetrics ( ) {
196
131
const url = `${ getPrometheusBaseURL ( ) } /api/v1/label/__name__/values` ;
197
132
return coFetchJSON ( url ) ;
@@ -202,20 +137,9 @@ export class ClusterOverview extends React.Component {
202
137
return coFetchJSON ( url ) ;
203
138
}
204
139
205
- fetchPrometheusQuery ( query , callback ) {
206
- this . getPrometheusQuery ( query ) . then ( result => {
207
- if ( this . _isMounted ) {
208
- callback ( result ) ;
209
- }
210
- } ) . catch ( error => {
211
- if ( this . _isMounted ) {
212
- callback ( error ) ;
213
- }
214
- } ) . then ( ( ) => {
215
- if ( this . _isMounted ) {
216
- setTimeout ( ( ) => this . fetchPrometheusQuery ( query , callback ) , REFRESH_TIMEOUT ) ;
217
- }
218
- } ) ;
140
+ fetchPrometheusQuery ( query , key ) {
141
+ const url = `${ getPrometheusBaseURL ( ) } /api/v1/query?query=${ encodeURIComponent ( query ) } ` ;
142
+ this . fetchAndStore ( url , key ) ;
219
143
}
220
144
221
145
fetchHealth ( callback ) {
@@ -234,45 +158,51 @@ export class ClusterOverview extends React.Component {
234
158
} ) ;
235
159
}
236
160
237
- async fetchAlerts ( ) {
161
+ fetchAlerts ( ) {
238
162
const url = `${ getAlertManagerBaseURL ( ) } /api/v2/alerts` ;
239
- let alertsResponse ;
163
+ this . fetchAndStore ( url , 'alertsResponse' ) ;
164
+ }
165
+
166
+
167
+ async fetchAndStore ( url , key ) {
168
+ let response ;
240
169
try {
241
- alertsResponse = await coFetchJSON ( url ) ;
170
+ response = await coFetchJSON ( url ) ;
242
171
} catch ( error ) {
243
- alertsResponse = error ;
172
+ response = error ;
244
173
} finally {
245
174
if ( this . _isMounted ) {
246
175
this . setState ( {
247
- alertsResponse ,
176
+ [ key ] : response ,
248
177
} ) ;
249
- setTimeout ( ( ) => this . fetchAlerts ( ) , REFRESH_TIMEOUT ) ;
178
+ setTimeout ( ( ) => this . fetchAndStore ( url , key ) , REFRESH_TIMEOUT ) ;
250
179
}
251
180
}
252
181
}
253
182
254
183
componentDidMount ( ) {
255
184
this . _isMounted = true ;
256
185
257
- this . fetchPrometheusQuery ( CONSUMERS_CPU_QUERY , response => this . setConsumersData ( 'workloadCpuResults' , response ) ) ;
258
- this . fetchPrometheusQuery ( CONSUMERS_MEMORY_QUERY , response => this . setConsumersData ( 'workloadMemoryResults' , response ) ) ;
259
- this . fetchPrometheusQuery ( NODE_CONSUMERS_MEMORY_QUERY , response => this . setConsumersData ( 'infraMemoryResults' , response ) ) ;
260
- this . fetchPrometheusQuery ( NODE_CONSUMERS_CPU_QUERY , response => this . setConsumersData ( 'infraCpuResults' , response ) ) ;
186
+ this . fetchPrometheusQuery ( CONSUMERS_CPU_QUERY , 'workloadCpuResults' ) ;
187
+ this . fetchPrometheusQuery ( CONSUMERS_MEMORY_QUERY , 'workloadMemoryResults' ) ;
188
+ this . fetchPrometheusQuery ( NODE_CONSUMERS_MEMORY_QUERY , 'infraMemoryResults' ) ;
189
+ this . fetchPrometheusQuery ( NODE_CONSUMERS_CPU_QUERY , 'infraCpuResults' ) ;
261
190
262
191
this . fetchHealth ( this . setHealthData ) ;
263
- this . fetchPrometheusQuery ( OPENSHIFT_VERSION_QUERY , response => this . setDetailsOpenshiftResponse ( response ) ) ;
264
192
265
- this . fetchPrometheusQuery ( CAPACITY_MEMORY_TOTAL_QUERY , response => this . setCapacityData ( 'memoryTotal' , response ) ) ;
266
- this . fetchPrometheusQuery ( CAPACITY_NETWORK_TOTAL_QUERY , response => this . setCapacityData ( 'networkTotal' , response ) ) ;
267
- this . fetchPrometheusQuery ( CAPACITY_NETWORK_USED_QUERY , response => this . setCapacityData ( 'networkUsed' , response ) ) ;
193
+ this . fetchPrometheusQuery ( OPENSHIFT_VERSION_QUERY , 'openshiftClusterVersionResponse' ) ;
194
+
195
+ this . fetchPrometheusQuery ( CAPACITY_MEMORY_TOTAL_QUERY , 'memoryTotal' ) ;
196
+ this . fetchPrometheusQuery ( CAPACITY_NETWORK_TOTAL_QUERY , 'networkTotal' ) ;
197
+ this . fetchPrometheusQuery ( CAPACITY_NETWORK_USED_QUERY , 'networkUsed' ) ;
268
198
269
- this . fetchPrometheusQuery ( CEPH_OSD_UP_QUERY , response => this . setCephDiskStats ( 'cephOsdUp' , response ) ) ;
270
- this . fetchPrometheusQuery ( CEPH_OSD_DOWN_QUERY , response => this . setCephDiskStats ( 'cephOsdDown' , response ) ) ;
199
+ this . fetchPrometheusQuery ( CEPH_OSD_UP_QUERY , 'cephOsdUp' ) ;
200
+ this . fetchPrometheusQuery ( CEPH_OSD_DOWN_QUERY , 'cephOsdDown' ) ;
271
201
272
202
this . getStorageMetrics ( ) ;
273
203
274
- this . fetchPrometheusQuery ( UTILIZATION_CPU_USED_QUERY , response => this . setUtilizationData ( 'cpuUtilization' , response ) ) ;
275
- this . fetchPrometheusQuery ( UTILIZATION_MEMORY_USED_QUERY , response => this . setUtilizationData ( 'memoryUtilization' , response ) ) ;
204
+ this . fetchPrometheusQuery ( UTILIZATION_CPU_USED_QUERY , 'cpuUtilization' ) ;
205
+ this . fetchPrometheusQuery ( UTILIZATION_MEMORY_USED_QUERY , 'memoryUtilization' ) ;
276
206
this . fetchAlerts ( ) ;
277
207
}
278
208
@@ -281,35 +211,18 @@ export class ClusterOverview extends React.Component {
281
211
}
282
212
283
213
render ( ) {
284
- const {
285
- openshiftClusterVersions,
286
- healthData,
287
- consumersData,
288
- capacityData,
289
- utilizationData,
290
- alertsResponse,
291
- diskStats,
292
- } = this . state ;
293
-
294
214
const inventoryResourceMapToProps = resources => {
295
215
return {
296
216
value : {
297
217
LoadingComponent : LoadingInline ,
298
218
...resources ,
299
- openshiftClusterVersions,
300
- ...capacityData ,
301
- ...consumersData ,
219
+ ...this . state ,
302
220
303
221
eventsData : {
304
222
Component : OverviewEventStream ,
305
223
loaded : true ,
306
224
} ,
307
- healthData,
308
-
309
- ...utilizationData ,
310
225
complianceData, // TODO: mock, replace by real data and remove from web-ui-components
311
- alertsResponse,
312
- diskStats,
313
226
} ,
314
227
} ;
315
228
} ;
0 commit comments