From a8df7d052bbe92cea05397f938142ec5aa02cd15 Mon Sep 17 00:00:00 2001 From: dhia-gharsallaoui <74959435+dhia-gharsallaoui@users.noreply.github.com> Date: Tue, 20 Sep 2022 14:27:42 +0200 Subject: [PATCH 1/4] add CI --- .github/workflows/go.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..966ab20 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,38 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... + + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.17 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.29 From d286e7bac2ceda3499beb4fbdb308be6c45f6765 Mon Sep 17 00:00:00 2001 From: shrivardhan Date: Wed, 21 Sep 2022 17:34:26 -0700 Subject: [PATCH 2/4] Fix agg post agg (#72) --- .../quantiles_doubles_sketch_test.go | 25 ++++++++-- builder/postaggregation/post_aggregator.go | 6 +++ .../quantile_from_tdigestsketch_test.go | 24 ++++++++-- ...ntiles_doubles_sketch_to_histogram_test.go | 48 +++++++++++++++---- ...antiles_doubles_sketch_to_quantile_test.go | 24 ++++++++-- ...ntiles_doubles_sketch_to_quantiles_test.go | 46 ++++++++++++------ .../quantiles_from_tdigestsketch_test.go | 24 ++++++++-- 7 files changed, 157 insertions(+), 40 deletions(-) diff --git a/builder/aggregation/quantiles_doubles_sketch_test.go b/builder/aggregation/quantiles_doubles_sketch_test.go index 6180ab0..bdcb0a1 100644 --- a/builder/aggregation/quantiles_doubles_sketch_test.go +++ b/builder/aggregation/quantiles_doubles_sketch_test.go @@ -9,11 +9,26 @@ import ( func TestQuantilesDoublesSketch(t *testing.T) { quantilesDoublesSketch := NewQuantilesDoublesSketch() quantilesDoublesSketch.SetName("output_name").SetFieldName("metric_name").SetK(100) - // "omitempty" will ignore boolean=false - expected := `{"type":"quantilesDoublesSketch", "name":"output_name", "fieldName": "metric_name", "k":100}` + quantilesDoublesSketchJSON := `{"type":"quantilesDoublesSketch", "name":"output_name", "fieldName": "metric_name", "k":100}` + + t.Run("build quantilesDoublesSketch", + func(t *testing.T) { + aggJSON, err := json.Marshal(quantilesDoublesSketch) + assert.Nil(t, + err) + assert.JSONEq(t, + quantilesDoublesSketchJSON, + string(aggJSON)) + }) - quantilesDoublesSketchJSON, err := json.Marshal(quantilesDoublesSketch) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesDoublesSketchJSON)) + t.Run("load quantilesDoublesSketch", + func(t *testing.T) { + agg, err := Load([]byte(quantilesDoublesSketchJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesDoublesSketch, + agg) + }) } diff --git a/builder/postaggregation/post_aggregator.go b/builder/postaggregation/post_aggregator.go index 6352683..19367ca 100644 --- a/builder/postaggregation/post_aggregator.go +++ b/builder/postaggregation/post_aggregator.go @@ -60,10 +60,16 @@ func Load(data []byte) (builder.PostAggregator, error) { p = NewLongGreatest() case "longLeast": p = NewLongLeast() + case "quantileFromTDigestSketch": + p = NewQuantileFromTDigestSketch() case "quantilesFromTDigestSketch": p = NewQuantilesFromTDigestSketch() case "quantilesDoublesSketchToQuantile": p = NewQuantilesDoublesSketchToQuantile() + case "quantilesDoublesSketchToQuantiles": + p = NewQuantilesDoublesSketchToQuantiles() + case "quantilesDoublesSketchToHistogram": + p = NewQuantilesDoublesSketchToHistogram() default: return nil, errors.New("unsupported postaggregation type") } diff --git a/builder/postaggregation/quantile_from_tdigestsketch_test.go b/builder/postaggregation/quantile_from_tdigestsketch_test.go index 9af95b8..5028d7a 100644 --- a/builder/postaggregation/quantile_from_tdigestsketch_test.go +++ b/builder/postaggregation/quantile_from_tdigestsketch_test.go @@ -7,13 +7,14 @@ import ( ) func TestQuantileFromTDigestSketch(t *testing.T) { + qf := NewQuantileFromTDigestSketchField() qf.SetType("fieldAccess").SetFieldName("merged_sketch") quantilesFromTDigestSketch := NewQuantileFromTDigestSketch() quantilesFromTDigestSketch.SetName("tp90").SetField(qf).SetFraction(0.90) // "omitempty" will ignore boolean=false - expected := ` + quantileFromTDigestSketchJSON := ` { "type": "quantileFromTDigestSketch", "name": "tp90", @@ -24,8 +25,23 @@ func TestQuantileFromTDigestSketch(t *testing.T) { "fraction": 0.9 } ` + t.Run("build quantileFromTDigestSketch", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesFromTDigestSketch) + assert.Nil(t, + err) + assert.JSONEq(t, + quantileFromTDigestSketchJSON, + string(postAggJSON)) + }) - quantileFromTDigestSketchJSON, err := json.Marshal(quantilesFromTDigestSketch) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantileFromTDigestSketchJSON)) + t.Run("load quantileFromTDigestSketch", + func(t *testing.T) { + postAgg, err := Load([]byte(quantileFromTDigestSketchJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesFromTDigestSketch, + postAgg) + }) } diff --git a/builder/postaggregation/quantiles_doubles_sketch_to_histogram_test.go b/builder/postaggregation/quantiles_doubles_sketch_to_histogram_test.go index 97c008c..7011b1b 100644 --- a/builder/postaggregation/quantiles_doubles_sketch_to_histogram_test.go +++ b/builder/postaggregation/quantiles_doubles_sketch_to_histogram_test.go @@ -13,7 +13,7 @@ func TestQuantilesDoublesSketchToHistogram_SetNumBins(t *testing.T) { quantilesDoublesSketchToHistogram.SetName("h").SetField(qf).SetNumBins(2) // "omitempty" will ignore boolean=false - expected := ` + quantilesDoublesSketchToHistogramJSON := ` { "type": "quantilesDoublesSketchToHistogram", "name": "h", @@ -26,9 +26,25 @@ func TestQuantilesDoublesSketchToHistogram_SetNumBins(t *testing.T) { } ` - quantilesDoublesSketchToHistogramJSON, err := json.Marshal(quantilesDoublesSketchToHistogram) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesDoublesSketchToHistogramJSON)) + t.Run("build quantilesDoublesSketchToHistogram", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesDoublesSketchToHistogram) + assert.Nil(t, + err) + assert.JSONEq(t, + string(postAggJSON), + quantilesDoublesSketchToHistogramJSON) + }) + + t.Run("load quantilesDoublesSketchToHistogram", + func(t *testing.T) { + postAgg, err := Load([]byte(quantilesDoublesSketchToHistogramJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesDoublesSketchToHistogram, + postAgg) + }) } func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) { @@ -38,7 +54,7 @@ func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) { quantilesDoublesSketchToHistogram.SetName("h").SetField(qf).SetSplitPoints([]float64{0.5, 1.5, 2.0}) // "omitempty" will ignore boolean=false - expected := ` + quantilesDoublesSketchToHistogramJSON := ` { "type": "quantilesDoublesSketchToHistogram", "name": "h", @@ -51,7 +67,23 @@ func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) { } ` - quantilesDoublesSketchToHistogramJSON, err := json.Marshal(quantilesDoublesSketchToHistogram) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesDoublesSketchToHistogramJSON)) + t.Run("build quantilesDoublesSketchToHistogram", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesDoublesSketchToHistogram) + assert.Nil(t, + err) + assert.JSONEq(t, + string(postAggJSON), + quantilesDoublesSketchToHistogramJSON) + }) + + t.Run("load quantilesDoublesSketchToHistogram", + func(t *testing.T) { + postAgg, err := Load([]byte(quantilesDoublesSketchToHistogramJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesDoublesSketchToHistogram, + postAgg) + }) } diff --git a/builder/postaggregation/quantiles_doubles_sketch_to_quantile_test.go b/builder/postaggregation/quantiles_doubles_sketch_to_quantile_test.go index 742b8db..21e614f 100644 --- a/builder/postaggregation/quantiles_doubles_sketch_to_quantile_test.go +++ b/builder/postaggregation/quantiles_doubles_sketch_to_quantile_test.go @@ -13,7 +13,7 @@ func TestQuantilesDoublesSketchToQuantile(t *testing.T) { quantilesDoublesSketchToQuantile.SetName("tp90").SetField(qf).SetFraction(0.90) // "omitempty" will ignore boolean=false - expected := ` + quantilesDoublesSketchToQuantileJSON := ` { "type": "quantilesDoublesSketchToQuantile", "name": "tp90", @@ -26,7 +26,23 @@ func TestQuantilesDoublesSketchToQuantile(t *testing.T) { } ` - quantilesDoublesSketchToQuantileJSON, err := json.Marshal(quantilesDoublesSketchToQuantile) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesDoublesSketchToQuantileJSON)) + t.Run("build quantilesDoublesSketchToQuantile", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesDoublesSketchToQuantile) + assert.Nil(t, + err) + assert.JSONEq(t, + string(postAggJSON), + quantilesDoublesSketchToQuantileJSON) + }) + + t.Run("load quantilesDoublesSketchToQuantile", + func(t *testing.T) { + postAgg, err := Load([]byte(quantilesDoublesSketchToQuantileJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesDoublesSketchToQuantile, + postAgg) + }) } diff --git a/builder/postaggregation/quantiles_doubles_sketch_to_quantiles_test.go b/builder/postaggregation/quantiles_doubles_sketch_to_quantiles_test.go index 36cba97..e16e209 100644 --- a/builder/postaggregation/quantiles_doubles_sketch_to_quantiles_test.go +++ b/builder/postaggregation/quantiles_doubles_sketch_to_quantiles_test.go @@ -13,20 +13,36 @@ func TestQuantilesDoublesSketchToQuantiles(t *testing.T) { quantilesDoublesSketchToQuantiles.SetName("tp75tp90").SetField(qf).SetFractions([]float64{0.75, 0.90}) // "omitempty" will ignore boolean=false - expected := ` -{ - "type": "quantilesDoublesSketchToQuantiles", - "name": "tp75tp90", - "field": { - "type": "fieldAccess", - "name": "tp75tp90", - "fieldName": "a1:agg" - }, - "fractions": [0.75, 0.9] -} -` + quantilesDoublesSketchToQuantilesJSON := ` + { + "type": "quantilesDoublesSketchToQuantiles", + "name": "tp75tp90", + "field": { + "type": "fieldAccess", + "name": "tp75tp90", + "fieldName": "a1:agg" + }, + "fractions": [0.75, 0.9] + } + ` + + t.Run("build quantilesDoublesSketchToQuantiles", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesDoublesSketchToQuantiles) + assert.Nil(t, + err) + assert.JSONEq(t, + string(postAggJSON), + quantilesDoublesSketchToQuantilesJSON) + }) - quantilesDoublesSketchToQuantilesJSON, err := json.Marshal(quantilesDoublesSketchToQuantiles) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesDoublesSketchToQuantilesJSON)) + t.Run("load quantilesDoublesSketchToQuantiles", + func(t *testing.T) { + postAgg, err := Load([]byte(quantilesDoublesSketchToQuantilesJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesDoublesSketchToQuantiles, + postAgg) + }) } diff --git a/builder/postaggregation/quantiles_from_tdigestsketch_test.go b/builder/postaggregation/quantiles_from_tdigestsketch_test.go index 1345abb..5c36f71 100644 --- a/builder/postaggregation/quantiles_from_tdigestsketch_test.go +++ b/builder/postaggregation/quantiles_from_tdigestsketch_test.go @@ -13,7 +13,7 @@ func TestQuantilesFromTDigestSketch(t *testing.T) { quantilesFromTDigestSketch.SetName("tp75tp90").SetField(qf).SetFractions([]float64{0.75, 0.90}) // "omitempty" will ignore boolean=false - expected := ` + quantilesFromTDigestSketchJSON := ` { "type": "quantilesFromTDigestSketch", "name": "tp75tp90", @@ -25,7 +25,23 @@ func TestQuantilesFromTDigestSketch(t *testing.T) { } ` - quantilesFromTDigestSketchJSON, err := json.Marshal(quantilesFromTDigestSketch) - assert.Nil(t, err) - assert.JSONEq(t, expected, string(quantilesFromTDigestSketchJSON)) + t.Run("build quantilesFromTDigestSketch", + func(t *testing.T) { + postAggJSON, err := json.Marshal(quantilesFromTDigestSketch) + assert.Nil(t, + err) + assert.JSONEq(t, + string(postAggJSON), + quantilesFromTDigestSketchJSON) + }) + + t.Run("load quantilesFromTDigestSketch", + func(t *testing.T) { + postAgg, err := Load([]byte(quantilesFromTDigestSketchJSON)) + assert.Nil(t, + err) + assert.Equal(t, + quantilesFromTDigestSketch, + postAgg) + }) } From 05d8bb88a4204c43ed018827c2d6a8854fd037cb Mon Sep 17 00:00:00 2001 From: dhia gharsallaoui Date: Thu, 22 Sep 2022 10:57:14 +0200 Subject: [PATCH 3/4] use mage and support multi os and go version --- .github/workflows/go.yml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 966ab20..9ed814e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,20 +9,43 @@ on: jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.17, 1.18, 1.19] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 + - name: Build + run: go build -v ./... + + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 with: go-version: 1.19 - - name: Build - run: go build -v ./... + - uses: actions/checkout@v3 + + - name: Install mage + run: | + git clone https://github.com/magefile/mage + cd mage + go run bootstrap.go install + cd ./.. - name: Test - run: go test -v ./... + run: mage test + + - name: Vet + run: mage vet golangci: name: lint @@ -31,7 +54,9 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.17 + - uses: actions/checkout@v3 + - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: From 47e7ef2daaa58e691d5522389cd48c1387f7104c Mon Sep 17 00:00:00 2001 From: dhia gharsallaoui Date: Wed, 28 Sep 2022 12:09:41 +0200 Subject: [PATCH 4/4] support multios build --- .github/workflows/go.yml | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9ed814e..1a56d7d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,45 +7,47 @@ on: branches: [ "master" ] jobs: - - build: + cross-build-test: strategy: + fail-fast: false matrix: - go-version: [1.17, 1.18, 1.19] - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - - - uses: actions/checkout@v3 - - - name: Build - run: go build -v ./... - - test: - name: test + goos: ['android', 'linux', 'solaris', 'illumos', 'dragonfly', 'freebsd', 'openbsd', 'plan9', 'windows', 'darwin', 'netbsd'] + go-version: ['1.17', '1.18', '1.19'] runs-on: ubuntu-latest + continue-on-error: true steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.19 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 + - name: Install mage + run: | + git clone https://github.com/magefile/mage + cd mage + go run bootstrap.go install + cd ./.. - - name: Install mage - run: | - git clone https://github.com/magefile/mage - cd mage - go run bootstrap.go install - cd ./.. + - name: Checkout code into the Go module directory + uses: actions/checkout@v3 - - name: Test - run: mage test + - name: Print Go version and environment + id: vars + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env - - name: Vet - run: mage vet + - name: Build + run: | + GOOS=$GOOS mage -v build 2> /dev/null + if [ $? -ne 0 ]; then + echo "::warning ::$GOOS Build Failed" + exit 0 + fi golangci: name: lint