@@ -267,6 +267,46 @@ func TestLokiConfigurationForTopology(t *testing.T) {
267267 assert .NotNil (t , qr .Result )
268268}
269269
270+ func TestLokiConfigurationForTableHistogram (t * testing.T ) {
271+ // GIVEN a Loki service
272+ lokiMock := httpMock {}
273+ lokiMock .On ("ServeHTTP" , mock .Anything , mock .Anything ).Run (func (args mock.Arguments ) {
274+ _ , _ = args .Get (0 ).(http.ResponseWriter ).Write ([]byte (`{"status":"","data":{"resultType":"matrix","result":[]}}` ))
275+ })
276+ lokiSvc := httptest .NewServer (& lokiMock )
277+ defer lokiSvc .Close ()
278+ lokiURL , err := url .Parse (lokiSvc .URL )
279+ require .NoError (t , err )
280+
281+ // THAT is accessed behind the NOO console plugin backend
282+ backendRoutes := setupRoutes (& Config {
283+ Loki : loki.Config {
284+ URL : lokiURL ,
285+ Timeout : time .Second ,
286+ },
287+ })
288+ backendSvc := httptest .NewServer (backendRoutes )
289+ defer backendSvc .Close ()
290+
291+ // WHEN the Loki flows endpoint is queried in the backend using count type
292+ resp , err := backendSvc .Client ().Get (backendSvc .URL + "/api/loki/topology?type=count" )
293+ require .NoError (t , err )
294+
295+ // THEN the query has been properly forwarded to Loki
296+ req := lokiMock .Calls [0 ].Arguments [1 ].(* http.Request )
297+ assert .Equal (t , `topk(100,sum by(SrcK8S_Name,SrcK8S_Type,SrcK8S_OwnerName,SrcK8S_OwnerType,SrcK8S_Namespace,SrcAddr,SrcK8S_HostName,DstK8S_Name,DstK8S_Type,DstK8S_OwnerName,DstK8S_OwnerType,DstK8S_Namespace,DstAddr,DstK8S_HostName) (count_over_time({app="netobserv-flowcollector"}|~` + "`" + `Duplicate":false` + "`" + `|json[30s])))` , req .URL .Query ().Get ("query" ))
298+ // without any multi-tenancy header
299+ assert .Empty (t , req .Header .Get ("X-Scope-OrgID" ))
300+
301+ // AND the response is sent back to the client
302+ body , err := ioutil .ReadAll (resp .Body )
303+ require .NoError (t , err )
304+ var qr model.AggregatedQueryResponse
305+ err = json .Unmarshal (body , & qr )
306+ require .NoError (t , err )
307+ assert .NotNil (t , qr .Result )
308+ }
309+
270310func TestLokiConfiguration_MultiTenant (t * testing.T ) {
271311 lokiMock := httpMock {}
272312 lokiMock .On ("ServeHTTP" , mock .Anything , mock .Anything ).Run (func (args mock.Arguments ) {
0 commit comments