瀏覽代碼

Make tag filter of the form `-tagfilter=foo=1` work. (#509)

Tag filters like `-tagfilter=foo=1` currently cannot be used to filter
by a unitless numeric tag as the tag filter regular expression expects
the unit part to be always present.  They can be made working by using
`-tagfilter=foo=1unit` instead, but that's weird syntax. So fix this by
merely making the unit part optional.

I was wondering if this simple fix could have any unintended effects but
as far as I can tell from testing it does not.
Alexey Alexandrov 5 年之前
父節點
當前提交
2ed0793423
No account linked to committer's email address
共有 2 個文件被更改,包括 50 次插入1 次删除
  1. 1
    1
      internal/driver/driver_focus.go
  2. 49
    0
      internal/driver/driver_test.go

+ 1
- 1
internal/driver/driver_focus.go 查看文件

@@ -25,7 +25,7 @@ import (
25 25
 	"github.com/google/pprof/profile"
26 26
 )
27 27
 
28
-var tagFilterRangeRx = regexp.MustCompile("([+-]?[[:digit:]]+)([[:alpha:]]+)")
28
+var tagFilterRangeRx = regexp.MustCompile("([+-]?[[:digit:]]+)([[:alpha:]]+)?")
29 29
 
30 30
 // applyFocus filters samples based on the focus/ignore options
31 31
 func applyFocus(prof *profile.Profile, numLabelUnits map[string]string, v variables, ui plugin.UI) error {

+ 49
- 0
internal/driver/driver_test.go 查看文件

@@ -1455,6 +1455,55 @@ func TestNumericTagFilter(t *testing.T) {
1455 1455
 			map[string]string{"bytes": "bytes"},
1456 1456
 			false,
1457 1457
 		},
1458
+		{
1459
+			"Match exact value, unitless tag",
1460
+			"pid=123",
1461
+			map[string][]int64{"pid": {123}},
1462
+			nil,
1463
+			true,
1464
+		},
1465
+		{
1466
+			"Match range, unitless tag",
1467
+			"pid=123:123",
1468
+			map[string][]int64{"pid": {123}},
1469
+			nil,
1470
+			true,
1471
+		},
1472
+		{
1473
+			"Don't match range, unitless tag",
1474
+			"pid=124:124",
1475
+			map[string][]int64{"pid": {123}},
1476
+			nil,
1477
+			false,
1478
+		},
1479
+		{
1480
+			"Match range without upper bound, unitless tag",
1481
+			"pid=100:",
1482
+			map[string][]int64{"pid": {123}},
1483
+			nil,
1484
+			true,
1485
+		},
1486
+		{
1487
+			"Don't match range without upper bound, unitless tag",
1488
+			"pid=200:",
1489
+			map[string][]int64{"pid": {123}},
1490
+			nil,
1491
+			false,
1492
+		},
1493
+		{
1494
+			"Match range without lower bound, unitless tag",
1495
+			"pid=:200",
1496
+			map[string][]int64{"pid": {123}},
1497
+			nil,
1498
+			true,
1499
+		},
1500
+		{
1501
+			"Don't match range without lower bound, unitless tag",
1502
+			"pid=:100",
1503
+			map[string][]int64{"pid": {123}},
1504
+			nil,
1505
+			false,
1506
+		},
1458 1507
 	}
1459 1508
 	for _, test := range tagFilterTests {
1460 1509
 		t.Run(test.desc, func(t *testing.T) {