@@ -83,6 +83,22 @@ const pageinfoMiddleware = (req, res, next) => {
83
83
return next ( )
84
84
}
85
85
86
+ // THIS IS AN EXPERIMENT. THIS CODE WILL BE DELETED IN THE NEAR FUTURE.
87
+ // The cache-control headers (and surrogate-control) are set to be
88
+ // aggressive. That means that in theory, after a deployment, when Fastly
89
+ // has been purged accordingly, the next time a pageinfo is requested,
90
+ // it'll come here to the backend code and produce the JSON response,
91
+ // and once it's done it once, it won't be needed again, because,
92
+ // in theory, the CDN will have cached it.
93
+ // But pageinfo requests are very frequent. So frequent that sometimes,
94
+ // the delay of CDN is longer than the chance of it being requested again
95
+ // from the backend. This can possibly still happen even with a origin
96
+ // shield.
97
+ // In this experiment we want to measure how often this happens.
98
+ // We are going to test how often the CDN requests the *same* pageinfo from the
99
+ // backend.
100
+ const CACHEABLE_PATHNAMES = new Map ( )
101
+
86
102
router . get (
87
103
'/v1' ,
88
104
validationMiddleware ,
@@ -159,8 +175,20 @@ router.get(
159
175
intro,
160
176
}
161
177
162
- const tags = [ 'version:v1' , `pathname:${ pathname } ` ]
163
- statsd . increment ( 'api.pageinfo' , 1 , tags )
178
+ const tags = [
179
+ // According to https://docs.datadoghq.com/getting_started/tagging/#define-tags
180
+ // the max length of a tag is 200 characters. Most of ours are less than
181
+ // that but we truncate just to be safe.
182
+ `pathname:${ pathname } ` . slice ( 0 , 200 ) ,
183
+ ]
184
+ statsd . increment ( 'pageinfo.lookup' , 1 , tags )
185
+
186
+ // See lengthy comment above about the experiment and the
187
+ // CACHEABLE_PATHNAMES global Map object.
188
+ if ( CACHEABLE_PATHNAMES . has ( pathname ) ) {
189
+ statsd . increment ( 'pageinfo.cacheable' , CACHEABLE_PATHNAMES . get ( pathname ) , tags )
190
+ }
191
+ CACHEABLE_PATHNAMES . set ( pathname , ( CACHEABLE_PATHNAMES . get ( pathname ) || 0 ) + 1 )
164
192
165
193
defaultCacheControl ( res )
166
194
0 commit comments