Skip to content

Commit

Permalink
base 3 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raghu0891 committed Dec 12, 2024
1 parent b036c30 commit 241061c
Show file tree
Hide file tree
Showing 45 changed files with 2,113 additions and 810 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/observability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
go-version-file: "go.mod"

- name: Build
run: go build -v ./...
run: make build

- name: Unit Tests
run: go test -v ./...
run: make test
6 changes: 5 additions & 1 deletion observability-lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ lint:

.PHONY: test
test:
go test -v ./...
go test ./...

.PHONY: update
update:
go test ./dashboards/... -update=1
3 changes: 3 additions & 0 deletions observability-lib/dashboards/atlas-don/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func NewDashboard(props *Props) (*grafana.Dashboard, error) {
}

props.platformOpts = platformPanelOpts(props.OCRVersion)
if props.Tested {
props.platformOpts.LabelQuery = ""
}

builder := grafana.NewBuilder(&grafana.BuilderOptions{
Name: props.Name,
Expand Down
47 changes: 45 additions & 2 deletions observability-lib/dashboards/atlas-don/component_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package atlasdon_test

import (
"flag"
"os"
"testing"

Expand All @@ -11,12 +12,54 @@ import (
atlasdon "github.com/goplugin/plugin-common/observability-lib/dashboards/atlas-don"
)

var update = flag.Bool("update", false, "update golden test files")

const fileOutput = "test-output.json"

func TestGenerateFile(t *testing.T) {
if *update == false {
t.Skip("skipping test")
}

testDashboard, err := atlasdon.NewDashboard(&atlasdon.Props{
Name: "DON OCR Dashboard",
MetricsDataSource: grafana.NewDataSource("Prometheus", "1"),
OCRVersion: "ocr2",
Tested: true,
})
if err != nil {
t.Errorf("Error creating dashboard: %v", err)
}
json, errJSON := testDashboard.GenerateJSON()
if errJSON != nil {
t.Errorf("Error generating JSON: %v", errJSON)
}
if _, errExists := os.Stat(fileOutput); errExists == nil {
errRemove := os.Remove(fileOutput)
if errRemove != nil {
t.Errorf("Error removing file: %v", errRemove)
}
}
file, errFile := os.Create(fileOutput)
if errFile != nil {
panic(errFile)
}
writeString, err := file.WriteString(string(json))
if err != nil {
t.Errorf("Error writing to file: %v", writeString)
}
t.Cleanup(func() {
file.Close()
})
}

func TestNewDashboard(t *testing.T) {
t.Run("NewDashboard creates a dashboard", func(t *testing.T) {
testDashboard, err := atlasdon.NewDashboard(&atlasdon.Props{
Name: "DON OCR Dashboard",
MetricsDataSource: grafana.NewDataSource("Prometheus", "1"),
OCRVersion: "ocr2",
Tested: true,
})
if err != nil {
t.Errorf("Error creating dashboard: %v", err)
Expand All @@ -28,11 +71,11 @@ func TestNewDashboard(t *testing.T) {
t.Errorf("Error generating JSON: %v", errJSON)
}

jsonCompared, errCompared := os.ReadFile("test-output.json")
jsonCompared, errCompared := os.ReadFile(fileOutput)
if errCompared != nil {
t.Errorf("Error reading file: %v", errCompared)
}

require.ElementsMatch(t, jsonCompared, json)
require.JSONEq(t, string(jsonCompared), string(json))
})
}
1 change: 1 addition & 0 deletions observability-lib/dashboards/atlas-don/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Props struct {
MetricsDataSource *grafana.DataSource // MetricsDataSource is the datasource for querying metrics
OCRVersion string // OCRVersion is the version of the OCR (ocr, ocr2, ocr3)
platformOpts platformOpts
Tested bool
}

// PlatformPanelOpts generate different queries depending on params
Expand Down
Loading

0 comments on commit 241061c

Please sign in to comment.