functions.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { alignOptions, aggOptions } from './constants';
  2. export const getMetricTypesByService = (metricDescriptors, service) =>
  3. metricDescriptors.filter(m => m.service === service);
  4. export const getMetricTypes = (metricDescriptors, metricType, interpolatedMetricType, selectedService) => {
  5. const metricTypes = getMetricTypesByService(metricDescriptors, selectedService).map(m => ({
  6. value: m.type,
  7. name: m.displayName,
  8. }));
  9. const metricTypeExistInArray = metricTypes.some(m => m.value === interpolatedMetricType);
  10. const selectedMetricType = metricTypeExistInArray ? metricType : metricTypes[0].value;
  11. return {
  12. metricTypes,
  13. selectedMetricType,
  14. };
  15. };
  16. export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => {
  17. return !metricValueType
  18. ? []
  19. : alignOptions.filter(i => {
  20. return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
  21. });
  22. };
  23. export const getAggregationOptionsByMetric = (valueType, metricKind) => {
  24. return !metricKind
  25. ? []
  26. : aggOptions.filter(i => {
  27. return i.valueTypes.indexOf(valueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
  28. });
  29. };
  30. export const getLabelKeys = async (datasource, selectedMetricType) => {
  31. const refId = 'handleLabelKeysQuery';
  32. const response = await datasource.getLabels(selectedMetricType, refId);
  33. const labelKeys = response.meta
  34. ? [
  35. ...Object.keys(response.meta.resourceLabels).map(l => `resource.label.${l}`),
  36. ...Object.keys(response.meta.metricLabels).map(l => `metric.label.${l}`),
  37. ]
  38. : [];
  39. return labelKeys;
  40. };