2222 * that defined in Kibana's package.json.
2323 */
2424
25- import { coerce } from 'semver' ;
26- import { interval } from 'rxjs' ;
27- import { map , switchMap , catchError , distinctUntilChanged } from 'rxjs/operators' ;
28- import { isEsCompatibleWithKibana } from './is_es_compatible_with_kibana' ;
25+ import { interval , from } from 'rxjs' ;
26+ import { map , switchMap , distinctUntilChanged , catchError , startWith } from 'rxjs/operators' ;
27+ import {
28+ esVersionCompatibleWithKibana ,
29+ esVersionEqualsKibana ,
30+ } from './es_kibana_version_compatability' ;
2931import { Logger } from '../../logging' ;
3032import { APICaller } from '..' ;
3133
@@ -37,12 +39,6 @@ export interface PollEsNodesVersionOptions {
3739 esVersionCheckInterval : number ;
3840}
3941
40- export interface NodesInfo {
41- nodes : {
42- [ key : string ] : NodeInfo ;
43- } ;
44- }
45-
4642interface NodeInfo {
4743 version : string ;
4844 ip : string ;
@@ -52,6 +48,12 @@ interface NodeInfo {
5248 name : string ;
5349}
5450
51+ export interface NodesInfo {
52+ nodes : {
53+ [ key : string ] : NodeInfo ;
54+ } ;
55+ }
56+
5557export interface NodesVersionCompatibility {
5658 isCompatible : boolean ;
5759 message ?: string ;
@@ -77,18 +79,14 @@ export function mapNodesVersionCompatibility(
7779
7880 // Aggregate incompatible ES nodes.
7981 const incompatibleNodes = nodes . filter (
80- node => ! isEsCompatibleWithKibana ( node . version , kibanaVersion )
82+ node => ! esVersionCompatibleWithKibana ( node . version , kibanaVersion )
8183 ) ;
8284
8385 // Aggregate ES nodes which should prompt a Kibana upgrade. It's acceptable
84- // if ES and Kibana versions are not the same so long as they are not
86+ // if ES and Kibana versions are not the same as long as they are not
8587 // incompatible, but we should warn about it.
8688 // Ignore version qualifiers https://github.com/elastic/elasticsearch/issues/36859
87- const warningNodes = nodes . filter ( node => {
88- const nodeSemVer = coerce ( node . version ) ;
89- const kibanaSemver = coerce ( kibanaVersion ) ;
90- return nodeSemVer && kibanaSemver && nodeSemVer . version !== kibanaSemver . version ;
91- } ) ;
89+ const warningNodes = nodes . filter ( node => ! esVersionEqualsKibana ( node . version , kibanaVersion ) ) ;
9290
9391 let message ;
9492 if ( incompatibleNodes . length > 0 ) {
@@ -115,6 +113,18 @@ export function mapNodesVersionCompatibility(
115113 } ;
116114}
117115
116+ // Returns true if two NodesVersionCompatibility entries match
117+ function compareNodes ( prev : NodesVersionCompatibility , curr : NodesVersionCompatibility ) {
118+ const nodesEqual = ( n : NodeInfo , m : NodeInfo ) => n . ip === m . ip && n . version === m . version ;
119+ return (
120+ curr . isCompatible === prev . isCompatible &&
121+ curr . incompatibleNodes . length === prev . incompatibleNodes . length &&
122+ curr . warningNodes . length === prev . warningNodes . length &&
123+ curr . incompatibleNodes . every ( ( node , i ) => nodesEqual ( node , prev . incompatibleNodes [ i ] ) ) &&
124+ curr . warningNodes . every ( ( node , i ) => nodesEqual ( node , prev . warningNodes [ i ] ) )
125+ ) ;
126+ }
127+
118128export const pollEsNodesVersion = ( {
119129 callWithInternalUser,
120130 log,
@@ -130,22 +140,21 @@ export const pollEsNodesVersion = ({
130140 filterPath : [ 'nodes.*.version' , 'nodes.*.http.publish_address' , 'nodes.*.ip' ] ,
131141 } ) ;
132142 } ) ,
133- // Log, but otherwise ignore 'nodes.info' request errors
134- catchError ( ( err , caught$ ) => {
135- log . error ( 'Unable to retrieve version information from Elasticsearch nodes.' , err ) ;
136- return caught$ ;
137- } ) ,
138143 map ( ( nodesInfo : NodesInfo ) =>
139144 mapNodesVersionCompatibility ( nodesInfo , kibanaVersion , ignoreVersionMismatch )
140145 ) ,
141- // Only emit if the IP or version numbers of the nodes changed from the
142- // previous result.
143- distinctUntilChanged ( ( prev , curr ) => {
144- const nodesEqual = ( n : NodeInfo , m : NodeInfo ) => n . ip === m . ip && n . version === m . version ;
145- return (
146- curr . incompatibleNodes . every ( ( node , i ) => nodesEqual ( node , prev . incompatibleNodes [ i ] ) ) &&
147- curr . warningNodes . every ( ( node , i ) => nodesEqual ( node , prev . warningNodes [ i ] ) )
146+ catchError ( ( _err , caught$ ) => {
147+ // Return `isCompatible=false` when there's a 'nodes.info' request error
148+ return caught$ . pipe (
149+ startWith ( {
150+ isCompatible : false ,
151+ message : 'Unable to retrieve version information from Elasticsearch nodes.' ,
152+ incompatibleNodes : [ ] ,
153+ warningNodes : [ ] ,
154+ kibanaVersion,
155+ } )
148156 ) ;
149- } )
157+ } ) ,
158+ distinctUntilChanged ( compareNodes ) // Only emit if there are new nodes or versions
150159 ) ;
151160} ;
0 commit comments