@@ -11,6 +11,7 @@ import (
1111 "time"
1212
1313 lru "github.com/hashicorp/golang-lru/v2"
14+ "github.com/hashicorp/golang-lru/v2/expirable"
1415 _ "github.com/microsoft/go-mssqldb" // register Db driver
1516 _ "github.com/microsoft/go-mssqldb/integratedauth/krb5" // register Db driver
1617 "go.opentelemetry.io/collector/component"
@@ -59,6 +60,7 @@ func createDefaultConfig() component.Config {
5960 MaxQuerySampleCount : 1000 ,
6061 TopQueryCount : 200 ,
6162 CollectionInterval : time .Minute ,
63+ QueryPlanCacheTTL : time .Hour ,
6264 },
6365 }
6466}
@@ -132,7 +134,7 @@ func setupSQLServerScrapers(params receiver.Settings, cfg *Config) []*sqlServerS
132134
133135 // lru only returns error when the size is less than 0
134136 metricCache := newCache (1 )
135- planCache , _ := lru. New [string , string ](1 )
137+ planCache := expirable . NewLRU [string , string ](1 , nil , time . Second )
136138
137139 sqlServerScraper := newSQLServerScraper (id , query ,
138140 sqlquery.TelemetryConfig {},
@@ -174,7 +176,7 @@ func setupSQLServerLogsScrapers(params receiver.Settings, cfg *Config) []*sqlSer
174176 id := component .NewIDWithName (metadata .Type , fmt .Sprintf ("logs-query-%d: %s" , i , query ))
175177
176178 cache := newCache (1 )
177- planCache , _ := lru. New [string , string ](int ( cfg .MaxQuerySampleCount ) )
179+ planCache := expirable . NewLRU [string , string ](1 , nil , cfg .TopQueryCollection . QueryPlanCacheTTL )
178180
179181 if query == getSQLServerQueryTextAndPlanQuery () {
180182 // we have 8 metrics in this query and multiple 2 to allow to cache more queries.
0 commit comments