Skip to content

Commit 553b0b9

Browse files
authored
Merge pull request #547 from bookingcom/dzhdanov/aliassub-fix
Backporting aliasSub fix from go-graphite/carbonapi/issues/290
2 parents 8881b34 + bd6c173 commit 553b0b9

File tree

10 files changed

+103
-60
lines changed

10 files changed

+103
-60
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
go-version: [ 1.21.x, 1.22.x, 1.23.x, tip ]
12+
go-version: [ 1.23.x, 1.24.x, tip ]
1313
steps:
1414
- name: Set up Go stable
1515
if: matrix.go-version != 'tip'
@@ -31,11 +31,18 @@ jobs:
3131
uses: actions/checkout@v4
3232
- name: test
3333
run: make test
34+
- name: govulncheck
35+
if: matrix.go-version != 'tip'
36+
uses: golang/govulncheck-action@v1
37+
with:
38+
go-version-input: ${{ matrix.go-version }}
39+
check-latest: true
40+
go-package: ./...
3441
- name: golangci-lint
35-
if: matrix.go-version == '1.23.x'
36-
uses: golangci/golangci-lint-action@v6
42+
if: matrix.go-version == '1.24.x'
43+
uses: golangci/golangci-lint-action@v8
3744
with:
38-
version: v1.60.1
45+
version: v2.1.6
3946
- name: integration test
40-
if: matrix.go-version == '1.23.x'
47+
if: matrix.go-version == '1.24.x'
4148
run: tests/system_test.sh

.golangci.yml

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,65 @@
1+
version: "2"
12
run:
2-
timeout: 2m
3+
build-tags:
4+
- cairo
35
tests: true
4-
build-tags: [ cairo ]
5-
skip-files:
6-
- ".*\\.pb\\.go$"
7-
- "function_test.go"
8-
- "expr_test.go"
9-
- "cairo_test.go"
10-
6+
timeout: 5m
117
linters:
128
enable:
139
- asciicheck
1410
- bodyclose
15-
- gochecknoinits
16-
- gofmt
17-
- goimports
18-
- gosec
19-
- misspell
2011
- unparam
21-
22-
# The linters we need to enable ASAP.
23-
# Enabling would require significant changes.
24-
# - gochecknoglobals
25-
# - unconvert
26-
# - wrapcheck
27-
28-
# The linters that would be nice to have in order of decreasing priority.
29-
# They are disabled now because they cause a lot of warnings that would require multiple changes.
30-
# - revive
31-
# - errorlint
32-
# - promlinter
33-
# - cyclop or gocyclo
34-
# - whitespace
35-
# - gomnd
36-
# - lll
37-
# - gocritic
38-
12+
- staticcheck
13+
settings:
14+
staticcheck:
15+
# SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
16+
# Example (to disable some checks): [ "all", "-SA1000", "-SA1001"]
17+
# Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
18+
checks:
19+
- all
20+
# Incorrect or missing package comment.
21+
# https://staticcheck.dev/docs/checks/#ST1000
22+
- -ST1000
23+
# Use consistent method receiver names.
24+
# https://staticcheck.dev/docs/checks/#ST1016
25+
- -ST1016
26+
# Omit embedded fields from selector expression.
27+
# https://staticcheck.dev/docs/checks/#QF1008
28+
- -QF1008
29+
# Some other staticcheck checks
30+
- -ST1003
31+
- -ST1005
32+
- -ST1008
33+
- -QF1004
34+
- -QF1001
35+
exclusions:
36+
generated: lax
37+
presets:
38+
- comments
39+
- common-false-positives
40+
- legacy
41+
- std-error-handling
42+
rules:
43+
- linters:
44+
- errcheck
45+
- govet
46+
- gofmt
47+
path: _test\.go
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$
52+
- \.pb\.go$
3953
issues:
40-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
4154
max-issues-per-linter: 0
42-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
4355
max-same-issues: 0
44-
# Excluding configuration per-path, per-linter, per-text and per-source
45-
exclude-rules:
46-
# Exclude some linters from running on tests files.
47-
- path: _test\.go
48-
linters:
49-
- errcheck
56+
formatters:
57+
enable:
58+
- gofmt
59+
- goimports
60+
exclusions:
61+
generated: lax
62+
paths:
63+
- third_party$
64+
- builtin$
65+
- examples$

docker/carbonapi/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21
1+
FROM golang:1.24
22

33
RUN apt-get update
44
RUN apt-get install -y libcairo2-dev

docker/go-carbon/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21
1+
FROM golang:1.24
22

