Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
add documentation

Fix compilation issue
  • Loading branch information
krysalead committed Jul 1, 2019
1 parent 0e797b0 commit e2da9fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/grafana-reporter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

// ServeReportHandler interface facilitates testsing the reportServing http handler
type ServeReportHandler struct {
newGrafanaClient func(url string, apiToken string, variables url.Values) grafana.Client
newGrafanaClient func(url string, apiToken string, variables url.Values, sslCheck bool) grafana.Client
newReport func(g grafana.Client, dashName string, time grafana.TimeRange, texTemplate string) report.Report
}

Expand All @@ -47,7 +47,7 @@ func RegisterHandlers(router *mux.Router, reportServerV4, reportServerV5 ServeRe

func (h ServeReportHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
log.Print("Reporter called")
g := h.newGrafanaClient(*proto+*ip, apiToken(req), dashVariables(req))
g := h.newGrafanaClient(*proto+*ip, apiToken(req), dashVariables(req), *sslCheck)
rep := h.newReport(g, dashID(req), time(req), texTemplate(req))

file, err := rep.Generate()
Expand Down
6 changes: 5 additions & 1 deletion cmd/grafana-reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func main() {

//'generated*'' variables injected from build.gradle: task 'injectGoVersion()'
log.Printf("grafana reporter, version: %s.%s-%s hash: %s", generatedMajor, generatedMinor, generatedRelease, generatedGitHash)
log.Printf("serving at '%s' and using grafana at '%s'", *port, *ip)
sslState := "SSL check"
if !*sslCheck {
sslState = "No SSL check"
}
log.Printf("serving at '%s' and using grafana at '%s' %s", *port, *ip, sslState)

router := mux.NewRouter()
RegisterHandlers(
Expand Down
12 changes: 6 additions & 6 deletions grafana/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGrafanaClientFetchesDashboard(t *testing.T) {
defer ts.Close()

Convey("When using the Grafana v4 client", func() {
grf := NewV4Client(ts.URL, "", url.Values{})
grf := NewV4Client(ts.URL, "", url.Values{}, true)
grf.GetDashboard("testDash")

Convey("It should use the v4 dashboards endpoint", func() {
Expand All @@ -46,7 +46,7 @@ func TestGrafanaClientFetchesDashboard(t *testing.T) {
})

Convey("When using the Grafana v5 client", func() {
grf := NewV5Client(ts.URL, "", url.Values{})
grf := NewV5Client(ts.URL, "", url.Values{}, true)
grf.GetDashboard("rYy7Paekz")

Convey("It should use the v5 dashboards endpoint", func() {
Expand Down Expand Up @@ -77,8 +77,8 @@ func TestGrafanaClientFetchesPanelPNG(t *testing.T) {
client Client
pngEndpoint string
}{
"v4": {NewV4Client(ts.URL, apiToken, variables), "/render/dashboard-solo/db/testDash"},
"v5": {NewV5Client(ts.URL, apiToken, variables), "/render/d-solo/testDash/_"},
"v4": {NewV4Client(ts.URL, apiToken, variables, true), "/render/dashboard-solo/db/testDash"},
"v5": {NewV5Client(ts.URL, apiToken, variables, true), "/render/d-solo/testDash/_"},
}
for clientDesc, cl := range cases {
grf := cl.client
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestGrafanaClientFetchPanelPNGErrorHandling(t *testing.T) {
}))
defer ts.Close()

grf := NewV4Client(ts.URL, "", url.Values{})
grf := NewV4Client(ts.URL, "", url.Values{}, true)

_, err := grf.GetPanelPng(Panel{44, "singlestat", "title"}, "testDash", TimeRange{"now-1h", "now"})

Expand All @@ -158,7 +158,7 @@ func TestGrafanaClientFetchPanelPNGErrorHandling(t *testing.T) {
}))
defer ts.Close()

grf := NewV4Client(ts.URL, "", url.Values{})
grf := NewV4Client(ts.URL, "", url.Values{}, true)

_, err := grf.GetPanelPng(Panel{44, "singlestat", "title"}, "testDash", TimeRange{"now-1h", "now"})

Expand Down
19 changes: 12 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

# Grafana reporter <img style="float: right;" src="https://travis-ci.org/IzakMarais/reporter.svg?branch=master">

A simple http service that generates *.PDF reports from [Grafana](http://grafana.org/) dashboards.
A simple http service that generates \*.PDF reports from [Grafana](http://grafana.org/) dashboards.

![demo](demo/report_v5.gif)

## Requirements

Runtime requirements
* `pdflatex` installed and available in PATH.
* a running Grafana instance that it can connect to. If you are using an old Grafana (version < v5.0), see `Deprecated Endpoint` below.

- `pdflatex` installed and available in PATH.
- a running Grafana instance that it can connect to. If you are using an old Grafana (version < v5.0), see `Deprecated Endpoint` below.

Build requirements:
* [golang](https://golang.org/)

- [golang](https://golang.org/)

## Getting started

Expand All @@ -34,6 +35,10 @@ Query available flags:

grafana-reporter --help

Deactivates the SSL checks:

grafana-reporter -ssl-check false

### Generate a dashboard report

#### Endpoint
Expand Down Expand Up @@ -96,7 +101,7 @@ If you also have `Make` and `Docker-compose` installed, you can run a simple loc
make compose-up

Then open a browser to `http://localhost:3000` and create a new test dashboard. Add the example graph and save the dashboard.
Observe the new URL and find the dashboard UID, e.g. `qaJCuCezz` from `http://localhost:3000/d/qaJCuCezz/new-dashboard-copy`
Observe the new URL and find the dashboard UID, e.g. `qaJCuCezz` from `http://localhost:3000/d/qaJCuCezz/new-dashboard-copy`
Next, go to: `http://localhost:8080/api/v5/report/qaJCuCezz`, which will output the grafana-reporter PDF.

## Development
Expand All @@ -113,5 +118,5 @@ or, the [GoConvey](http://goconvey.co/) webGUI:

### Release

A new release requires changes to the git tag, `cmd/grafana-reporter/version.go` and `Makefile: docker-build` job.
A new release requires changes to the git tag, `cmd/grafana-reporter/version.go` and `Makefile: docker-build` job.
Build the Docker image and push to Dockerhub.

0 comments on commit e2da9fa

Please sign in to comment.