@@ -2,11 +2,13 @@ import { DateTime } from 'luxon';
22import { SettingsConfigurable , ISettingsSubscriber , SettingsSubscription } from '../settings/ISettingsSubscriber' ;
33import { DefaultSettings , ProfileSettings } from '../settings/Settings' ;
44import { LoggerFactory } from '../telemetry/LoggerFactory' ;
5+ import { TelemetryService } from '../telemetry/TelemetryService' ;
56import { Closeable } from '../utils/Closeable' ;
67import { AwsRegion , getRegion } from '../utils/Region' ;
78import { CombinedSchemas } from './CombinedSchemas' ;
89import { GetSchemaTaskManager } from './GetSchemaTaskManager' ;
910import { RegionalSchemasType } from './RegionalSchemas' ;
11+ import { SamSchemasType , SamStoreKey } from './SamSchemas' ;
1012import { SchemaStore } from './SchemaStore' ;
1113
1214const StaleDaysThreshold = 7 ;
@@ -16,6 +18,7 @@ export class SchemaRetriever implements SettingsConfigurable, Closeable {
1618 private settingsSubscription ?: SettingsSubscription ;
1719 private settings : ProfileSettings = DefaultSettings . profile ;
1820 private readonly log = LoggerFactory . getLogger ( SchemaRetriever ) ;
21+ private readonly telemetry = TelemetryService . instance . get ( 'SchemaRetriever' ) ;
1922
2023 constructor (
2124 private readonly schemaTaskManager : GetSchemaTaskManager ,
@@ -35,6 +38,7 @@ export class SchemaRetriever implements SettingsConfigurable, Closeable {
3538 // Initialize schemas with current region
3639 this . getRegionalSchemasIfMissing ( [ this . settings . region ] ) ;
3740 this . getRegionalSchemasIfStale ( ) ;
41+ this . getSamSchemasIfMissingOrStale ( ) ;
3842
3943 // Subscribe to profile settings changes
4044 this . settingsSubscription = settingsManager . subscribe ( 'profile' , ( newProfileSettings ) => {
@@ -120,9 +124,36 @@ export class SchemaRetriever implements SettingsConfigurable, Closeable {
120124 const lastModified = DateTime . fromMillis ( existingValue . lastModifiedMs ) ;
121125 const isStale = now . diff ( lastModified , 'days' ) . days >= StaleDaysThreshold ;
122126
127+ const ageMs = now . diff ( lastModified ) . milliseconds ;
128+ this . telemetry . histogram ( 'schema.public.maxAge' , ageMs , {
129+ unit : 'ms' ,
130+ } ) ;
131+
123132 if ( isStale ) {
124133 this . schemaTaskManager . addTask ( region ) ;
125134 }
126135 }
127136 }
137+
138+ private getSamSchemasIfMissingOrStale ( ) {
139+ const existingValue = this . schemaStore . samSchemas . get < SamSchemasType > ( SamStoreKey ) ;
140+
141+ if ( existingValue === undefined ) {
142+ this . schemaTaskManager . runSamTask ( ) ;
143+ return ;
144+ }
145+
146+ const now = DateTime . now ( ) ;
147+ const lastModified = DateTime . fromMillis ( existingValue . lastModifiedMs ) ;
148+ const isStale = now . diff ( lastModified , 'days' ) . days >= StaleDaysThreshold ;
149+
150+ const ageMs = now . diff ( lastModified ) . milliseconds ;
151+ this . telemetry . histogram ( 'schema.sam.maxAge' , ageMs , {
152+ unit : 'ms' ,
153+ } ) ;
154+
155+ if ( isStale ) {
156+ this . schemaTaskManager . runSamTask ( ) ;
157+ }
158+ }
128159}
0 commit comments