|
|
@@ -67,6 +67,54 @@ func TestMetrics(t *testing.T) {
|
|
|
return nil
|
|
|
})
|
|
|
|
|
|
+ var getDataSourceAccessStatsQuery *models.GetDataSourceAccessStatsQuery
|
|
|
+ bus.AddHandler("test", func(query *models.GetDataSourceAccessStatsQuery) error {
|
|
|
+ query.Result = []*models.DataSourceAccessStats{
|
|
|
+ {
|
|
|
+ Type: models.DS_ES,
|
|
|
+ Access: "direct",
|
|
|
+ Count: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: models.DS_ES,
|
|
|
+ Access: "proxy",
|
|
|
+ Count: 2,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: models.DS_PROMETHEUS,
|
|
|
+ Access: "proxy",
|
|
|
+ Count: 3,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "unknown_ds",
|
|
|
+ Access: "proxy",
|
|
|
+ Count: 4,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "unknown_ds2",
|
|
|
+ Access: "",
|
|
|
+ Count: 5,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "unknown_ds3",
|
|
|
+ Access: "direct",
|
|
|
+ Count: 6,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "unknown_ds4",
|
|
|
+ Access: "direct",
|
|
|
+ Count: 7,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "unknown_ds5",
|
|
|
+ Access: "proxy",
|
|
|
+ Count: 8,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ getDataSourceAccessStatsQuery = query
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+
|
|
|
var wg sync.WaitGroup
|
|
|
var responseBuffer *bytes.Buffer
|
|
|
var req *http.Request
|
|
|
@@ -90,6 +138,7 @@ func TestMetrics(t *testing.T) {
|
|
|
Convey("Should not gather stats or call http endpoint", func() {
|
|
|
So(getSystemStatsQuery, ShouldBeNil)
|
|
|
So(getDataSourceStatsQuery, ShouldBeNil)
|
|
|
+ So(getDataSourceAccessStatsQuery, ShouldBeNil)
|
|
|
So(req, ShouldBeNil)
|
|
|
})
|
|
|
})
|
|
|
@@ -107,6 +156,7 @@ func TestMetrics(t *testing.T) {
|
|
|
|
|
|
So(getSystemStatsQuery, ShouldNotBeNil)
|
|
|
So(getDataSourceStatsQuery, ShouldNotBeNil)
|
|
|
+ So(getDataSourceAccessStatsQuery, ShouldNotBeNil)
|
|
|
So(req, ShouldNotBeNil)
|
|
|
So(req.Method, ShouldEqual, http.MethodPost)
|
|
|
So(req.Header.Get("Content-Type"), ShouldEqual, "application/json")
|
|
|
@@ -142,6 +192,12 @@ func TestMetrics(t *testing.T) {
|
|
|
So(metrics.Get("stats.ds."+models.DS_ES+".count").MustInt(), ShouldEqual, 9)
|
|
|
So(metrics.Get("stats.ds."+models.DS_PROMETHEUS+".count").MustInt(), ShouldEqual, 10)
|
|
|
So(metrics.Get("stats.ds.other.count").MustInt(), ShouldEqual, 11+12)
|
|
|
+
|
|
|
+ So(metrics.Get("stats.ds_access."+models.DS_ES+".direct.count").MustInt(), ShouldEqual, 1)
|
|
|
+ So(metrics.Get("stats.ds_access."+models.DS_ES+".proxy.count").MustInt(), ShouldEqual, 2)
|
|
|
+ So(metrics.Get("stats.ds_access."+models.DS_PROMETHEUS+".proxy.count").MustInt(), ShouldEqual, 3)
|
|
|
+ So(metrics.Get("stats.ds_access.other.direct.count").MustInt(), ShouldEqual, 6+7)
|
|
|
+ So(metrics.Get("stats.ds_access.other.proxy.count").MustInt(), ShouldEqual, 4+8)
|
|
|
})
|
|
|
})
|
|
|
|