From 5a3b8595930dcf6f388b38f0741b78e49279929f Mon Sep 17 00:00:00 2001 From: yotamloe Date: Thu, 12 May 2022 11:23:54 +0300 Subject: [PATCH 1/6] Add info logs + update dep (goleveldb) --- go.mod | 2 +- go.sum | 44 ++++++++++++++++++++++++++++++++++++++++++++ logsender_test.go | 6 +++--- logziosender.go | 21 ++++++++++++--------- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index cdbf2da..4c30698 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.15 require ( github.com/beeker1121/goque v2.1.0+incompatible github.com/shirou/gopsutil/v3 v3.22.3 - github.com/syndtr/goleveldb v1.0.0 // indirect + github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect go.uber.org/atomic v1.9.0 ) diff --git a/go.sum b/go.sum index 6ce765e..09477b4 100644 --- a/go.sum +++ b/go.sum @@ -5,22 +5,39 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= @@ -33,24 +50,49 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= @@ -59,5 +101,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/logsender_test.go b/logsender_test.go index 2f144d3..eb973f2 100644 --- a/logsender_test.go +++ b/logsender_test.go @@ -718,13 +718,13 @@ func TestLogzioSender_E2E(t *testing.T) { SetDebug(os.Stderr), ) if err != nil { - panic(err) + t.Fatal(err) } msg := `{"traceID":"0000000000000001","operationName":"o3","spanID":"2a3ad4a54c048830","references":[],"startTime":1632401226891238,"startTimeMillis":1632401226891,"duration":0,"logs":[],"process":{"serviceName":"testService","tags":[]},"type":"jaegerSpan"}` for i := 0; i < 10000; i++ { - err := l.Send([]byte(msg)) + err = l.Send([]byte(msg)) if err != nil { - panic(err) + t.Fatal(err) } } time.Sleep(time.Second * 40) diff --git a/logziosender.go b/logziosender.go index d1c28ec..bff75e8 100644 --- a/logziosender.go +++ b/logziosender.go @@ -242,7 +242,7 @@ func (l *LogzioSender) isEnoughDiskSpace() bool { func (l *LogzioSender) isEnoughMemory(dataSize uint64) bool { usage := l.queue.Length() if usage+dataSize >= l.inMemoryCapacity { - l.debugLog("Logz.io: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) + l.infoLog("Logz.io: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) l.droppedLogs++ return false } else { @@ -291,7 +291,7 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i if c { req.Header.Add("Content-Encoding", "gzip") } - l.debugLog("logziosender.go: Sending bulk of %v bytes\n", l.buf.Len()) + l.infoLog("logziosender.go: Sending bulk of %v bytes\n", l.buf.Len()) resp, err := l.httpClient.Do(req) if err != nil { //l.debugLog("logziosender.go: Error sending logs to %s %s\n", l.url, err) @@ -302,9 +302,9 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i statusCode := resp.StatusCode _, err = ioutil.ReadAll(resp.Body) if err != nil { - l.debugLog("Error reading response body: %v", err) + l.infoLog("Error reading response body: %v", err) } - l.debugLog("logziosender.go: Response status code: %v \n", statusCode) + l.infoLog("logziosender.go: Response status code: %v \n", statusCode) if statusCode == 200 { l.droppedLogs = 0 } @@ -335,16 +335,16 @@ func (l *LogzioSender) shouldRetry(statusCode int) bool { retry := true switch statusCode { case http.StatusBadRequest: - l.debugLog("Got HTTP %d bad request, skip retry\n", statusCode) + l.infoLog("Got HTTP %d bad request, skip retry\n", statusCode) retry = false case http.StatusNotFound: - l.debugLog("Got HTTP %d not found, skip retry\n", statusCode) + l.infoLog("Got HTTP %d not found, skip retry\n", statusCode) retry = false case http.StatusUnauthorized: - l.debugLog("Got HTTP %d unauthorized, skip retry\n", statusCode) + l.infoLog("Got HTTP %d unauthorized, skip retry\n", statusCode) retry = false case http.StatusForbidden: - l.debugLog("Got HTTP %d forbidden, skip retry\n", statusCode) + l.infoLog("Got HTTP %d forbidden, skip retry\n", statusCode) retry = false case http.StatusOK: retry = false @@ -409,7 +409,6 @@ func (l *LogzioSender) dequeueUpToMaxBatchSize() { break } _, err := l.buf.Write(append(item.Value, '\n')) - //l.debugLog("logziosender.go: Adding item with size %d (total buffSize: %d)\n", len(item.Value), l.buf.Len()) if err != nil { l.errorLog("error writing to buffer %s", err) } @@ -439,6 +438,10 @@ func (l *LogzioSender) debugLog(format string, a ...interface{}) { } } +func (l *LogzioSender) infoLog(format string, a ...interface{}) { + fmt.Fprintf(os.Stderr, format, a...) +} + func (l *LogzioSender) errorLog(format string, a ...interface{}) { fmt.Fprintf(os.Stderr, format, a...) } From 8bbd2ae2288b8e8e524785c57d698bcf910e1451 Mon Sep 17 00:00:00 2001 From: yotamloe Date: Thu, 12 May 2022 12:21:33 +0300 Subject: [PATCH 2/6] Change `token` query parameter to optional for generic use --- README.md | 24 ++++++++++++++++++------ logsender_test.go | 18 ++---------------- logziosender.go | 43 +++++++++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 7a98153..6552f55 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,8 @@ func main() { ## Data compression All bulks are compressed with gzip by default to disable compressing initialize the client with `SetCompress(false)`: ```go - logzio.New(token, SetCompress(false), + logzio.New(token, + SetCompress(false), ) ``` @@ -132,7 +133,6 @@ All bulks are compressed with gzip by default to disable compressing initialize ```shell $ go test -v - ``` @@ -145,6 +145,9 @@ $ go test -v * **Douglas Chimento** - [dougEfresh][me] * **Ido Halevi** - [idohalevi](https://github.com/idohalevi) +## Maintainers +* **Yotam Loewenbach** - [yotamloe](https://github.com/yotamloe) + ## License @@ -155,10 +158,19 @@ This project is licensed under the Apache License - see the [LICENSE](LICENSE) f * [logzio-java-sender](https://github.com/logzio/logzio-java-sender) -## Changelog +## Changelog +- v1.0.5 + - Change `token` query parameter to optional for generic use + - Changed logging levels + - Update goleveldb version +- v1.0.4 + - Update gopsutil version (v3.21.6 -> v3.22.3) +- v1.0.3 + - Adjust buffer clearance + - Changed logging format +- v1.0.2 + - Update dependencies - v1.0.1 - Add gzip compression - Add option for in Memory queue - -- v1.0.2 - - Update dependencies + diff --git a/logsender_test.go b/logsender_test.go index eb973f2..8d60576 100644 --- a/logsender_test.go +++ b/logsender_test.go @@ -93,9 +93,7 @@ func TestLogzioSender_InMemoryCapacityLimit(t *testing.T) { func TestLogzioSender_InMemorySend(t *testing.T) { var sent = make([]byte, 1024) - var sentToken string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - sentToken = r.URL.Query().Get("token") w.WriteHeader(http.StatusOK) r.Body.Read(sent) })) @@ -117,9 +115,6 @@ func TestLogzioSender_InMemorySend(t *testing.T) { } l.Drain() time.Sleep(200 * time.Millisecond) - if sentToken != "fake-token" { - t.Fatalf("token not sent %s", sentToken) - } item, err := l.queue.Dequeue() if item != nil { t.Fatalf("Unexpect item in the queue - %s", string(item.Value)) @@ -129,9 +124,7 @@ func TestLogzioSender_InMemorySend(t *testing.T) { func TestLogzioSender_InMemoryDrain(t *testing.T) { var sent = make([]byte, 1024) - var sentToken string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - sentToken = r.URL.Query().Get("token") w.WriteHeader(http.StatusOK) r.Body.Read(sent) })) @@ -152,9 +145,6 @@ func TestLogzioSender_InMemoryDrain(t *testing.T) { } l.Drain() time.Sleep(time.Second * 10) - if sentToken != "fake-token" { - t.Fatalf("token not sent %s", sentToken) - } item, err := l.queue.Dequeue() if item != nil { t.Fatalf("Unexpect item in the queue - %s", string(item.Value)) @@ -378,9 +368,7 @@ func TestLogzioSender_Retries(t *testing.T) { func TestLogzioSender_Send(t *testing.T) { var sent = make([]byte, 1024) - var sentToken string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - sentToken = r.URL.Query().Get("token") w.WriteHeader(http.StatusOK) r.Body.Read(sent) })) @@ -402,9 +390,7 @@ func TestLogzioSender_Send(t *testing.T) { if sentMsg != "blah\n" { t.Fatalf("%s != %s ", sent, sentMsg) } - if sentToken != "fake-token" { - t.Fatalf("token not sent %s", sentToken) - } + } func TestLogzioSender_DelayStart(t *testing.T) { @@ -614,7 +600,7 @@ func TestLogzioSender_CountDropped(t *testing.T) { if l.droppedLogs != 3 { t.Fatalf("items should have been dropped") } - l.diskThreshold = 95 + l.diskThreshold = 98 l.Send([]byte("blah")) l.Send([]byte("blah")) l.Drain() diff --git a/logziosender.go b/logziosender.go index bff75e8..f3b5e45 100644 --- a/logziosender.go +++ b/logziosender.go @@ -172,8 +172,11 @@ func SetTempDirectory(dir string) SenderOptionFunc { // SetUrl set the url which maybe different from the defaultUrl func SetUrl(url string) SenderOptionFunc { return func(l *LogzioSender) error { - l.url = fmt.Sprintf("%s/?token=%s", url, l.token) - l.debugLog("logziosender.go: Setting url to %s\n", l.url) + if l.token != "" { + l.url = fmt.Sprintf("%s/?token=%s", url, l.token) + } + l.url = url + l.debugLog("sender: Setting url to %s\n", l.url) return nil } } @@ -219,14 +222,14 @@ func (l *LogzioSender) isEnoughDiskSpace() bool { if l.checkDiskSpace { diskStat, err := disk.Usage(l.dir) if err != nil { - l.debugLog("logziosender.go: failed to get disk usage: %v\n", err) + l.debugLog("sender: failed to get disk usage: %v\n", err) l.checkDiskSpace = false return false } usage := float32(diskStat.UsedPercent) if usage > l.diskThreshold { - l.debugLog("Logz.io: Dropping logs, as FS used space on %s is %g percent,"+ + l.debugLog("sender: Dropping logs, as FS used space on %s is %g percent,"+ " and the drop threshold is %g percent\n", l.dir, usage, l.diskThreshold) l.droppedLogs++ @@ -242,7 +245,7 @@ func (l *LogzioSender) isEnoughDiskSpace() bool { func (l *LogzioSender) isEnoughMemory(dataSize uint64) bool { usage := l.queue.Length() if usage+dataSize >= l.inMemoryCapacity { - l.infoLog("Logz.io: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) + l.infoLog("sender: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) l.droppedLogs++ return false } else { @@ -291,10 +294,10 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i if c { req.Header.Add("Content-Encoding", "gzip") } - l.infoLog("logziosender.go: Sending bulk of %v bytes\n", l.buf.Len()) + l.infoLog("sender: Sending bulk of %v bytes\n", l.buf.Len()) resp, err := l.httpClient.Do(req) if err != nil { - //l.debugLog("logziosender.go: Error sending logs to %s %s\n", l.url, err) + l.infoLog("sender: Error sending logs to %s %s\n", l.url, err) return httpError } @@ -302,9 +305,9 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i statusCode := resp.StatusCode _, err = ioutil.ReadAll(resp.Body) if err != nil { - l.infoLog("Error reading response body: %v", err) + l.infoLog("sender: Error reading response body: %v", err) } - l.infoLog("logziosender.go: Response status code: %v \n", statusCode) + l.infoLog("sender: Response status code: %v \n", statusCode) if statusCode == 200 { l.droppedLogs = 0 } @@ -335,16 +338,16 @@ func (l *LogzioSender) shouldRetry(statusCode int) bool { retry := true switch statusCode { case http.StatusBadRequest: - l.infoLog("Got HTTP %d bad request, skip retry\n", statusCode) + l.infoLog("sender: Got HTTP %d bad request, skip retry\n", statusCode) retry = false case http.StatusNotFound: - l.infoLog("Got HTTP %d not found, skip retry\n", statusCode) + l.infoLog("sender: Got HTTP %d not found, skip retry\n", statusCode) retry = false case http.StatusUnauthorized: - l.infoLog("Got HTTP %d unauthorized, skip retry\n", statusCode) + l.infoLog("sender: Got HTTP %d unauthorized, skip retry\n", statusCode) retry = false case http.StatusForbidden: - l.infoLog("Got HTTP %d forbidden, skip retry\n", statusCode) + l.infoLog("sender: Got HTTP %d forbidden, skip retry\n", statusCode) retry = false case http.StatusOK: retry = false @@ -355,11 +358,11 @@ func (l *LogzioSender) shouldRetry(statusCode int) bool { // Drain - Send remaining logs func (l *LogzioSender) Drain() { if l.draining.Load() { - l.debugLog("logziosender.go: Already draining\n") + l.debugLog("sender: Already draining\n") return } l.mux.Lock() - l.debugLog("logziosender.go: draining queue\n") + l.debugLog("sender: draining queue\n") defer l.mux.Unlock() l.draining.Toggle() defer l.draining.Toggle() @@ -372,7 +375,7 @@ func (l *LogzioSender) Drain() { toBackOff := false for attempt := 0; attempt < sendRetries; attempt++ { if toBackOff { - l.debugLog("logziosender.go: failed to send logs, trying again in %v\n", backOff) + l.debugLog("sender: failed to send logs, trying again in %v\n", backOff) time.Sleep(backOff) backOff *= 2 } @@ -400,7 +403,7 @@ func (l *LogzioSender) dequeueUpToMaxBatchSize() { for l.buf.Len() < maxSize && err == nil { item, err := l.queue.Dequeue() if err != nil { - l.debugLog("queue state: %s\n", err) + l.debugLog("sender: queue state: %s\n", err) } if item != nil { // NewLine is appended tp item.Value @@ -410,7 +413,7 @@ func (l *LogzioSender) dequeueUpToMaxBatchSize() { } _, err := l.buf.Write(append(item.Value, '\n')) if err != nil { - l.errorLog("error writing to buffer %s", err) + l.errorLog("sender: error writing to buffer %s", err) } } else { break @@ -425,10 +428,10 @@ func (l *LogzioSender) Sync() error { } func (l *LogzioSender) requeue() { - l.debugLog("logziosender.go: Requeue %s", l.buf.String()) + l.debugLog("sender: Requeue %s", l.buf.String()) err := l.Send(l.buf.Bytes()) if err != nil { - l.errorLog("could not requeue logs %s", err) + l.errorLog("sender: could not requeue logs %s", err) } } From 89c808f1d953de42805ee5652cb923713a61b237 Mon Sep 17 00:00:00 2001 From: yotamloe Date: Thu, 12 May 2022 12:33:48 +0300 Subject: [PATCH 3/6] Add tests for url setting --- logsender_test.go | 31 +++++++++++++++++++++++++++++++ logziosender.go | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/logsender_test.go b/logsender_test.go index 8d60576..c66d16e 100644 --- a/logsender_test.go +++ b/logsender_test.go @@ -28,6 +28,37 @@ const ( defaultQueueSize = 40 * 1024 * 1024 ) +func TestLogzioSender_SetUrl(t *testing.T) { + l, err := New( + "", + SetDebug(os.Stderr), + SetUrl("http://localhost:12345"), + SetInMemoryQueue(true), + SetinMemoryCapacity(500), + SetDrainDuration(time.Minute), + ) + if err != nil { + t.Fatal(err) + } + if l.url != "http://localhost:12345" { + t.Fatalf("url should be http://localhost:12345, actual: %s", l.url) + } + l2, err := New( + "token", + SetDebug(os.Stderr), + SetUrl("http://localhost:12345"), + SetInMemoryQueue(true), + SetinMemoryCapacity(500), + SetDrainDuration(time.Minute), + ) + if err != nil { + t.Fatal(err) + } + if l2.url != "http://localhost:12345/?token=token" { + t.Fatalf("url should be http://localhost:12345/?token=token, actual: %s", l.url) + } +} + // In memory queue tests func TestLogzioSender_inMemoryRetries(t *testing.T) { var sent = make([]byte, 1024) diff --git a/logziosender.go b/logziosender.go index f3b5e45..d72260c 100644 --- a/logziosender.go +++ b/logziosender.go @@ -172,10 +172,10 @@ func SetTempDirectory(dir string) SenderOptionFunc { // SetUrl set the url which maybe different from the defaultUrl func SetUrl(url string) SenderOptionFunc { return func(l *LogzioSender) error { + l.url = url if l.token != "" { l.url = fmt.Sprintf("%s/?token=%s", url, l.token) } - l.url = url l.debugLog("sender: Setting url to %s\n", l.url) return nil } From aac780767ee09ace67209156ed9cc1e113164bc1 Mon Sep 17 00:00:00 2001 From: yotamloe Date: Thu, 12 May 2022 12:50:26 +0300 Subject: [PATCH 4/6] revert goleveldb version update --- README.md | 1 - go.mod | 2 +- go.sum | 44 -------------------------------------------- 3 files changed, 1 insertion(+), 46 deletions(-) diff --git a/README.md b/README.md index 6552f55..240ac92 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,6 @@ This project is licensed under the Apache License - see the [LICENSE](LICENSE) f - v1.0.5 - Change `token` query parameter to optional for generic use - Changed logging levels - - Update goleveldb version - v1.0.4 - Update gopsutil version (v3.21.6 -> v3.22.3) - v1.0.3 diff --git a/go.mod b/go.mod index 4c30698..cdbf2da 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.15 require ( github.com/beeker1121/goque v2.1.0+incompatible github.com/shirou/gopsutil/v3 v3.22.3 - github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect + github.com/syndtr/goleveldb v1.0.0 // indirect go.uber.org/atomic v1.9.0 ) diff --git a/go.sum b/go.sum index 09477b4..6ce765e 100644 --- a/go.sum +++ b/go.sum @@ -5,39 +5,22 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= @@ -50,49 +33,24 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= @@ -101,7 +59,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 9a516eb4c869d5d52b81d6be0a68564fa80372e2 Mon Sep 17 00:00:00 2001 From: yotamloe Date: Thu, 12 May 2022 14:46:56 +0300 Subject: [PATCH 5/6] update Author git link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 240ac92..51e2283 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ $ go test -v ## Authors -* **Douglas Chimento** - [dougEfresh][me] +* **Douglas Chimento** - [dougEfresh](https://github.com/dougEfresh) * **Ido Halevi** - [idohalevi](https://github.com/idohalevi) ## Maintainers From af73d975162538c87da9192f71c9559708f98ade Mon Sep 17 00:00:00 2001 From: yotamloe Date: Mon, 16 May 2022 11:28:36 +0300 Subject: [PATCH 6/6] change logging + remove `draining queue` log --- logziosender.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/logziosender.go b/logziosender.go index d72260c..aca9854 100644 --- a/logziosender.go +++ b/logziosender.go @@ -245,7 +245,7 @@ func (l *LogzioSender) isEnoughDiskSpace() bool { func (l *LogzioSender) isEnoughMemory(dataSize uint64) bool { usage := l.queue.Length() if usage+dataSize >= l.inMemoryCapacity { - l.infoLog("sender: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) + l.debugLog("sender: Dropping logs, the max capacity is %d and %d is requested, Request size: %d\n", l.inMemoryCapacity, usage+dataSize, dataSize) l.droppedLogs++ return false } else { @@ -294,10 +294,10 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i if c { req.Header.Add("Content-Encoding", "gzip") } - l.infoLog("sender: Sending bulk of %v bytes\n", l.buf.Len()) + l.debugLog("sender: Sending bulk of %v bytes\n", l.buf.Len()) resp, err := l.httpClient.Do(req) if err != nil { - l.infoLog("sender: Error sending logs to %s %s\n", l.url, err) + l.debugLog("sender: Error sending logs to %s %s\n", l.url, err) return httpError } @@ -305,9 +305,9 @@ func (l *LogzioSender) makeHttpRequest(data bytes.Buffer, attempt int, c bool) i statusCode := resp.StatusCode _, err = ioutil.ReadAll(resp.Body) if err != nil { - l.infoLog("sender: Error reading response body: %v", err) + l.debugLog("sender: Error reading response body: %v", err) } - l.infoLog("sender: Response status code: %v \n", statusCode) + l.debugLog("sender: Response status code: %v \n", statusCode) if statusCode == 200 { l.droppedLogs = 0 } @@ -338,16 +338,16 @@ func (l *LogzioSender) shouldRetry(statusCode int) bool { retry := true switch statusCode { case http.StatusBadRequest: - l.infoLog("sender: Got HTTP %d bad request, skip retry\n", statusCode) + l.debugLog("sender: Got HTTP %d bad request, skip retry\n", statusCode) retry = false case http.StatusNotFound: - l.infoLog("sender: Got HTTP %d not found, skip retry\n", statusCode) + l.debugLog("sender: Got HTTP %d not found, skip retry\n", statusCode) retry = false case http.StatusUnauthorized: - l.infoLog("sender: Got HTTP %d unauthorized, skip retry\n", statusCode) + l.debugLog("sender: Got HTTP %d unauthorized, skip retry\n", statusCode) retry = false case http.StatusForbidden: - l.infoLog("sender: Got HTTP %d forbidden, skip retry\n", statusCode) + l.debugLog("sender: Got HTTP %d forbidden, skip retry\n", statusCode) retry = false case http.StatusOK: retry = false @@ -362,7 +362,6 @@ func (l *LogzioSender) Drain() { return } l.mux.Lock() - l.debugLog("sender: draining queue\n") defer l.mux.Unlock() l.draining.Toggle() defer l.draining.Toggle() @@ -441,10 +440,6 @@ func (l *LogzioSender) debugLog(format string, a ...interface{}) { } } -func (l *LogzioSender) infoLog(format string, a ...interface{}) { - fmt.Fprintf(os.Stderr, format, a...) -} - func (l *LogzioSender) errorLog(format string, a ...interface{}) { fmt.Fprintf(os.Stderr, format, a...) }