@@ -92,12 +92,14 @@ type MetadataService interface {
9292 AllMetricMetadata (ctx context.Context ) (map [string ][]v1.Metadata , error )
9393 // LabelNames returns all the unique label names present in the block in sorted order.
9494 // If a metric is provided, then it will return all unique label names linked to the metric during a predefined period of time
95- LabelNames (ctx context.Context , metricName string , startTime time. Time , endTime time. Time ) ([]string , error )
95+ LabelNames (ctx context.Context , metricName string ) ([]string , error )
9696 // LabelValues performs a query for the values of the given label.
97- LabelValues (ctx context.Context , label string , startTime time. Time , endTime time. Time ) ([]model.LabelValue , error )
97+ LabelValues (ctx context.Context , label string ) ([]model.LabelValue , error )
9898 // ChangeDataSource is used if the prometheusURL is changing.
9999 // The client should re init its own parameter accordingly if necessary
100100 ChangeDataSource (prometheusURL string ) error
101+ // SetLookbackInterval is a method to use to change the interval that then will be used to retrieve data such as label and metrics from prometheus.
102+ SetLookbackInterval (interval time.Duration )
101103 // GetURL is returning the url used to contact the prometheus server
102104 // In case the instance is used directly in Prometheus, it should be the externalURL
103105 GetURL () string
@@ -108,15 +110,17 @@ type MetadataService interface {
108110// because it will manage which sub instance of the Client to use (like a factory).
109111type httpClient struct {
110112 MetadataService
111- requestTimeout time.Duration
112- mutex sync.RWMutex
113- subClient MetadataService
114- url string
113+ requestTimeout time.Duration
114+ mutex sync.RWMutex
115+ subClient MetadataService
116+ url string
117+ lookbackInterval time.Duration
115118}
116119
117- func NewClient (prometheusURL string ) (MetadataService , error ) {
120+ func NewClient (prometheusURL string , lookbackInterval time. Duration ) (MetadataService , error ) {
118121 c := & httpClient {
119- requestTimeout : 30 ,
122+ requestTimeout : 30 ,
123+ lookbackInterval : lookbackInterval ,
120124 }
121125 if err := c .ChangeDataSource (prometheusURL ); err != nil {
122126 return nil , err
@@ -136,18 +140,16 @@ func (c *httpClient) AllMetricMetadata(ctx context.Context) (map[string][]v1.Met
136140 return c .subClient .AllMetricMetadata (ctx )
137141}
138142
139- func (c * httpClient ) LabelNames (ctx context.Context , name string ,
140- startTime time.Time , endTime time.Time ) ([]string , error ) {
143+ func (c * httpClient ) LabelNames (ctx context.Context , name string ) ([]string , error ) {
141144 c .mutex .RLock ()
142145 defer c .mutex .RUnlock ()
143- return c .subClient .LabelNames (ctx , name , startTime , endTime )
146+ return c .subClient .LabelNames (ctx , name )
144147}
145148
146- func (c * httpClient ) LabelValues (ctx context.Context , label string ,
147- startTime time.Time , endTime time.Time ) ([]model.LabelValue , error ) {
149+ func (c * httpClient ) LabelValues (ctx context.Context , label string ) ([]model.LabelValue , error ) {
148150 c .mutex .RLock ()
149151 defer c .mutex .RUnlock ()
150- return c .subClient .LabelValues (ctx , label , startTime , endTime )
152+ return c .subClient .LabelValues (ctx , label )
151153}
152154
153155func (c * httpClient ) GetURL () string {
@@ -156,6 +158,13 @@ func (c *httpClient) GetURL() string {
156158 return c .url
157159}
158160
161+ func (c * httpClient ) SetLookbackInterval (interval time.Duration ) {
162+ c .mutex .Lock ()
163+ defer c .mutex .Unlock ()
164+ c .lookbackInterval = interval
165+ c .subClient .SetLookbackInterval (interval )
166+ }
167+
159168func (c * httpClient ) ChangeDataSource (prometheusURL string ) error {
160169 c .mutex .Lock ()
161170 defer c .mutex .Unlock ()
@@ -192,10 +201,12 @@ func (c *httpClient) ChangeDataSource(prometheusURL string) error {
192201 if isCompatible {
193202 c .subClient = & compatibleHTTPClient {
194203 prometheusClient : v1 .NewAPI (prometheusHTTPClient ),
204+ lookbackInterval : c .lookbackInterval ,
195205 }
196206 } else {
197207 c .subClient = & notCompatibleHTTPClient {
198208 prometheusClient : v1 .NewAPI (prometheusHTTPClient ),
209+ lookbackInterval : c .lookbackInterval ,
199210 }
200211 }
201212
0 commit comments