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

Add CUE files for panel plugins #11

Merged
merged 1 commit into from
Nov 13, 2024
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
26 changes: 26 additions & 0 deletions BarChart/backend/bar.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 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.

package model

import (
"github.com/perses/perses/cue/schemas/common"
)

kind: "BarChart"
spec: close({
calculation: common.#calculation
format?: common.#format
sort?: "asc" | "desc"
mode?: "value" | "percentage"
})
12 changes: 12 additions & 0 deletions BarChart/backend/bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"kind": "BarChart",
"spec": {
"calculation": "last-number",
"format": {
"unit": "percent",
"decimalPlaces": 2
},
"sort": "desc",
"mode": "value"
}
}
23 changes: 23 additions & 0 deletions BarChart/backend/migrate.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if #panel.type != _|_ if #panel.type == "bargauge" {
kind: "BarChart"
spec: {
#calcName: *"\(#panel.options.reduceOptions.calcs[0])" | null // only consider [0] here as Perses's BarChart doesn't support individual calcs
calculation: [// switch
if #mapping.calc[#calcName] != _|_ {#mapping.calc[#calcName]},
{#defaultCalc},
][0]

#unitPath: *"\(#panel.fieldConfig.defaults.unit)" | null
if #unitPath != null if #mapping.unit[#unitPath] != _|_ {
format: {
unit: #mapping.unit[#unitPath]
}
}
#decimal: *(#panel.fieldConfig.defaults.decimal) | null
if #decimal != null {
format: {
decimalPlaces: #decimal
}
}
}
}
4 changes: 4 additions & 0 deletions BarChart/cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module: "github.com/perses/plugins/barchart@v0"
language: {
version: "v0.10.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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.

package common

#calculation: "first" | *"last" | "first-number" | "last-number" | "mean" | "sum" | "min" | "max"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2023 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.

package common

#format: #timeFormat | #percentFormat | #decimalFormat | #bytesFormat | #throughputFormat

#timeFormat: {
unit: "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years"
decimalPlaces?: number
}

#percentFormat: {
unit: "percent" | "percent-decimal"
decimalPlaces?: number
}

#decimalFormat: {
unit: "decimal"
decimalPlaces?: number
shortValues?: bool
}

#bytesFormat: {
unit: "bytes"
decimalPlaces?: number
shortValues?: bool
}

#throughputFormat: {
unit: "bits/sec" | "bytes/sec" | "counts/sec" | "events/sec" | "messages/sec" | "ops/sec" | "packets/sec" | "reads/sec" | "records/sec" | "requests/sec" | "rows/sec" | "writes/sec"
decimalPlaces?: number
shortValues?: bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2023 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.

package proxy

import (
"github.com/perses/perses/cue/schemas/common"
)

#HTTPAllowedEndpoint: {
endpointPattern: string
method: "POST" | "PUT" | "PATCH" | "GET" | "DELETE"
}

#HTTPProxy: {
kind: "HTTPProxy"
spec: {
// url is the url of the datasource. It is not the url of the proxy.
// The Perses server is the proxy, so it needs to know where to redirect the request.
url: common.#url
// allowedEndpoints is a list of tuples of http methods and http endpoints that will be accessible.
// Leave it empty if you don't want to restrict the access to the datasource.
allowedEndpoints?: [...#HTTPAllowedEndpoint]
// headers can be used to provide additional headers that need to be forwarded when requesting the datasource
headers?: {[string]: string}
// secret is the name of the secret that should be used for the proxy or discovery configuration
// It will contain any sensitive information such as password, token, certificate.
secret?: string
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 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.

package common

#stepOption: {
value: number
color?: string
name?: string
}

#thresholds: {
mode?: "percent" | "absolute"
defaultColor?: string
steps?: [...#stepOption]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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.

package common

#url: =~"^https?:\/\/[^\\s\/$.?#].[^\\s]*$"
26 changes: 26 additions & 0 deletions GaugeChart/backend/gauge.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 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.

package model

import (
"github.com/perses/perses/cue/schemas/common"
)

kind: "GaugeChart"
spec: close({
calculation: common.#calculation
format?: common.#format
thresholds?: common.#thresholds
max?: number // determines end value of last threshold color segment when unit is not a percent
})
20 changes: 20 additions & 0 deletions GaugeChart/backend/gauge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"kind": "GaugeChart",
"spec": {
"calculation": "last-number",
"format": {
"unit": "percent",
"decimalPlaces": 2
},
"thresholds": {
"steps": [
{
"value": 85
},
{
"value": 95
}
]
}
}
}
39 changes: 39 additions & 0 deletions GaugeChart/backend/migrate.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
if #panel.type != _|_ if #panel.type == "gauge" {
kind: "GaugeChart"
spec: {
#calcName: *"\(#panel.options.reduceOptions.calcs[0])" | null // only consider [0] here as Perses's GaugeChart doesn't support individual calcs
calculation: [// switch
if #mapping.calc[#calcName] != _|_ {#mapping.calc[#calcName]},
#defaultCalc,
][0]

#unitPath: *"\(#panel.fieldConfig.defaults.unit)" | null
if #unitPath != null if #mapping.unit[#unitPath] != _|_ {
format: {
unit: #mapping.unit[#unitPath]
}
}
#decimal: *(#panel.fieldConfig.defaults.decimal) | null
if #decimal != null {
format: {
decimalPlaces: #decimal
}
}

if #panel.fieldConfig.defaults.thresholds != _|_ if #panel.fieldConfig.defaults.thresholds.steps != _|_ {
thresholds: {
// defaultColor: TODO how to fill this one?
steps: [for _, step in #panel.fieldConfig.defaults.thresholds.steps if step.value != _|_ {
value: [// switch
if step.value == null {0},
step.value,
][0]
color: step.color
}]
}
}
if #panel.fieldConfig.defaults.max != _|_ {
max: #panel.fieldConfig.defaults.max
}
}
},
4 changes: 4 additions & 0 deletions GaugeChart/cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module: "github.com/perses/plugins/gaugechart@v0"
language: {
version: "v0.10.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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.

package common

#calculation: "first" | *"last" | "first-number" | "last-number" | "mean" | "sum" | "min" | "max"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2023 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.

package common

#format: #timeFormat | #percentFormat | #decimalFormat | #bytesFormat | #throughputFormat

#timeFormat: {
unit: "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years"
decimalPlaces?: number
}

#percentFormat: {
unit: "percent" | "percent-decimal"
decimalPlaces?: number
}

#decimalFormat: {
unit: "decimal"
decimalPlaces?: number
shortValues?: bool
}

#bytesFormat: {
unit: "bytes"
decimalPlaces?: number
shortValues?: bool
}

#throughputFormat: {
unit: "bits/sec" | "bytes/sec" | "counts/sec" | "events/sec" | "messages/sec" | "ops/sec" | "packets/sec" | "reads/sec" | "records/sec" | "requests/sec" | "rows/sec" | "writes/sec"
decimalPlaces?: number
shortValues?: bool
}
Loading