Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: influxdata/influxdb-client-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.12.0
Choose a base ref
...
head repository: influxdata/influxdb-client-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.12.1
Choose a head ref
  • 9 commits
  • 8 files changed
  • 3 contributors

Commits on Oct 27, 2022

  1. Copy the full SHA
    4bbb786 View commit details

Commits on Nov 11, 2022

  1. Copy the full SHA
    b683d3f View commit details

Commits on Nov 15, 2022

  1. Merge pull request #363 from bonitoo-io/fix/v1-api-error

    fix: return also v1 error from generated code
    vlastahajek authored Nov 15, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    63ea2e1 View commit details
  2. Copy the full SHA
    6f2f8f9 View commit details
  3. Copy the full SHA
    cae80f4 View commit details
  4. Merge pull request #364 from bonitoo-io/fix/retryAttempts-limit

    fix: retry delay calculation check
    vlastahajek authored Nov 15, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5971a9a View commit details

Commits on Dec 1, 2022

  1. Copy the full SHA
    f9a2425 View commit details
  2. Merge pull request #366 from bonitoo-io/docs/readme-improvements

    docs: Readme improvements
    vlastahajek authored Dec 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    78855a4 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    powersj Joshua Powers
    Copy the full SHA
    539f088 View commit details
Showing with 63 additions and 39 deletions.
  1. +12 −2 CHANGELOG.md
  2. +19 −5 README.md
  3. +9 −2 domain/client.gen.go
  4. +9 −2 domain/templates/client.tmpl
  5. +0 −21 domain/utils.go
  6. +9 −5 internal/write/service.go
  7. +4 −1 internal/write/service_test.go
  8. +1 −1 version.go
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
## 2.12.1 [2022-12-01]
### Bug fixes
- [#363](https://github.com/influxdata/influxdb-client-go/pull/363) Generated server stubs return also error message from InfluxDB 1.x forward compatible API.
- [#364](https://github.com/influxdata/influxdb-client-go/pull/364) Fixed panic when retrying over a long period without a server connection.

### Documentation
- [#366](https://github.com/influxdata/influxdb-client-go/pull/366) Readme improvements:
- Added GOPATH installation description
- Added error handling to Basic Example.

## 2.12.0 [2022-10-27]
### Features
- [#358](https://github.com/influxdata/influxdb-client-go/pull/358):
- Added possibility to set an application name, which will be part of the User-Agent HTTP header:
- Set using `Options.SetApplicationName`
- Warning message is written to log if an application name is not set
- Warning message is written to log if an application name is not set
- This may change to be logged as an error in a future release
- Added example how to fully override `User-Agent` header using `Doer` interface

### Bug fixes
- [#359](https://github.com/influxdata/influxdb-client-go/pull/359) `WriteAPIBlocking.Flush()` correctly returns nil error.
- [#359](https://github.com/influxdata/influxdb-client-go/pull/359) `WriteAPIBlocking.Flush()` correctly returns nil error.

## 2.11.0 [2022-09-29]
### Features
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ This repository contains the reference Go client for InfluxDB 2.
- [Documentation](#documentation)
- [Examples](#examples)
- [How To Use](#how-to-use)
- [Installation](#installation)
- [Basic Example](#basic-example)
- [Writes in Detail](#writes)
- [Queries in Detail](#queries)
@@ -64,11 +65,17 @@ There are also other examples in the API docs:
### Installation
**Go 1.17** or later is required.

1. Add the client package your to your project dependencies (go.mod).
#### Go mod project
1. Add the latest version of the client package to your project dependencies (go.mod).
```sh
go get github.com/influxdata/influxdb-client-go/v2
```
1. Add import `github.com/influxdata/influxdb-client-go/v2` to your source code.
#### GOPATH project
```sh
go get github.com/influxdata/influxdb-client-go
```
Note: To have _go get_ in the GOPATH mode, the environment variable `GO111MODULE` must have the `off` value.

### Basic Example
The following example demonstrates how to write data to InfluxDB 2 and read them back using the Flux language:
@@ -101,12 +108,17 @@ func main() {
AddField("avg", 23.2).
AddField("max", 45.0).
SetTime(time.Now())
writeAPI.WritePoint(context.Background(), p)
err := writeAPI.WritePoint(context.Background(), p)
if err != nil {
panic(err)
}
// Or write directly line protocol
line := fmt.Sprintf("stat,unit=temperature avg=%f,max=%f", 23.5, 45.0)
writeAPI.WriteRecord(context.Background(), line)
err = writeAPI.WriteRecord(context.Background(), line)
if err != nil {
panic(err)
}
// Get query client
queryAPI := client.QueryAPI("my-org")
// Get parser flux query result
@@ -124,6 +136,8 @@ func main() {
if result.Err() != nil {
fmt.Printf("Query error: %s\n", result.Err().Error())
}
} else {
panic(err)
}
// Ensures background processes finishes
client.Close()
11 changes: 9 additions & 2 deletions domain/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions domain/templates/client.tmpl
Original file line number Diff line number Diff line change
@@ -62,16 +62,23 @@ func isJSON(rsp *http.Response) bool {

func decodeError(body []byte, rsp *http.Response) error {
if isJSON(rsp) {
var serverError Error
var serverError struct {
Error
V1Error *string `json:"error,omitempty"`
}
err := json.Unmarshal(body, &serverError)
if err != nil {
message := fmt.Sprintf("cannot decode error response: %v", err)
serverError.Message = &message
}
if serverError.V1Error != nil {
serverError.Message = serverError.V1Error
serverError.Code = ErrorCodeInvalid
}
if serverError.Message == nil && serverError.Code == "" {
serverError.Message = &rsp.Status
}
return serverError.Error()
return serverError.Error.Error()
} else {
message := rsp.Status
if len(body) > 0 {
21 changes: 0 additions & 21 deletions domain/utils.go

This file was deleted.

14 changes: 9 additions & 5 deletions internal/write/service.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ type Batch struct {
RetryAttempts uint
// true if it was removed from queue
Evicted bool
// time where this batch expires
// time when this batch expires
Expires time.Time
}

@@ -105,10 +105,10 @@ func (w *Service) SetBatchErrorCallback(cb BatchErrorCallback) {

// HandleWrite handles writes of batches and handles retrying.
// Retrying is triggered by new writes, there is no scheduler.
// It first checks retry queue, cause it has highest priority.
// It first checks retry queue, because it has the highest priority.
// If there are some batches in retry queue, those are written and incoming batch is added to end of retry queue.
// Immediate write is allowed only in case there was success or not retryable error.
// Otherwise delay is checked based on recent batch.
// Otherwise, delay is checked based on recent batch.
// If write of batch fails with retryable error (connection errors and HTTP code >= 429),
// Batch retry time is calculated based on #of attempts.
// If writes continues failing and # of attempts reaches maximum or total retry time reaches maxRetryTime,
@@ -249,13 +249,17 @@ func isIgnorableError(error *http2.Error) bool {
return false
}

// computeRetryDelay calculates retry delay
// computeRetryDelay calculates retry delay.
// Retry delay is calculated as random value within the interval
// [retry_interval * exponential_base^(attempts) and retry_interval * exponential_base^(attempts+1)]
func (w *Service) computeRetryDelay(attempts uint) uint {
minDelay := int(w.writeOptions.RetryInterval() * pow(w.writeOptions.ExponentialBase(), attempts))
maxDelay := int(w.writeOptions.RetryInterval() * pow(w.writeOptions.ExponentialBase(), attempts+1))
retryDelay := uint(rand.Intn(maxDelay-minDelay) + minDelay)
diff := maxDelay - minDelay
if diff <= 0 { //check overflows
return w.writeOptions.MaxRetryInterval()
}
retryDelay := uint(rand.Intn(diff) + minDelay)
if retryDelay > w.writeOptions.MaxRetryInterval() {
retryDelay = w.writeOptions.MaxRetryInterval()
}
5 changes: 4 additions & 1 deletion internal/write/service_test.go
Original file line number Diff line number Diff line change
@@ -467,7 +467,10 @@ func TestComputeRetryDelay(t *testing.T) {
assertBetween(t, srv.computeRetryDelay(2), 20_000, 40_000)
assertBetween(t, srv.computeRetryDelay(3), 40_000, 80_000)
assertBetween(t, srv.computeRetryDelay(4), 80_000, 125_000)
assert.EqualValues(t, 125_000, srv.computeRetryDelay(5))

for i := uint(5); i < 200; i++ { //test also limiting higher values
assert.EqualValues(t, 125_000, srv.computeRetryDelay(i))
}
}

func TestErrorCallback(t *testing.T) {
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import (

const (
// Version defines current version
Version = "2.12.0"
Version = "2.12.1"
)

func init() {