Skip to content

Commit

Permalink
Merge pull request #1761 from perses/feat/dashboard-as-code
Browse files Browse the repository at this point in the history
Merge feature SDK Dashboard As Code
  • Loading branch information
Nexucis committed Feb 22, 2024
2 parents 2e8f8f3 + cf9ad35 commit 6298a0d
Show file tree
Hide file tree
Showing 213 changed files with 8,476 additions and 163 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand All @@ -86,7 +86,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand All @@ -107,7 +107,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delete-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand Down
36 changes: 25 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
- name: install mdox
run: go install github.com/bwplotka/mdox@latest
- name: check docs
run: make checkdocs

gofmt:
name: "check code format"
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
- name: install cue
run: go install cuelang.org/go/cmd/cue@v0.4.2
enable_cue: true
- name: check format
run: make checkformat
- name: check go.mod
Expand All @@ -60,10 +58,11 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
enable_cue: true # needed for DaC CLI commands unit tests
- name: test
run: make integration-test
test-mysql:
Expand All @@ -82,10 +81,11 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
enable_cue: true # needed for DaC CLI commands unit tests
- name: test
run: make mysql-integration-test
golangci:
Expand All @@ -94,7 +94,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
Expand All @@ -114,13 +114,27 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
- name: install cue
run: go install cuelang.org/go/cmd/cue@latest
enable_cue: true
- name: eval cue schema
run: make cue-eval
- name: test cue schema
run: make cue-test
check-cue-gen:
name: "check cue gen files"
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_go: true
enable_cue: true
- name: generate cue files
run: make cue-gen
- name: check for changes
run: git diff --exit-code || { echo "CUE generated files are not up to date. Please run 'make cue-gen' and commit the changes."; exit 1; }
6 changes: 3 additions & 3 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand All @@ -47,7 +47,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- uses: perses/github-actions@v0.2.0
- uses: perses/github-actions@v0.3.2
- uses: ./.github/perses-ci/actions/setup_environment
with:
enable_npm: true
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Thumbs.db


/bin
/built
/dist

coverage.txt
Expand All @@ -27,8 +28,7 @@ coverage.txt

EXTRACTED_CHANGELOG.md

cue.mod/pkg
cue.mod/usr
cue.mod/gen

dev/local_db

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ USER nobody
COPY --chown=nobody:nobody perses /bin/perses
COPY --chown=nobody:nobody percli /bin/percli
COPY --chown=nobody:nobody LICENSE /LICENSE
COPY --chown=nobody:nobody schemas/ /etc/perses/schemas/
COPY --chown=nobody:nobody cue/schemas/ /etc/perses/schemas/
COPY --chown=nobody:nobody cue.mod/ /etc/perses/cue.mod/
COPY --chown=nobody:nobody docs/examples/config.docker.yaml /etc/perses/config.yaml
COPY --from=build-env --chown=nobody:nobody /perses /perses
Expand Down
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 The Perses Authors
# Copyright 2024 The Perses Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -48,7 +48,7 @@ tag:
checkformat:
@echo ">> checking go code format"
! $(GOFMT) -d $$(find . -name '*.go' -not -path "./ui/*" -print) | grep '^'
@echo ">> running check for cue file format"
@echo ">> running check for CUE file format"
./scripts/cue.sh --checkformat

.PHONY: checkdocs
Expand Down Expand Up @@ -91,12 +91,19 @@ fmt-docs:

.PHONY: cue-eval
cue-eval:
@echo ">> eval cue schemas"
$(CUE) eval ./schemas/...
@echo ">> eval CUE files"
$(CUE) eval ./cue/...

.PHONY: cue-gen
cue-gen:
@echo ">> generate CUE definitions from golang datamodel"
$(CUE) get go github.com/perses/perses/pkg/model/api/v1
cp -r cue.mod/gen/github.com/perses/perses/pkg/model/* cue/model/ && rm -r cue.mod/gen
find cue/model -name "*.cue" -exec sed -i 's/\"github.com\/perses\/perses\/pkg/\"github.com\/perses\/perses\/cue/g' {} \;

.PHONY: cue-test
cue-test:
@echo ">> test cue schemas with json data"
@echo ">> test CUE schemas with json data"
$(GO) run ./scripts/cue-test/cue-test.go

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ progress. The current pieces that are in place are:
- The Plugin architecture has finally reached a stable point.
- The plugins concern the Variables, Panels, Queries and Datasources definitions.
- To provide a good static validation, the backend is using multiple CUE schemas and the CLI got a `lint` command.
All schemas are available in the [schemas](./schemas) folder.
All schemas are available in the [cue/schemas](./cue/schemas) folder.
- A backend REST API provides R/W access to dashboard and datasource definitions.
- A CLI that can be used to interact with the REST API. A short doc is available [here](./docs/tooling/cli.md)
- While the UI is still in progress, we already have:
Expand Down
8 changes: 5 additions & 3 deletions cmd/percli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os"

"github.com/perses/perses/internal/cli/cmd/apply"
"github.com/perses/perses/internal/cli/cmd/dac"
"github.com/perses/perses/internal/cli/cmd/describe"
"github.com/perses/perses/internal/cli/cmd/get"
"github.com/perses/perses/internal/cli/cmd/lint"
Expand All @@ -42,19 +43,20 @@ func newRootCommand() *cobra.Command {
Short: "Command line interface to interact with the Perses API",
}

// The list of the commands supported
// The list of supported commands
cmd.AddCommand(apply.NewCMD())
cmd.AddCommand(dac.NewCMD())
cmd.AddCommand(describe.NewCMD())
cmd.AddCommand(get.NewCMD())
cmd.AddCommand(lint.NewCMD())
cmd.AddCommand(login.NewCMD())
cmd.AddCommand(migrate.NewCMD())
cmd.AddCommand(refresh.NewCMD())
cmd.AddCommand(project.NewCMD())
cmd.AddCommand(refresh.NewCMD())
cmd.AddCommand(remove.NewCMD())
cmd.AddCommand(version.NewCMD())

// the list of the global flags supported
// the list of supported global flags
cmd.PersistentFlags().StringVar(&configPath, "percliconfig", config.GetDefaultPath(), "Path to the percliconfig file to use for CLI requests.")
cmd.PersistentFlags().StringVar(&logLevel, "log.level", "info", "Set the log verbosity level. Possible values: panic, fatal, error, warning, info, debug, trace")

Expand Down
44 changes: 44 additions & 0 deletions cue/dac-utils/dashboard/dashboard.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This package offers an utility to build a dashboards easily, by allowing
// to provide panels together with their layout.

package dashboard

import (
"github.com/perses/perses/cue/model/api/v1"
v1Dashboard "github.com/perses/perses/cue/model/api/v1/dashboard"
)

// expected user inputs
#name: string
#project: string
#variables: [...v1Dashboard.#Variable]
#panelGroups: [string]: {
layout: v1Dashboard.#Layout
panels: [string]: v1.#Panel
}

// output: the dashboard in the format expected by Perses
v1.#Dashboard & {
metadata: {
name: #name
project: #project
}
spec: {
variables: #variables
panels: {for group in #panelGroups {group.panels}}
layouts: [for group in #panelGroups {group.layout}]
}
}
Loading

0 comments on commit 6298a0d

Please sign in to comment.