Skip to content

Commit ae5f3d6

Browse files
authored
fix: grafana not work when endpoint contains dot (open-falcon#924)
* fix: grafana not work when endpoint contains dot * use go 1.15 instead of 1.8 * inc sleep time to make travis-ci pass * update goconvey version * update vendors to fix travis-ci
1 parent 0c37ac5 commit ae5f3d6

File tree

113 files changed

+15458
-7051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+15458
-7051
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: required
33
language: go
44

55
go:
6-
- "1.8"
6+
- "1.15"
77

88
env:
99
- DB_USER=root DB_PASSWORD=test123456 DB_HOST=127.0.0.1 DB_PORT=13306 REDIS_HOST=127.0.0.1 REDIS_PORT=16379 API_PORT=18080 API_HOST=127.0.0.1

docker_test.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ docker run --name falcon-mysql -e MYSQL_ROOT_PASSWORD=$DB_PASSWORD -p $DB_PORT:3
1414
docker run --name falcon-redis -p $REDIS_PORT:6379 -d redis:4-alpine3.8
1515

1616
echo "waiting mysql start..."
17-
sleep 10
17+
sleep 15
1818
for x in `ls ./scripts/mysql/db_schema/*.sql`; do
1919
echo "- - -" $x ...
2020
mysql -h $DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASSWORD < $x
@@ -35,11 +35,13 @@ docker run -itd --name falcon-plus \
3535
-e MYSQL_PORT=$DB_USER:$DB_PASSWORD@tcp\(db.falcon:3306\) \
3636
-e REDIS_PORT=redis.falcon:6379 \
3737
$image_tag
38+
sleep 15
3839

3940
## start falcon backend modules, such as graph,api,etc.
40-
sleep 5
4141
docker exec falcon-plus sh ctrl.sh start \
4242
graph hbs judge transfer nodata aggregator agent gateway api alarm
4343

44-
sleep 5
44+
echo "sleep 15s waiting for falcon-plus process ready..."
45+
sleep 15
46+
4547
make test

modules/aggregator/cron/run_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func Test_expressionValid(t *testing.T) {
2222

2323
expressionMap := map[string]bool{
2424
// true
25-
"1210": true,
26-
"$#": true,
27-
"$(cpu.busy)": true,
28-
"$(cpu.busy)+$(cpu.idle)-$(cpu.nice)": true,
29-
"$(cpu.busy)>=80": true,
25+
"1210": true,
26+
"$#": true,
27+
"$(cpu.busy)": true,
28+
"$(cpu.busy)+$(cpu.idle)-$(cpu.nice)": true,
29+
"$(cpu.busy)>=80": true,
3030
"($(cpu.busy)+$(cpu.idle)-$(cpu.nice))>80": true,
3131
"$(qps/module=judge,project=falcon)": true,
3232
"($(cpu.idle)+$(cpu.busy))=100": true,

modules/api/app/controller/graph/grafana_controller.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func repsonseDefault(limit int) (result []APIGrafanaMainQueryOutputs) {
4646
for _, h := range enps {
4747
result = append(result, APIGrafanaMainQueryOutputs{
4848
Expandable: true,
49-
Text: h.Endpoint,
49+
Text: strings.Replace(h.Endpoint, ".", "~", -1), //convert '.' to '~' of endpoint
5050
})
5151
}
5252
return
@@ -62,50 +62,52 @@ func responseHostsRegexp(limit int, regexpKey string) (result []APIGrafanaMainQu
6262
for _, h := range enps {
6363
result = append(result, APIGrafanaMainQueryOutputs{
6464
Expandable: true,
65-
Text: h.Endpoint,
65+
Text: strings.Replace(h.Endpoint, ".", "~", -1), //convert '.' to '~' of endpoint
6666
})
6767
}
6868
return
6969
}
7070

7171
//for resolve mixed query with endpoint & counter of query string
7272
func cutEndpointCounterHelp(regexpKey string) (hosts []string, counter string) {
73+
//e.g. "{aaa,bbb}#xxx#yyy#zzz#.*" => hosts=[aaa,bbb], counter="xxx\.yyy\.zzz\..*"
7374
r, _ := regexp.Compile("^{?([^#}]+)}?#(.+)")
7475
matchedList := r.FindAllStringSubmatch(regexpKey, 1)
7576
if len(matchedList) != 0 {
7677
if len(matchedList[0]) > 1 {
77-
//get hosts
78-
hostsTmp := matchedList[0][1]
78+
//get hosts and convert '~' to '.' of endpoint
79+
hostsTmp := strings.Replace(matchedList[0][1], "~", ".", -1)
7980
counterTmp := matchedList[0][2]
8081
hosts = strings.Split(hostsTmp, ",")
8182
counter = strings.Replace(counterTmp, "#", "\\.", -1)
8283
}
8384
} else {
8485
log.Errorf("grafana query inputs error: %v", regexpKey)
8586
}
87+
8688
return
8789
}
8890

8991
func expandableChecking(counter string, counterSearchKeyWord string) (expsub string, needexp bool) {
90-
re := regexp.MustCompile("(\\.\\+|\\.\\*)\\s*$")
91-
counterSearchKeyWord = re.ReplaceAllString(counterSearchKeyWord, "")
92-
counterSearchKeyWord = strings.Replace(counterSearchKeyWord, "\\.", ".", -1)
93-
expCheck := strings.Replace(counter, counterSearchKeyWord, "", -1)
92+
terms := strings.Split(counterSearchKeyWord, "\\.")
93+
expCheck := ""
94+
95+
if len(terms) == 1 {
96+
expCheck = counter
97+
} else {
98+
counter_search_prefix := strings.Join(terms[0:len(terms)-1], ".")
99+
expCheck = strings.TrimPrefix(counter, counter_search_prefix)
100+
expCheck = strings.TrimPrefix(expCheck, ".")
101+
}
94102
if expCheck == "" {
95103
needexp = false
96104
expsub = expCheck
97105
} else {
98-
needexp = true
99-
re = regexp.MustCompile("^\\.")
100-
expsubArr := strings.Split(re.ReplaceAllString(expCheck, ""), ".")
101-
switch len(expsubArr) {
102-
case 0:
103-
expsub = ""
104-
case 1:
105-
expsub = expsubArr[0]
106+
a := strings.Split(expCheck, ".")
107+
expsub = a[0]
108+
if len(a) == 1 {
106109
needexp = false
107-
default:
108-
expsub = expsubArr[0]
110+
} else {
109111
needexp = true
110112
}
111113
}
@@ -216,6 +218,7 @@ func GrafanaMainQuery(c *gin.Context) {
216218
} else if strings.Contains(inputs.Query, "#") && !strings.Contains(inputs.Query, "#select metric") {
217219
output = responseCounterRegexp(inputs.Query)
218220
}
221+
log.Debugf("query response:%v", output)
219222
c.JSON(200, output)
220223
return
221224
}

vendor/github.com/BurntSushi/toml/COMPATIBLE

Lines changed: 0 additions & 3 deletions
This file was deleted.

vendor/github.com/BurntSushi/toml/COPYING

Lines changed: 0 additions & 14 deletions
This file was deleted.

vendor/github.com/BurntSushi/toml/Makefile

Lines changed: 0 additions & 19 deletions
This file was deleted.

vendor/github.com/BurntSushi/toml/README.md

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)