@@ -23,14 +23,21 @@ type FacetRequest struct {
2323 Field string `json:"field"`
2424}
2525
26- type DataSetClient struct {
26+ type DataSetClient interface {
27+ DoLRQRequest (ctx context.Context , req LRQRequest ) (* LRQResult , error )
28+ DoFacetValuesRequest (ctx context.Context , req FacetQuery ) (* LRQResult , error )
29+ DoTopFacetRequest (ctx context.Context , req TopFacetRequest ) (* LRQResult , error )
30+ DoFacetRequest (ctx context.Context , req FacetRequest ) (int , error )
31+ }
32+
33+ type dataSetClient struct {
2734 dataSetUrl string
2835 apiKey string
2936 netClient * http.Client
3037 rateLimiter * rate.Limiter
3138}
3239
33- func NewDataSetClient (dataSetUrl string , apiKey string ) * DataSetClient {
40+ func NewDataSetClient (dataSetUrl string , apiKey string ) DataSetClient {
3441 // Consider using the backend.httpclient package provided by the Grafana SDK.
3542 // This would allow a per-instance configurable timeout, rather than the hardcoded value here.
3643 netClient := & http.Client {
@@ -41,16 +48,16 @@ func NewDataSetClient(dataSetUrl string, apiKey string) *DataSetClient {
4148 // Consult with Grafana support about this, potentially there's a simplier option.
4249 rateLimiter := rate .NewLimiter (100 * rate .Every (1 * time .Minute ), 100 ) // 100 requests / minute
4350
44- return & DataSetClient {
51+ return & dataSetClient {
4552 dataSetUrl : dataSetUrl ,
4653 apiKey : apiKey ,
4754 netClient : netClient ,
4855 rateLimiter : rateLimiter ,
4956 }
5057}
5158
52- func (d * DataSetClient ) newRequest (method , url string , body io.Reader ) (* http.Request , error ) {
53- const VERSION = "3.1.0 "
59+ func (d * dataSetClient ) newRequest (method , url string , body io.Reader ) (* http.Request , error ) {
60+ const VERSION = "3.1.1 "
5461
5562 if err := d .rateLimiter .Wait (context .Background ()); err != nil {
5663 log .DefaultLogger .Error ("error applying rate limiter" , "err" , err )
@@ -72,7 +79,7 @@ func (d *DataSetClient) newRequest(method, url string, body io.Reader) (*http.Re
7279 return request , nil
7380}
7481
75- func (d * DataSetClient ) doPingRequest (ctx context.Context , req interface {}) (* LRQResult , error ) {
82+ func (d * dataSetClient ) doPingRequest (ctx context.Context , req interface {}) (* LRQResult , error ) {
7683 // Long-Running Query (LRQ) api usage:
7784 // - An initial POST request is made containing the standard/power query
7885 // - Its response may or may not contain the results
@@ -206,19 +213,19 @@ loop:
206213 return & respBody , nil
207214}
208215
209- func (d * DataSetClient ) DoLRQRequest (ctx context.Context , req LRQRequest ) (* LRQResult , error ) {
216+ func (d * dataSetClient ) DoLRQRequest (ctx context.Context , req LRQRequest ) (* LRQResult , error ) {
210217 return d .doPingRequest (ctx , req )
211218}
212219
213- func (d * DataSetClient ) DoFacetValuesRequest (ctx context.Context , req FacetQuery ) (* LRQResult , error ) {
220+ func (d * dataSetClient ) DoFacetValuesRequest (ctx context.Context , req FacetQuery ) (* LRQResult , error ) {
214221 return d .doPingRequest (ctx , req )
215222}
216223
217- func (d * DataSetClient ) DoTopFacetRequest (ctx context.Context , req TopFacetRequest ) (* LRQResult , error ) {
224+ func (d * dataSetClient ) DoTopFacetRequest (ctx context.Context , req TopFacetRequest ) (* LRQResult , error ) {
218225 return d .doPingRequest (ctx , req )
219226}
220227
221- func (d * DataSetClient ) DoFacetRequest (ctx context.Context , req FacetRequest ) (int , error ) {
228+ func (d * dataSetClient ) DoFacetRequest (ctx context.Context , req FacetRequest ) (int , error ) {
222229 body , err := json .Marshal (req )
223230 if err != nil {
224231 log .DefaultLogger .Error ("error marshalling request to DataSet" , "err" , err )
0 commit comments