Skip to content

Commit

Permalink
[Stack Monitoring] Remove unexpected docs from persistentMetricsetsQu…
Browse files Browse the repository at this point in the history
…ery portion of health API response (#134976)
  • Loading branch information
matschaffer authored Jun 23, 2022
1 parent 88c25a9 commit ecc1ec9
Showing 1 changed file with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,37 @@ export const monitoredClustersQuery = ({ timeRange, timeout }: QueryOptions) =>
};

/**
* some metricset documents use a stable ID to maintain a single occurence of
* some metricset documents use a stable ID to maintain a single occurrence of
* the documents in the index. we query those metricsets separately without
* a time range filter
*/
export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => {
const shardMatches = [
{
term: {
type: 'shards',
},
},
{
term: {
'metricset.name': 'shard',
},
},
];

const logstashStateMatches = [
{
term: {
type: 'logstash_state',
},
},
{
term: {
'metricset.name': 'node',
},
},
];

const metricsetsAggregations = {
elasticsearch: {
terms: {
Expand All @@ -71,18 +97,7 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => {
shard: lastSeenByIndex({
filter: {
bool: {
should: [
{
term: {
type: 'shards',
},
},
{
term: {
'metricset.name': 'shard',
},
},
],
should: shardMatches,
},
},
}),
Expand All @@ -98,27 +113,28 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => {
node: lastSeenByIndex({
filter: {
bool: {
should: [
{
term: {
type: 'logstash_state',
},
},
{
term: {
'metricset.name': 'node',
},
},
],
should: logstashStateMatches,
},
},
}),
},
},
};

// Outer query on expected types to avoid catching kibana internal collection documents containing source_node.uuid
return {
timeout: `${timeout}s`,
query: {
bool: {
filter: [
{
bool: {
should: shardMatches.concat(logstashStateMatches),
},
},
],
},
},
aggs: {
clusters: {
terms: clusterUuidTerm,
Expand Down

0 comments on commit ecc1ec9

Please sign in to comment.