Skip to content

Commit

Permalink
extract clusters from response
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Sep 7, 2023
1 parent 66c3f08 commit ee221cd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@

import React, { Component } from 'react';
import type { RequestDetailsProps } from '../../types';
import { getLocalClusterDetails } from './utils';

export class Clusters extends Component<RequestDetailsProps> {
static shouldShow = (request: Request) =>
Boolean(request.response?.json);

render() {
console.log(this.props);
const rawResponse = this.props.request.response?.json?.rawResponse;
if (!rawResponse) {
return null;
}

const clusters = rawResponse._clusters
? (
rawResponse._clusters as estypes.ClusterStatistics & {
details: Record<string, ClusterDetails>;
}
).details
: {
local: getLocalClusterDetails(rawResponse)
};
console.log(clusters);

return this.props.request.response?.json
? <div>Cluster details go here</div>
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { estypes } from '@elastic/elasticsearch';

function getLocalClusterStatus(rawResponse: estypes.SearchResponse): estypes.ClusterSearchStatus {
if (rawResponse.error) {
return 'failed';
}

if (rawResponse.timed_out || rawResponse._shards.failed) {
return 'partial';
}

return 'successful';
}

export function getLocalClusterDetails(rawResponse: estypes.SearchResponse) {
const shards = {
...rawResponse._shards,
};
delete shards.failures;
return {
status: getLocalClusterStatus(rawResponse),
indices: '',
took: rawResponse.took,
timed_out: rawResponse.timed_out,
_shards: shards,
failures: rawResponse._shards.failures,
};
}

0 comments on commit ee221cd

Please sign in to comment.