1
- import { isEqualIgnoreFunctions } from '@hypertrace/common' ;
1
+ import { Color , isEqualIgnoreFunctions } from '@hypertrace/common' ;
2
2
import { GraphQlTimeRange , MetricAggregationType } from '@hypertrace/distributed-tracing' ;
3
3
import { GraphQlRequestCacheability , GraphQlRequestOptions } from '@hypertrace/graphql-client' ;
4
4
import { ModelApi } from '@hypertrace/hyperdash' ;
@@ -8,6 +8,10 @@ import {
8
8
ENTITY_TOPOLOGY_GQL_REQUEST ,
9
9
TopologyNodeSpecification
10
10
} from '../../../../graphql/request/handlers/entities/query/topology/entity-topology-graphql-query-handler.service' ;
11
+ import { MetricAggregationSpecificationModel } from '../specifiers/metric-aggregation-specification.model' ;
12
+ import { TopologyMetricCategoryModel } from './metrics/topology-metric-category.model' ;
13
+ import { TopologyMetricWithCategoryModel } from './metrics/topology-metric-with-category.model' ;
14
+ import { TopologyMetricsModel } from './metrics/topology-metrics.model' ;
11
15
import { TopologyDataSourceModel } from './topology-data-source.model' ;
12
16
13
17
describe ( 'topology data source model' , ( ) => {
@@ -17,6 +21,57 @@ describe('topology data source model', () => {
17
21
let lastEmittedQuery : unknown ;
18
22
let lastEmittedQueryRequestOption : GraphQlRequestOptions | undefined ;
19
23
24
+ const createCategoryModel = (
25
+ name : string ,
26
+ minValue : number ,
27
+ fillColor : Color ,
28
+ strokeColor : Color ,
29
+ focusColor : Color ,
30
+ maxValue ?: number
31
+ ) : TopologyMetricCategoryModel => {
32
+ const categoryModel = new TopologyMetricCategoryModel ( ) ;
33
+ categoryModel . name = name ;
34
+ categoryModel . minValue = minValue ;
35
+ categoryModel . maxValue = maxValue ;
36
+ categoryModel . fillColor = fillColor ;
37
+ categoryModel . strokeColor = strokeColor ;
38
+ categoryModel . focusColor = focusColor ;
39
+
40
+ return categoryModel ;
41
+ } ;
42
+
43
+ const createSpecificationModel = ( metric : string , aggregation : MetricAggregationType ) => {
44
+ const specification = new MetricAggregationSpecificationModel ( ) ;
45
+ specification . metric = metric ;
46
+ specification . aggregation = aggregation ;
47
+
48
+ specification . modelOnInit ( ) ;
49
+
50
+ return specification ;
51
+ } ;
52
+
53
+ const createMetricWithCategory = (
54
+ spec : MetricAggregationSpecificationModel ,
55
+ categories : TopologyMetricCategoryModel [ ]
56
+ ) => {
57
+ const withCategoryModel = new TopologyMetricWithCategoryModel ( ) ;
58
+ withCategoryModel . specification = spec ;
59
+ withCategoryModel . categories = categories ;
60
+
61
+ return withCategoryModel ;
62
+ } ;
63
+
64
+ const createTopologyMetricsModel = ( metric : string , aggregation : MetricAggregationType ) => {
65
+ const primary = createMetricWithCategory ( createSpecificationModel ( metric , aggregation ) , [
66
+ createCategoryModel ( metric , 0 , Color . Blue2 , Color . Blue3 , Color . Blue4 , 10 )
67
+ ] ) ;
68
+
69
+ const metricsModel : TopologyMetricsModel = new TopologyMetricsModel ( ) ;
70
+ metricsModel . primary = primary ;
71
+
72
+ return metricsModel ;
73
+ } ;
74
+
20
75
beforeEach ( ( ) => {
21
76
const mockApi : Partial < ModelApi > = {
22
77
getTimeRange : jest . fn ( ( ) => testTimeRange )
@@ -25,12 +80,9 @@ describe('topology data source model', () => {
25
80
model . downstreamEntityTypes = [ ObservabilityEntityType . Api , ObservabilityEntityType . Backend ] ;
26
81
model . upstreamEntityTypes = [ ObservabilityEntityType . Service ] ;
27
82
model . entityType = ObservabilityEntityType . Service ;
28
- model . nodeMetricSpecifications = [
29
- specBuilder . metricAggregationSpecForKey ( 'numCalls' , MetricAggregationType . Average )
30
- ] ;
31
- model . edgeMetricSpecifications = [
32
- specBuilder . metricAggregationSpecForKey ( 'duration' , MetricAggregationType . Average )
33
- ] ;
83
+ model . nodeMetricsModel = createTopologyMetricsModel ( 'numCalls' , MetricAggregationType . Average ) ;
84
+ model . edgeMetricsModel = createTopologyMetricsModel ( 'duration' , MetricAggregationType . Average ) ;
85
+
34
86
model . api = mockApi as ModelApi ;
35
87
model . query$ . subscribe ( query => {
36
88
lastEmittedQuery = query . buildRequest ( [ ] ) ;
0 commit comments