Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 1.12/1.11 & multiple Grafana versions #70

Merged
merged 7 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,65 @@
---
language: go

services:
- docker
- docker

# Versions of go that are explicitly supported.
go:
- 1.13.x

env:
- GRAFANA_INTEGRATION=1
# Different Grafana + Go versions that will be tested.
jobs:
include:
- name: "Grafana 6.6.2 1.13.x"
env:
- "GRAFANA_VERSION=6.6.2"
- "GRAFANA_INTEGRATION=1"
go: "1.13.x"
- name: "Grafana 6.5.3 1.13.x"
env:
- "GRAFANA_VERSION=6.5.3"
- "GRAFANA_INTEGRATION=1"
go: "1.13.x"
- name: "Grafana 6.4.5 1.13.x"
env:
- "GRAFANA_VERSION=6.4.5 1.13.x"
- "GRAFANA_INTEGRATION=1"
go: "1.13.x"
- name: "Grafana 6.6.2 1.12.x"
env:
- "GRAFANA_VERSION=6.6.2"
- "GRAFANA_INTEGRATION=1"
go: "1.12.x"
- name: "Grafana 6.5.3 1.12.x"
env:
- "GRAFANA_VERSION=6.5.3"
- "GRAFANA_INTEGRATION=1"
go: "1.12.x"
- name: "Grafana 6.4.5 1.12.x"
env:
- "GRAFANA_VERSION=6.4.5"
- "GRAFANA_INTEGRATION=1"
go: "1.12.x"
- name: "Grafana 6.6.2 1.11.x"
env:
- "GRAFANA_VERSION=6.6.2"
- "GRAFANA_INTEGRATION=1"
go: "1.11.x"
- name: "Grafana 6.5.3 1.11.x"
env:
- "GRAFANA_VERSION=6.5.3"
- "GRAFANA_INTEGRATION=1"
go: "1.11.x"
- name: "Grafana 6.4.5 1.11.x"
env:
- "GRAFANA_VERSION=6.4.5"
- "GRAFANA_INTEGRATION=1"
go: "1.11.x"

# Required for coverage.
before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
# Run Grafana
- docker pull grafana/grafana:6.6.0
- docker run --rm -d -p 3000:3000 grafana/grafana:6.6.0
- "docker pull grafana/grafana:$GRAFANA_VERSION"
- "docker run --rm -d -p 3000:3000 grafana/grafana:$GRAFANA_VERSION"

# only one subpackage tested yet
script:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.13

require (
github.com/gosimple/slug v1.1.1
github.com/pkg/errors v0.9.1
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4=
github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
26 changes: 14 additions & 12 deletions rest-annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/url"
"strconv"
"time"

"github.com/pkg/errors"
)

// https://grafana.com/docs/grafana/latest/http_api/annotations/
Expand All @@ -18,13 +20,13 @@ func (r *Client) CreateAnnotation(a CreateAnnotationRequest) (StatusMessage, err
err error
)
if raw, err = json.Marshal(a); err != nil {
return StatusMessage{}, fmt.Errorf("failed to marshal request: %w", err)
return StatusMessage{}, errors.Wrap(err, "marshal request")
}
if raw, _, err = r.post("api/annotations", nil, raw); err != nil {
return StatusMessage{}, fmt.Errorf("failed to create annotation: %w", err)
return StatusMessage{}, errors.Wrap(err, "create annotation")
}
if err = json.Unmarshal(raw, &resp); err != nil {
return StatusMessage{}, fmt.Errorf("failed to unmarshal response message: %w", err)
return StatusMessage{}, errors.Wrap(err, "unmarshal response message")
}
return resp, nil
}
Expand All @@ -37,13 +39,13 @@ func (r *Client) PatchAnnotation(id uint, a PatchAnnotationRequest) (StatusMessa
err error
)
if raw, err = json.Marshal(a); err != nil {
return StatusMessage{}, fmt.Errorf("failed to marshal request: %w", err)
return StatusMessage{}, errors.Wrap(err, "marshal request")
}
if raw, _, err = r.patch(fmt.Sprintf("api/annotations/%d", id), nil, raw); err != nil {
return StatusMessage{}, fmt.Errorf("failed to patch annotation: %w", err)
return StatusMessage{}, errors.Wrap(err, "patch annotation")
}
if err = json.Unmarshal(raw, &resp); err != nil {
return StatusMessage{}, fmt.Errorf("failed to unmarshal response message: %w", err)
return StatusMessage{}, errors.Wrap(err, "unmarshal response message")
}
return resp, nil
}
Expand All @@ -62,10 +64,10 @@ func (r *Client) GetAnnotations(params ...GetAnnotationsParams) ([]AnnotationRes
}

if raw, _, err = r.get("api/annotations", requestParams); err != nil {
return nil, fmt.Errorf("failed to get annotations: %w", err)
return nil, errors.Wrap(err, "get annotations")
}
if err = json.Unmarshal(raw, &resp); err != nil {
return nil, fmt.Errorf("failed to unmarshal response message: %w", err)
return nil, errors.Wrap(err, "unmarshal response message")
}
return resp, nil
}
Expand All @@ -79,15 +81,15 @@ func (r *Client) DeleteAnnotation(id uint) (StatusMessage, error) {
)

if raw, _, err = r.delete(fmt.Sprintf("api/annotations/%d", id)); err != nil {
return StatusMessage{}, fmt.Errorf("failed to delete annotation: %w", err)
return StatusMessage{}, errors.Wrap(err, "delete annotation")
}
if err = json.Unmarshal(raw, &resp); err != nil {
return StatusMessage{}, fmt.Errorf("failed to unmarshal response message: %w", err)
return StatusMessage{}, errors.Wrap(err, "unmarshal response message")
}
return resp, nil
}

// AnnotationOption is the type for all options implementing query parameters
// GetAnnotationsParams is the type for all options implementing query parameters
// https://grafana.com/docs/grafana/latest/http_api/annotations/#find-annotations
type GetAnnotationsParams func(values url.Values)

Expand Down Expand Up @@ -155,5 +157,5 @@ func WithEndTime(t time.Time) GetAnnotationsParams {
}

func toMilliseconds(t time.Time) int64 {
return t.UnixNano() / 1_000_000
return t.UnixNano() / 1000000
}
2 changes: 1 addition & 1 deletion rest-annotation_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAnnotations(t *testing.T) {

ar := sdk.CreateAnnotationRequest{
Text: "test",
Time: time.Now().UnixNano() / 1_000_000,
Time: time.Now().UnixNano() / 1000000,
}
resp, err := client.CreateAnnotation(ar)
if err != nil {
Expand Down