Skip to content

Commit

Permalink
Merge branch '2428-iss-gzip-tune' into 'dev'
Browse files Browse the repository at this point in the history
Resolve "替换现有 gzip 实现"

See merge request cloudcare-tools/datakit!3244
  • Loading branch information
谭彪 committed Oct 30, 2024
2 parents e776abf + 285e033 commit cf73feb
Show file tree
Hide file tree
Showing 50 changed files with 35,180 additions and 67 deletions.
3 changes: 2 additions & 1 deletion cmd/make/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ func compileArch(bin, goos, goarch, dir, mainEntranceFile, tags string) error {
}

func compileAPMInject(goos, goarch, dir string) error {
if goos != "linux" {
// skip build under macOS, we'll never release production package under macOS.
if goos != "linux" || runtime.GOOS != "linux" {
l.Warnf("skip building apm auto-inject launcher: unsupported os %s", goos)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/make/build/pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func PubDatakit() error {
}

// apm-auto-inject-launcher
if goos == Linux && (goarch == AMD64 || goarch == ARM64) {
if goos == Linux && (goarch == AMD64 || goarch == ARM64) && runtime.GOOS == "linux" {
gzName, gzPath := tarFiles(
PubDir, BuildDir, "datakit-apm-inject", goos, goarch, TarWithRlsVer)
basics[gzName] = gzPath
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/GuanceCloud/platypus v0.2.10-0.20240815092339-21f3924850ee
github.com/GuanceCloud/timeout v1.9.1
github.com/IBM/sarama v1.41.2
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible // indirect
github.com/antchfx/xmlquery v1.3.18 // indirect
github.com/apache/thrift v0.16.0
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
Expand Down Expand Up @@ -392,6 +392,8 @@ require (

require github.com/andybalholm/brotli v1.0.4

require github.com/klauspost/pgzip v1.2.6

replace (
github.com/c-bata/go-prompt => github.com/coanor/go-prompt v0.2.6
github.com/google/gopacket => github.com/GuanceCloud/gopacket v0.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ github.com/DataDog/sketches-go v1.4.1 h1:j5G6as+9FASM2qC36lvpvQAj9qsv/jUs3FtO8Cw
github.com/DataDog/sketches-go v1.4.1/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk=
github.com/GuanceCloud/client_model v0.0.0-20230418154757-93bd4e878a5e h1:i34dA4kiRTfG+KdvkIXCLPDduarVeFlQhGDD3TefgS4=
github.com/GuanceCloud/client_model v0.0.0-20230418154757-93bd4e878a5e/go.mod h1:PMnE48aPzuRu83FmWZugC0O3d54ZupJd/MmiaYxz8sM=
github.com/GuanceCloud/cliutils v1.1.22-0.20240930074036-255c78c086fd h1:KxbB1a1NybivPLnI+xVcR0WPPXlI1+jCyCmPMJ5LnpE=
github.com/GuanceCloud/cliutils v1.1.22-0.20240930074036-255c78c086fd/go.mod h1:5bIAZ9yA6l7W8MMUKw0+SIZJRpmEwxM6ZYLy4vweTgU=
github.com/GuanceCloud/cliutils v1.1.22-0.20241018104846-17e816f0e123 h1:CigTx24h5Lc/49Zghr8d70jrMeoEJ9tJXUE/79uzbQ0=
github.com/GuanceCloud/cliutils v1.1.22-0.20241018104846-17e816f0e123/go.mod h1:5bIAZ9yA6l7W8MMUKw0+SIZJRpmEwxM6ZYLy4vweTgU=
github.com/GuanceCloud/confd v0.1.101 h1:yjHgfl6YzAlTbFOFMTE4ERpFJzIyovOW7ZFc2/ZssL0=
Expand Down Expand Up @@ -1591,6 +1589,8 @@ github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZX
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08/go.mod h1:dFWs1zEqDjFtnBXsd1vPOZaLsESovai349994nHx3e0=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
29 changes: 0 additions & 29 deletions internal/io/dataway/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,6 @@ func (b *body) pretty() string {
return strings.Join(arr, "\n")
}

func (z *gzipWriter) zip(data []byte) ([]byte, error) {
if _, err := z.w.Write(data); err != nil {
return nil, err
}

if err := z.w.Flush(); err != nil {
return nil, err
}

if err := z.w.Close(); err != nil {
return nil, err
}

return z.buf.Bytes(), nil
}

func isGzip(data []byte) int8 {
if len(data) < 2 {
return -1
}

// See: https://stackoverflow.com/a/6059342/342348
if data[0] == 0x1f && data[1] == 0x8b {
return 1
} else {
return 0
}
}

type bodyCallback func(w *writer, b *body) error

func dumpPoints(pts []*point.Point) string {
Expand Down
68 changes: 68 additions & 0 deletions internal/io/dataway/gz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.

package dataway

import (
bytes "bytes"
"sync"

gzip "github.com/klauspost/compress/gzip"
)

var zippool sync.Pool

func getZipper() *gzipWriter {
if x := zippool.Get(); x == nil {
buf := bytes.Buffer{}
w := gzip.NewWriter(&buf)
return &gzipWriter{buf: &buf, w: w}
} else {
return x.(*gzipWriter)
}
}

func putZipper(z *gzipWriter) {
if z != nil {
// reset zip buffer and the writer.
z.buf.Reset()
z.w.Reset(z.buf)
zippool.Put(z)
}
}

type gzipWriter struct {
buf *bytes.Buffer
w *gzip.Writer
}

func (z *gzipWriter) zip(data []byte) ([]byte, error) {
if _, err := z.w.Write(data); err != nil {
return nil, err
}

if err := z.w.Flush(); err != nil {
return nil, err
}

if err := z.w.Close(); err != nil {
return nil, err
}

return z.buf.Bytes(), nil
}

func isGzip(data []byte) int8 {
if len(data) < 2 {
return -1
}

// See: https://stackoverflow.com/a/6059342/342348
if data[0] == 0x1f && data[1] == 0x8b {
return 1
} else {
return 0
}
}
Loading

0 comments on commit cf73feb

Please sign in to comment.