Skip to content

Commit

Permalink
WIP: Define schema with cue
Browse files Browse the repository at this point in the history
Closes: #20
Signed-off-by: Michael Gasch <mgasch@vmware.com>
  • Loading branch information
Michael Gasch committed Jun 14, 2021
1 parent 17a7ba3 commit e52c778
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/meta.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1alpha1

#apiVersion: string
#kind: string
#metadata: {
// TODO: fix regex - requires at least two chars
name: =~"^[a-z0-9][a-z0-9_]{1,61}[a-z0-9]$" & string
// optional
displayName?: string
// map[string]string, optional
labels?: [string]: string
}
198 changes: 198 additions & 0 deletions spec/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"openapi": "3.0.0",
"info": {
"title": "Generated by cue.",
"version": "no version"
},
"paths": {},
"components": {
"schemas": {
"apiVersion": {
"type": "string"
},
"indicator": {
"type": "object"
},
"kind": {
"type": "string"
},
"metadata": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "TODO: fix regex - requires at least two chars",
"type": "string",
"pattern": "^[a-z0-9][a-z0-9_]{1,61}[a-z0-9]$"
},
"displayName": {
"description": "optional",
"type": "string"
},
"labels": {
"description": "map[string]string, optional",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"spec": {
"type": "object",
"required": [
"service",
"timeWindow",
"budgetingMethod"
],
"properties": {
"service": {
"description": "list?",
"type": "string"
},
"description": {
"description": "optional\nTODO: 1050 exceeds go regex limit (1000)",
"type": "string"
},
"timeWindow": {
"description": "object oneOf",
"type": "object",
"oneOf": [
{
"$ref": "#/components/schemas/timeWindowSecond"
},
{
"$ref": "#/components/schemas/timeWindowCalendar"
}
]
},
"budgetingMethod": {
"description": "objectives:\nindicator:",
"type": "string",
"enum": [
"Occurrences",
"Timeslices"
]
}
}
},
"thresholdMetric": {
"type": "object",
"required": [
"source",
"queryType",
"query"
],
"properties": {
"source": {
"type": "string"
},
"queryType": {
"type": "string"
},
"query": {
"type": "string"
}
}
},
"timeWindow": {
"type": "object",
"required": [
"unit",
"count",
"isRolling"
],
"properties": {
"unit": {
"type": "string"
},
"count": {
"type": "string"
},
"isRolling": {
"type": "boolean"
}
}
},
"timeWindowCalendar": {
"type": "object",
"properties": {
"unit": {
"type": "string",
"enum": [
"Year",
"Quarter",
"Month",
"Week",
"Day"
]
},
"count": {
"type": "string",
"enum": [
"numeric"
]
},
"calendar": {
"type": "object",
"required": [
"startTime"
],
"properties": {
"startTime": {
"description": "note: leap-seconds not supported",
"type": "string"
}
}
}
},
"allOf": [
{
"$ref": "#/components/schemas/timeWindow"
},
{
"required": [
"unit",
"count"
]
},
{
"required": [
"calendar"
]
}
]
},
"timeWindowSecond": {
"type": "object",
"properties": {
"unit": {
"type": "string",
"enum": [
"Second"
]
},
"count": {
"type": "string",
"enum": [
"numeric"
]
}
},
"allOf": [
{
"$ref": "#/components/schemas/timeWindow"
},
{
"required": [
"unit",
"count"
]
}
]
}
}
}
}
15 changes: 15 additions & 0 deletions spec/slo-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: openslo/v1alpha1
kind: SLO
metadata:
name: "a_name"
displayName: "a display name"
spec:
service: "name"
description: "1234567890"
timeWindow:
unit: "Day"
count: numeric
isRolling: true
calendar:
startTime: "2009-11-10T23:00:00Z"
budgetingMethod: Occurrences
6 changes: 6 additions & 0 deletions spec/slo.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v1alpha1

apiVersion: "openslo/v1alpha1" & #apiVersion
kind: "SLO" & #kind
metadata: #metadata
spec: #spec
50 changes: 50 additions & 0 deletions spec/spec.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package v1alpha1

import "time"

#spec: {
// list?
service: string
// optional
// TODO: 1050 exceeds go regex limit (1000)
description?: string
// object oneOf
timeWindow: #timeWindowSecond | #timeWindowCalendar
budgetingMethod: "Occurrences" | "Timeslices"
// objectives:
// indicator:
}

#indicator: {

}

#thresholdMetric: {
source: string
queryType: string
query: string
}

#timeWindow: {
unit: string
count: string
isRolling: bool
}

#timeWindowSecond: {
#timeWindow & {
unit: "Second"
count: "numeric"
}
}

#timeWindowCalendar: {
#timeWindow & {
unit: "Year" | "Quarter" | "Month" | "Week" | "Day"
count: "numeric"
}
calendar: {
// note: leap-seconds not supported
startTime: time.Format(time.RFC3339)
}
}

0 comments on commit e52c778

Please sign in to comment.