Skip to content

Commit

Permalink
Fix tests and types
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 19, 2021
1 parent e6ba004 commit 34c838f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function fetchClusterStats(req: LegacyRequest, esIndexPattern: string, clusterUu
* @return {Array} Objects representing each cluster.
*/
export function handleClusterStats(response: ElasticsearchResponse) {
const hits = response.hits?.hits ?? [];
const hits = response?.hits?.hits ?? [];

return hits
.map((hit) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function handleResponse(
shardStats: any
) {
// map the hits
const hits = resp.hits?.hits ?? [];
const hits = resp?.hits?.hits ?? [];
return hits.map((hit) => {
const stats = hit._source.index_stats;
const earliestStats = hit.inner_hits?.earliest?.hits?.hits[0]?._source.index_stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { ElasticsearchResponse, ElasticsearchModifiedSource } from '../../../../
*/
export function handleResponse(
response: ElasticsearchResponse,
clusterStats: ElasticsearchModifiedSource,
nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } },
clusterStats: ElasticsearchModifiedSource | undefined,
nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } } | undefined,
pageOfNodes: Array<{ uuid: string }>,
timeOptions = {}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
*/
export function mapNodesInfo(
nodeHits: ElasticsearchResponseHit[],
clusterStats: ElasticsearchModifiedSource,
nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } }
clusterStats?: ElasticsearchModifiedSource,
nodesShardCount?: { nodes: { [nodeId: string]: { shardCount: number } } }
) {
const clusterState = clusterStats.cluster_state ?? { nodes: {} };
const clusterState = clusterStats?.cluster_state ?? { nodes: {} };

return nodeHits.reduce((prev, node) => {
const sourceNode = node._source.source_node || node._source.elasticsearch?.node;
Expand All @@ -50,7 +50,7 @@ export function mapNodesInfo(
isOnline,
nodeTypeLabel,
nodeTypeClass,
shardCount: nodesShardCount.nodes[uuid]?.shardCount ?? 0,
shardCount: nodesShardCount?.nodes[uuid]?.shardCount ?? 0,
},
};
}, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { merge } from 'lodash';
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { calculateAvailability } from '../calculate_availability';
import { LegacyRequest, ElasticsearchResponse } from '../../types';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';

export function handleResponse(resp: ElasticsearchResponse) {
const source = resp.hits?.hits[0]?._source?.logstash_stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import { createQuery } from '../create_query';
// @ts-ignore
import { LogstashMetric } from '../metrics';
import { LegacyRequest, ElasticsearchResponse } from '../../types';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';

export async function getPipelineStateDocument(
req: LegacyRequest,
Expand Down

0 comments on commit 34c838f

Please sign in to comment.