@@ -3,10 +3,29 @@ const config = require('config');
33const { Mutex, withTimeout, E_TIMEOUT } = require ( 'async-mutex' ) ;
44const apiKeys = require ( './apiKey' ) ;
55const path = require ( "path" ) ;
6+ const opentelemetry = require ( "@opentelemetry/api" ) ;
67const logger = require ( '../logger' ) . logger ;
78
89const GET_LOCATIONS = 'http://www.webpagetest.org/getLocations.php?f=json' ;
910
11+ const WstMeter = opentelemetry . metrics . getMeter ( 'default' ) ;
12+ const locationMetrics = {
13+ total : WstMeter . createGauge ( 'location.total' ) ,
14+ lastUpdate : WstMeter . createGauge ( 'location.last_update' ) ,
15+ ratio : WstMeter . createGauge ( 'location.ratio' ) ,
16+ score : WstMeter . createGauge ( 'location.score' ) ,
17+ selected : WstMeter . createGauge ( 'location.selected' ) ,
18+ agent : {
19+ total : WstMeter . createGauge ( 'location.agent.total' ) ,
20+ idle : WstMeter . createGauge ( 'location.agent.idle' ) ,
21+ queued : WstMeter . createGauge ( 'location.agent.queued' ) ,
22+ highprio : WstMeter . createGauge ( 'location.agent.highprio' ) ,
23+ lowprio : WstMeter . createGauge ( 'location.agent.lowprio' ) ,
24+ testing : WstMeter . createGauge ( 'location.agent.testing' ) ,
25+ blocking : WstMeter . createGauge ( 'location.agent.blocking' )
26+ } ,
27+ } ;
28+
1029class LocationSelector {
1130 constructor ( ) {
1231 if ( ! LocationSelector . instance ) {
@@ -111,6 +130,26 @@ class LocationSelector {
111130 this . location = this . getBestLocationId ( filtered ) ;
112131 this . cachedAllLocations = filtered ;
113132 this . lastUpdated = Date . now ( ) ;
133+
134+ // telemetry
135+ locationMetrics . total . record ( this . cachedAllLocations . length ) ;
136+ locationMetrics . lastUpdate . record ( this . lastUpdated ) ;
137+ this . cachedAllLocations . forEach ( ( loc ) => {
138+ let labels = { location : loc . location } ;
139+
140+ locationMetrics . ratio . record ( loc . PendingTests . TestAgentRatio , labels ) ;
141+ locationMetrics . score . record ( loc . score , labels ) ;
142+
143+ locationMetrics . selected . record ( loc . location === this . location ? 1 : 0 , labels ) ;
144+
145+ locationMetrics . agent . total . record ( loc . PendingTests . Total , labels ) ;
146+ locationMetrics . agent . idle . record ( loc . PendingTests . Idle , labels ) ;
147+ locationMetrics . agent . queued . record ( loc . PendingTests . Queued , labels ) ;
148+ locationMetrics . agent . highprio . record ( loc . PendingTests . HighPriority , labels ) ;
149+ locationMetrics . agent . lowprio . record ( loc . PendingTests . LowPriority , labels ) ;
150+ locationMetrics . agent . testing . record ( loc . PendingTests . Testing , labels ) ;
151+ locationMetrics . agent . blocking . record ( loc . PendingTests . Blocking , labels ) ;
152+ } ) ;
114153 } ;
115154
116155 async getLocation ( ) {
0 commit comments