| 
									
										
										
										
											2018-11-19 23:06:30 +08:00
										 |  |  | import uniqBy from 'lodash/uniqBy'; | 
					
						
							| 
									
										
										
										
											2018-10-31 20:55:40 +08:00
										 |  |  | import { alignOptions, aggOptions } from './constants'; | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 23:06:30 +08:00
										 |  |  | export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  | export const getMetricTypesByService = (metricDescriptors, service) => | 
					
						
							|  |  |  |   metricDescriptors.filter(m => m.service === service); | 
					
						
							| 
									
										
										
										
											2018-10-29 23:27:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 21:44:40 +08:00
										 |  |  | export const getMetricTypes = (metricDescriptors, metricType, interpolatedMetricType, selectedService) => { | 
					
						
							| 
									
										
										
										
											2018-10-31 20:36:41 +08:00
										 |  |  |   const metricTypes = getMetricTypesByService(metricDescriptors, selectedService).map(m => ({ | 
					
						
							| 
									
										
										
										
											2018-10-31 20:07:57 +08:00
										 |  |  |     value: m.type, | 
					
						
							|  |  |  |     name: m.displayName, | 
					
						
							|  |  |  |   })); | 
					
						
							| 
									
										
										
										
											2018-11-19 21:44:40 +08:00
										 |  |  |   const metricTypeExistInArray = metricTypes.some(m => m.value === interpolatedMetricType); | 
					
						
							| 
									
										
										
										
											2018-11-01 17:14:28 +08:00
										 |  |  |   const selectedMetricType = metricTypeExistInArray ? metricType : metricTypes[0].value; | 
					
						
							| 
									
										
										
										
											2018-10-31 20:07:57 +08:00
										 |  |  |   return { | 
					
						
							|  |  |  |     metricTypes, | 
					
						
							| 
									
										
										
										
											2018-10-31 20:36:41 +08:00
										 |  |  |     selectedMetricType, | 
					
						
							| 
									
										
										
										
											2018-10-31 20:07:57 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 23:27:53 +08:00
										 |  |  | export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => { | 
					
						
							|  |  |  |   return !metricValueType | 
					
						
							|  |  |  |     ? [] | 
					
						
							|  |  |  |     : alignOptions.filter(i => { | 
					
						
							|  |  |  |         return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-10-29 23:57:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getAggregationOptionsByMetric = (valueType, metricKind) => { | 
					
						
							|  |  |  |   return !metricKind | 
					
						
							|  |  |  |     ? [] | 
					
						
							|  |  |  |     : aggOptions.filter(i => { | 
					
						
							|  |  |  |         return i.valueTypes.indexOf(valueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-19 21:44:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getLabelKeys = async (datasource, selectedMetricType) => { | 
					
						
							|  |  |  |   const refId = 'handleLabelKeysQuery'; | 
					
						
							|  |  |  |   const response = await datasource.getLabels(selectedMetricType, refId); | 
					
						
							|  |  |  |   const labelKeys = response.meta | 
					
						
							|  |  |  |     ? [ | 
					
						
							|  |  |  |         ...Object.keys(response.meta.resourceLabels).map(l => `resource.label.${l}`), | 
					
						
							|  |  |  |         ...Object.keys(response.meta.metricLabels).map(l => `metric.label.${l}`), | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     : []; | 
					
						
							|  |  |  |   return labelKeys; | 
					
						
							|  |  |  | }; |