@@ -16,6 +16,7 @@ import {
1616 SnapshotRequest ,
1717 SnapshotNodePath ,
1818 SnapshotNodeMetric ,
19+ SnapshotNode ,
1920} from '../../../../common/http_api' ;
2021import { META_KEY } from './constants' ;
2122import { InfraSource } from '../../../lib/sources' ;
@@ -47,42 +48,49 @@ export const transformMetricsApiResponseToSnapshotResponse = (
4748 source : InfraSource ,
4849 metricsApiResponse : MetricsAPIResponse
4950) : SnapshotNodeResponse => {
50- const nodes = metricsApiResponse . series . map ( ( series ) => {
51- const node = {
52- metrics : options . metrics
53- . filter ( ( m ) => m . id !== META_KEY )
54- . map ( ( metric ) => {
55- const name = metric . id as SnapshotMetricType ;
56- const timeseries = {
57- id : name ,
58- columns : [
59- { name : 'timestamp' , type : 'date' as MetricsExplorerColumnType } ,
60- { name : 'metric_0' , type : 'number' as MetricsExplorerColumnType } ,
61- ] ,
62- rows : series . rows . map ( ( row ) => {
63- return { timestamp : row . timestamp , metric_0 : get ( row , metric . id , null ) } ;
64- } ) ,
65- } ;
66- const maxValue = calculateMax ( timeseries . rows ) ;
67- const avg = calculateAvg ( timeseries . rows ) ;
68- const value = getLastValue ( timeseries . rows ) ;
69- const nodeMetric : SnapshotNodeMetric = { name, max : maxValue , value, avg } ;
70- if ( snapshotRequest . includeTimeseries ) {
71- nodeMetric . timeseries = timeseries ;
72- }
73- return nodeMetric ;
74- } ) ,
75- path :
76- series . keys ?. map ( ( key ) => {
77- return { value : key , label : key } as SnapshotNodePath ;
78- } ) ?? [ ] ,
79- name : '' ,
80- } ;
51+ const nodes = metricsApiResponse . series
52+ . map ( ( series ) => {
53+ const node = {
54+ metrics : options . metrics
55+ . filter ( ( m ) => m . id !== META_KEY )
56+ . map ( ( metric ) => {
57+ const name = metric . id as SnapshotMetricType ;
58+ const timeseries = {
59+ id : name ,
60+ columns : [
61+ { name : 'timestamp' , type : 'date' as MetricsExplorerColumnType } ,
62+ { name : 'metric_0' , type : 'number' as MetricsExplorerColumnType } ,
63+ ] ,
64+ rows : series . rows . map ( ( row ) => {
65+ return { timestamp : row . timestamp , metric_0 : get ( row , metric . id , null ) } ;
66+ } ) ,
67+ } ;
68+ const maxValue = calculateMax ( timeseries . rows ) ;
69+ const avg = calculateAvg ( timeseries . rows ) ;
70+ const value = getLastValue ( timeseries . rows ) ;
71+ const nodeMetric : SnapshotNodeMetric = { name, max : maxValue , value, avg } ;
72+ if ( snapshotRequest . includeTimeseries ) {
73+ nodeMetric . timeseries = timeseries ;
74+ }
75+ return nodeMetric ;
76+ } ) ,
77+ path :
78+ series . keys ?. map ( ( key ) => {
79+ return { value : key , label : key } as SnapshotNodePath ;
80+ } ) ?? [ ] ,
81+ name : '' ,
82+ } ;
8183
82- const path = applyMetadataToLastPath ( series , node , snapshotRequest , source ) ;
83- const lastPath = last ( path ) ;
84- const name = ( lastPath && lastPath . label ) || 'N/A' ;
85- return { ...node , path, name } ;
86- } ) ;
84+ const isNoData = node . metrics . every ( ( m ) => m . value === null ) ;
85+ const isAPMNode = series . metricsets ?. includes ( 'app' ) ;
86+ if ( isNoData && isAPMNode ) return null ;
87+
88+ const path = applyMetadataToLastPath ( series , node , snapshotRequest , source ) ;
89+ const lastPath = last ( path ) ;
90+ const name = ( lastPath && lastPath . label ) || 'N/A' ;
91+
92+ return { ...node , path, name } ;
93+ } )
94+ . filter ( ( n ) => n !== null ) as SnapshotNode [ ] ;
8795 return { nodes, interval : `${ metricsApiResponse . info . interval } s` } ;
8896} ;
0 commit comments