Skip to content

Commit

Permalink
fix: unit tests (#69)
Browse files Browse the repository at this point in the history
* fix: unit tests

* chore: update release notes
  • Loading branch information
silenceqi authored Jan 4, 2025
1 parent 635abc6 commit 8a27cd4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 132 deletions.
1 change: 1 addition & 0 deletions docs/content.en/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Information about release notes of INFINI Console is provided here.

### Bug fix
- Fixed query thread pool metrics when cluster uuid is empty
- Fixed unit tests

### Improvements
- Optimize UI of agent list when its columns are overflow.
Expand Down
2 changes: 1 addition & 1 deletion model/alerting/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestCreateRule( t *testing.T) {
},
},

Channels: NotificationConfig{
Channels: &NotificationConfig{
Normal: []Channel{
{Name: "钉钉", Type: ChannelWebhook, Webhook: &CustomWebhook{
HeaderParams: map[string]string{
Expand Down
7 changes: 5 additions & 2 deletions modules/elastic/api/metrics_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ import (

func TestGetMetricParams(t *testing.T) {
handler:=APIHandler{}
req:=http.Request{}
bucketSize, min, max, err:=handler.getMetricRangeAndBucketSize(&req,60,15)
req, err :=http.NewRequest("GET","https://infinilabs.com/api/?bucket_size=1m",nil)
if err != nil {
t.Fatal(err)
}
bucketSize, min, max, err:=handler.GetMetricRangeAndBucketSize(req,"", "",15)

fmt.Println(bucketSize)
fmt.Println(util.FormatUnixTimestamp(min/1000))//2022-01-27 15:28:57
Expand Down
115 changes: 0 additions & 115 deletions modules/elastic/api/v1/metrics_util_test.go

This file was deleted.

46 changes: 32 additions & 14 deletions service/alerting/elasticsearch/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ package elasticsearch
import (
"fmt"
"infini.sh/console/model/alerting"
"infini.sh/console/model/insight"
"infini.sh/framework/core/elastic"
"infini.sh/framework/core/util"
"infini.sh/framework/modules/elastic/adapter/elasticsearch"
"net/http"
"sort"
"testing"
Expand Down Expand Up @@ -77,12 +80,15 @@ func TestEngine( t *testing.T) {
},

Metrics: alerting.Metric{
PeriodInterval: "1m",
Items: []alerting.MetricItem{
{Name: "a", Field: "payload.elasticsearch.node_stats.fs.total.free_in_bytes", Statistic: "min", Group: []string{"metadata.labels.cluster_id", "metadata.labels.node_id"}},
{Name: "b", Field: "payload.elasticsearch.node_stats.fs.total.total_in_bytes", Statistic: "max", Group: []string{"metadata.labels.cluster_id", "metadata.labels.node_id"}},
Metric: insight.Metric{
BucketSize: "1m",
Items: []insight.MetricItem{
{Name: "a", Field: "payload.elasticsearch.node_stats.fs.total.free_in_bytes", Statistic: "min"},
{Name: "b", Field: "payload.elasticsearch.node_stats.fs.total.total_in_bytes", Statistic: "max"},
},
Formula: "a/b*100",
},
Formula: "a/b*100",

//Expression: "min(fs.free_in_bytes)/max(fs.total_in_bytes)*100",
},
Conditions: alerting.Condition{
Expand All @@ -93,7 +99,7 @@ func TestEngine( t *testing.T) {
},
},

Channels: alerting.NotificationConfig{
Channels: &alerting.NotificationConfig{
Normal: []alerting.Channel{
{Name: "钉钉", Type: alerting.ChannelWebhook, Webhook: &alerting.CustomWebhook{
HeaderParams: map[string]string{
Expand Down Expand Up @@ -139,7 +145,7 @@ func TestEngine( t *testing.T) {

func TestGenerateAgg(t *testing.T) {
eng := &Engine{}
agg := eng.generateAgg(&alerting.MetricItem{
agg := eng.generateAgg(&insight.MetricItem{
Name: "a",
Field: "cpu.percent",
Statistic: "p99",
Expand Down Expand Up @@ -199,13 +205,23 @@ func TestGeneratePercentilesAggQuery(t *testing.T) {
// EscalationThrottlePeriod: "30m",
// },
//}
cfg := elastic.ElasticsearchConfig{}
cfg.ID = "test"
esClient := elasticsearch.ESAPIV7{}
esClient.Elasticsearch = cfg.ID
esClient.Version = elastic.Version{
Number: "7.10.2",
Major: 7,
Distribution: elastic.Elasticsearch,
}
elastic.UpdateClient(cfg, &esClient)
rule := alerting.Rule{
ID: util.GetUUID(),
Created: time.Now(),
Updated: time.Now(),
Enabled: true,
Resource: alerting.Resource{
ID: "c8i18llath2blrusdjng",
ID: cfg.ID,
Type: "elasticsearch",
Objects: []string{".infini_metrics*"},
TimeField: "timestamp",
Expand All @@ -225,12 +241,14 @@ func TestGeneratePercentilesAggQuery(t *testing.T) {
},

Metrics: alerting.Metric{
PeriodInterval: "1m",
Items: []alerting.MetricItem{
{Name: "a", Field: "payload.elasticsearch.index_stats.total.search.query_total", Statistic: "rate", Group: []string{"metadata.labels.cluster_id"}},
{Name: "b", Field: "payload.elasticsearch.index_stats.total.search.query_time_in_millis", Statistic: "rate", Group: []string{"metadata.labels.cluster_id"}},
Metric: insight.Metric{
BucketSize: "1m",
Items: []insight.MetricItem{
{Name: "a", Field: "payload.elasticsearch.index_stats.total.search.query_total", Statistic: "rate"},
{Name: "b", Field: "payload.elasticsearch.index_stats.total.search.query_time_in_millis", Statistic: "rate"},
},
Formula: "b/a",
},
Formula: "b/a",
},
Conditions: alerting.Condition{
Operator: "any",
Expand All @@ -239,7 +257,7 @@ func TestGeneratePercentilesAggQuery(t *testing.T) {
},
},

Channels: alerting.NotificationConfig{
Channels: &alerting.NotificationConfig{
Normal: []alerting.Channel{
{Name: "钉钉", Type: alerting.ChannelWebhook, Webhook: &alerting.CustomWebhook{
HeaderParams: map[string]string{
Expand Down

0 comments on commit 8a27cd4

Please sign in to comment.