33
RUN mkdir -p /data/graphite/whisper/
44
COPY ./docker/go-carbon/*.conf /etc/

pkg/expr/functions/aliasSub/function.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ func (f *aliasSub) Do(ctx context.Context, e parser.Expr, from, until int32, val
5555
var results []*types.MetricData
5656

5757
for _, a := range args {
58-
metric := helper.ExtractMetric(a.Name)
59-
6058
r := *a
61-
r.Name = re.ReplaceAllString(metric, replace)
59+
r.Name = re.ReplaceAllString(r.Name, replace)
6260
results = append(results, &r)
6361
}
6462

pkg/expr/functions/aliasSub/function_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ func TestAliasByNode(t *testing.T) {
5151
[]*types.MetricData{types.MakeMetricData("100",
5252
[]float64{1, 2, 3, 4, 5}, 1, now32)},
5353
},
54+
{
55+
"aliasSub(metric1.foo.bar.baz, \"foo\", \"replaced\")",
56+
map[parser.MetricRequest][]*types.MetricData{
57+
{"metric1.foo.bar.baz", 0, 1}: {types.MakeMetricData("metric1.foo.bar.baz", []float64{1, 2, 3, 4, 5}, 1, now32)},
58+
},
59+
[]*types.MetricData{types.MakeMetricData("metric1.replaced.bar.baz",
60+
[]float64{1, 2, 3, 4, 5}, 1, now32)},
61+
},
62+
// https://github.com/go-graphite/carbonapi/issues/290
63+
{
64+
//"aliasSub(*, '.dns.([^.]+).zone.', '\\1 diff to sql')",
65+
"aliasSub(*, 'dns.([^.]*).zone.', '\\1 diff to sql ')",
66+
map[parser.MetricRequest][]*types.MetricData{
67+
{"*", 0, 1}: {types.MakeMetricData("diffSeries(dns.snake.sql_updated, dns.snake.zone_updated)", []float64{1, 2, 3, 4, 5}, 1, now32)},
68+
},
69+
[]*types.MetricData{types.MakeMetricData("diffSeries(dns.snake.sql_updated, snake diff to sql updated)",
70+
[]float64{1, 2, 3, 4, 5}, 1, now32)},
71+
},
5472
}
5573

5674
for _, tt := range tests {

pkg/expr/functions/cactiStyle/function.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func (f *cactiStyle) Do(ctx context.Context, e parser.Expr, from, until int32, v
7676
min := ""
7777
max := ""
7878
current := ""
79-
if system == "si" {
79+
switch system {
80+
case "si":
8081
mv, mf := humanize.ComputeSI(minVal)
8182
xv, xf := humanize.ComputeSI(maxVal)
8283
cv, cf := humanize.ComputeSI(currentVal)
@@ -85,12 +86,12 @@ func (f *cactiStyle) Do(ctx context.Context, e parser.Expr, from, until int32, v
8586
max = fmt.Sprintf("%.0f%s", xv, xf)
8687
current = fmt.Sprintf("%.0f%s", cv, cf)
8788

88-
} else if system == "" {
89+
case "":
8990
min = fmt.Sprintf("%.0f", minVal)
9091
max = fmt.Sprintf("%.0f", maxVal)
9192
current = fmt.Sprintf("%.0f", currentVal)
9293

93-
} else {
94+
default:
9495
return nil, fmt.Errorf("%s is not supported for system", system)
9596
}
9697

pkg/expr/functions/cairo/cairo_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
package cairo
55

66
import (
7-
"go.uber.org/zap"
87
"testing"
98
"time"
109

10+
"go.uber.org/zap"
11+
1112
"github.com/bookingcom/carbonapi/pkg/expr/metadata"
1213
"github.com/bookingcom/carbonapi/pkg/expr/types"
1314
"github.com/bookingcom/carbonapi/pkg/parser"

pkg/expr/functions/cairo/png/cairo.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,15 +1200,16 @@ func drawGraph(cr *cairoSurfaceContext, params *Params,
12001200
}
12011201

12021202
// check if we need to stack all the things
1203-
if params.areaMode == AreaModeStacked {
1203+
switch params.areaMode {
1204+
case AreaModeStacked:
12041205
params.hasStack = true
12051206
for _, r := range results {
12061207
r.Stacked = true
12071208
r.StackName = "stack"
12081209
}
1209-
} else if params.areaMode == AreaModeFirst {
1210+
case AreaModeFirst:
12101211
results[0].Stacked = true
1211-
} else if params.areaMode == AreaModeAll {
1212+
case AreaModeAll:
12121213
for _, r := range results {
12131214
r.Stacked = true
12141215
}

pkg/expr/functions/legendValue/function.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ func (f *legendValue) Do(ctx context.Context, e parser.Expr, from, until int32,
6363
}
6464

6565
summary := ""
66-
if system == "si" {
66+
switch system {
67+
case "si":
6768
sv, sf := humanize.ComputeSI(summaryVal)
6869
summary = fmt.Sprintf("%.1f %s", sv, sf)
69-
} else if system == "binary" {
70+
case "binary":
7071
summary = humanize.IBytes(uint64(summaryVal))
71-
} else if system == "" {
72+
case "":
7273
summary = fmt.Sprintf("%f", summaryVal)
73-
} else {
74+
default:
7475
return nil, fmt.Errorf("%s is not supported for system", system)
7576
}
7677
values = append(values, fmt.Sprintf("%s: %s", method, summary))

0 commit comments

Comments
 (0)