Skip to content

Commit

Permalink
fix: add more input types for backend
Browse files Browse the repository at this point in the history
Signed-off-by: David van der Spek <[email protected]>
  • Loading branch information
davidspek committed Jul 14, 2023
1 parent 01b764e commit 7c8d767
Show file tree
Hide file tree
Showing 5 changed files with 718 additions and 27 deletions.
41 changes: 30 additions & 11 deletions api/observability/v1alpha1/loki_limit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ type LokiLimits struct {
type LokiLimitsInput LokiLimits

type StreamRetention struct {
Period metav1.Duration `yaml:"period" json:"period"`
Priority *int `yaml:"priority" json:"priority"`
Selector *string `yaml:"selector" json:"selector"`
// +kubebuilder:validation:Optional
Period *metav1.Duration `yaml:"period,omitempty" json:"period,omitempty"`
// +kubebuilder:validation:Optional
Priority *int `yaml:"priority,omitempty" json:"priority,omitempty"`
// +kubebuilder:validation:Optional
Selector *string `yaml:"selector,omitempty" json:"selector,omitempty"`
}

type StreamRetentionInput StreamRetention

type ShardstreamsConfig struct {
// +kubebuilder:validation:Optional
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
Expand All @@ -197,6 +202,8 @@ type ShardstreamsConfig struct {
DesiredRate *uint64 `yaml:"desired_rate,omitempty" json:"desired_rate,omitempty"`
}

type ShardstreamsConfigInput ShardstreamsConfig

type BlockedQuery struct {
// +kubebuilder:validation:Optional
Pattern *string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
Expand All @@ -209,6 +216,8 @@ type BlockedQuery struct {
Types *string `yaml:"types,omitempty" json:"types,omitempty"` // TODO: add validation that the string is a comma separated list of the types metric, filter and limited
}

type BlockedQueryInput BlockedQuery

type RulerAlertManagerConfig struct {
// URL of the Alertmanager to send notifications to.
AlertmanagerURL string `yaml:"alertmanager_url,omitempty" json:"alertmanager_url,omitempty"`
Expand All @@ -222,23 +231,25 @@ type RulerAlertManagerConfig struct {
AlertmanagerRefreshInterval *metav1.Duration `yaml:"alertmanager_refresh_interval,omitempty" json:"alertmanager_refresh_interval,omitempty"`
// Enables the ruler notifier to use the Alertmananger V2 API.
// +kubebuilder:validation:Optional
AlertmanangerEnableV2API bool `yaml:"enable_alertmanager_v2,omitempty" json:"enable_alertmanager_v2,omitempty"`
AlertmanangerEnableV2API *bool `yaml:"enable_alertmanager_v2,omitempty" json:"enable_alertmanager_v2,omitempty"`
// Configuration for alert relabeling.
// +kubebuilder:validation:Optional // TODO: remove all references to this to our own type since the yaml tags will be different
AlertRelabelConfigs []*RelabelConfig `yaml:"alert_relabel_configs,omitempty" json:"alert_relabel_configs,omitempty" doc:"description=List of alert relabel configs."`
// Capacity of the queue for notifications to be sent to the Alertmanager.
// +kubebuilder:validation:Optional
NotificationQueueCapacity int `yaml:"notification_queue_capacity,omitempty" json:"notification_queue_capacity,omitempty"`
NotificationQueueCapacity *int `yaml:"notification_queue_capacity,omitempty" json:"notification_queue_capacity,omitempty"`
// HTTP timeout duration when sending notifications to the Alertmanager.
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
NotificationTimeout *metav1.Duration `yaml:"notification_timeout,omitempty" json:"notification_timeout,omitempty"`
// Client configs for interacting with the Alertmanager
// +kubebuilder:validation:Optional
Notifier NotifierConfig `yaml:"alertmanager_client,omitempty" json:"alertmanager_client,omitempty"`
Notifier *NotifierConfig `yaml:"alertmanager_client,omitempty" json:"alertmanager_client,omitempty"`
}

type RulerAlertManagerConfigInput RulerAlertManagerConfig

type NotifierConfig struct {
// +kubebuilder:validation:Optional
TLS *NotifierTLSClientConfig `yaml:",inline,omitempty" json:",inline,omitempty"`
Expand All @@ -248,24 +259,30 @@ type NotifierConfig struct {
HeaderAuth *NotifierHeaderAuth `yaml:",inline,omitempty" json:",inline,omitempty"`
}

type NotifierConfigInput NotifierConfig

// NotifBasicAuth configures basic authentication for HTTP clients.
type NotifierBasicAuth struct {
// +kubebuilder:validation:Optional
Username string `yaml:"basic_auth_username,omitempty" json:"basic_auth_username,omitempty"`
Username *string `yaml:"basic_auth_username,omitempty" json:"basic_auth_username,omitempty"`
// +kubebuilder:validation:Optional
Password string `yaml:"basic_auth_password,omitempty" json:"basic_auth_password,omitempty"`
Password *string `yaml:"basic_auth_password,omitempty" json:"basic_auth_password,omitempty"`
}

type NotifierBasicAuthInput NotifierBasicAuth

// HeaderAuth condigures header based authorization for HTTP clients.
type NotifierHeaderAuth struct {
// +kubebuilder:validation:Optional
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Type *string `yaml:"type,omitempty" json:"type,omitempty"`
// +kubebuilder:validation:Optional
Credentials string `yaml:"credentials,omitempty" json:"credentials,omitempty"`
Credentials *string `yaml:"credentials,omitempty" json:"credentials,omitempty"`
// +kubebuilder:validation:Optional
CredentialsFile string `yaml:"credentials_file,omitempty" json:"credentials_file,omitempty"`
CredentialsFile *string `yaml:"credentials_file,omitempty" json:"credentials_file,omitempty"`
}

type NotifierHeaderAuthInput NotifierHeaderAuth

// ClientConfig is the config for client TLS.
type NotifierTLSClientConfig struct {
// +kubebuilder:validation:Optional
Expand All @@ -283,3 +300,5 @@ type NotifierTLSClientConfig struct {
// +kubebuilder:validation:Optional
MinVersion *string `yaml:"tls_min_version,omitempty" json:"tls_min_version,omitempty" category:"advanced"`
}

type NotifierTLSClientConfigInput NotifierTLSClientConfig
96 changes: 93 additions & 3 deletions api/observability/v1alpha1/prom_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package v1alpha1

import (
prom_v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"fmt"
"io"
"strconv"

prom_config "github.com/prometheus/common/config"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -174,11 +177,15 @@ type ProxyConfig struct {
ProxyConnectHeader prom_config.Header `yaml:"proxy_connect_header,omitempty" json:"proxy_connect_header,omitempty"`
}

// LabelName is a valid Prometheus label name which may only contain ASCII letters, numbers, as well as underscores.
// +kubebuilder:validation:Pattern:="^[a-zA-Z_][a-zA-Z0-9_]*$"
type LabelName string

type RelabelConfig struct {
// A list of labels from which values are taken and concatenated
// with the configured separator in order.
// +kubebuilder:validation:Optional
SourceLabels []*prom_v1.LabelName `yaml:"source_labels,omitempty" json:"source_labels,omitempty"`
SourceLabels []*LabelName `yaml:"source_labels,omitempty" json:"source_labels,omitempty"`
// Separator is the string between concatenated values from the source labels.
// +kubebuilder:validation:Optional
Separator *string `yaml:"separator,omitempty" json:"separator,omitempty"`
Expand All @@ -199,5 +206,88 @@ type RelabelConfig struct {
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=replace;Replace;keep;Keep;drop;Drop;hashmod;HashMod;labelmap;LabelMap;labeldrop;LabelDrop;labelkeep;LabelKeep;lowercase;Lowercase;uppercase;Uppercase;keepequal;KeepEqual;dropequal;DropEqual
// +kubebuilder:default=replace
Action *string `yaml:"action,omitempty" json:"action,omitempty"`
Action *RelabelAction `yaml:"action,omitempty" json:"action,omitempty"`
}

type RelabelConfigInput RelabelConfig

type RelabelAction string

const (
RelabelActionReplace RelabelAction = "replace"
RelabelActionReplace0 RelabelAction = "Replace"
RelabelActionKeep RelabelAction = "keep"
RelabelActionKeep0 RelabelAction = "Keep"
RelabelActionDrop RelabelAction = "drop"
RelabelActionDrop0 RelabelAction = "Drop"
RelabelActionHashmod RelabelAction = "hashmod"
RelabelActionHashMod RelabelAction = "HashMod"
RelabelActionLabelmap RelabelAction = "labelmap"
RelabelActionLabelMap RelabelAction = "LabelMap"
RelabelActionLabeldrop RelabelAction = "labeldrop"
RelabelActionLabelDrop RelabelAction = "LabelDrop"
RelabelActionLabelkeep RelabelAction = "labelkeep"
RelabelActionLabelKeep RelabelAction = "LabelKeep"
RelabelActionLowercase RelabelAction = "lowercase"
RelabelActionLowercase0 RelabelAction = "Lowercase"
RelabelActionUppercase RelabelAction = "uppercase"
RelabelActionUppercase0 RelabelAction = "Uppercase"
RelabelActionKeepequal RelabelAction = "keepequal"
RelabelActionKeepEqual RelabelAction = "KeepEqual"
RelabelActionDropequal RelabelAction = "dropequal"
RelabelActionDropEqual RelabelAction = "DropEqual"
)

var AllRelabelAction = []RelabelAction{
RelabelActionReplace,
RelabelActionReplace0,
RelabelActionKeep,
RelabelActionKeep0,
RelabelActionDrop,
RelabelActionDrop0,
RelabelActionHashmod,
RelabelActionHashMod,
RelabelActionLabelmap,
RelabelActionLabelMap,
RelabelActionLabeldrop,
RelabelActionLabelDrop,
RelabelActionLabelkeep,
RelabelActionLabelKeep,
RelabelActionLowercase,
RelabelActionLowercase0,
RelabelActionUppercase,
RelabelActionUppercase0,
RelabelActionKeepequal,
RelabelActionKeepEqual,
RelabelActionDropequal,
RelabelActionDropEqual,
}

func (e RelabelAction) IsValid() bool {
switch e {
case RelabelActionReplace, RelabelActionReplace0, RelabelActionKeep, RelabelActionKeep0, RelabelActionDrop, RelabelActionDrop0, RelabelActionHashmod, RelabelActionHashMod, RelabelActionLabelmap, RelabelActionLabelMap, RelabelActionLabeldrop, RelabelActionLabelDrop, RelabelActionLabelkeep, RelabelActionLabelKeep, RelabelActionLowercase, RelabelActionLowercase0, RelabelActionUppercase, RelabelActionUppercase0, RelabelActionKeepequal, RelabelActionKeepEqual, RelabelActionDropequal, RelabelActionDropEqual:
return true
}
return false
}

func (e RelabelAction) String() string {
return string(e)
}

func (e *RelabelAction) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}

*e = RelabelAction(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid RelabelAction", str)
}
return nil
}

func (e RelabelAction) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
106 changes: 105 additions & 1 deletion api/observability/v1alpha1/tempo_limit_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package v1alpha1

import (
"encoding/json"
"fmt"
"io"
"strconv"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -116,13 +121,49 @@ type FilterPolicy struct {
Exclude *PolicyMatch `yaml:"exclude,omitempty" json:"exclude,omitempty"`
}

type FilterPolicyInput FilterPolicy

type MatchType string

const (
Strict MatchType = "strict"
Regex MatchType = "regex"
)

var AllMatchType = []MatchType{
Strict,
Regex,
}

func (e MatchType) IsValid() bool {
switch e {
case Strict, Regex:
return true
}
return false
}

func (e MatchType) String() string {
return string(e)
}

func (e *MatchType) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}

*e = MatchType(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid MatchType", str)
}
return nil
}

func (e MatchType) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}

type PolicyMatch struct {
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=strict;regex
Expand All @@ -131,11 +172,72 @@ type PolicyMatch struct {
Attributes []MatchPolicyAttribute `yaml:"attributes,omitempty" json:"attributes,omitempty"`
}

type PolicyMatchInput PolicyMatch

type MatchPolicyAttribute struct {
// +kubebuilder:validation:Optional
Key *string `yaml:"key,omitempty" json:"key,omitempty"`

// +kubebuilder:validation:Optional
Value runtime.RawExtension `yaml:"value,omitempty" json:"value,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:Type=object
Value WrappedMap `yaml:"value,omitempty" json:"value,omitempty"`
}

type MatchPolicyAttributeInput MatchPolicyAttribute

type WrappedMap struct {
Object map[string]interface{} `yaml:",inline" json:",inline"`
}

// MarshalJSON defers JSON encoding to the wrapped map
func (w *WrappedMap) MarshalJSON() ([]byte, error) {
return json.Marshal(w.Object)
}

// UnmarshalJSON implements the Unmarshaler interface.
func (w *WrappedMap) UnmarshalJSON(data []byte) error {
var out map[string]interface{}
err := json.Unmarshal(data, &out)
if err != nil {
return err
}
w.Object = out
return nil
}

func (w *WrappedMap) DeepCopy() *WrappedMap {
if w != nil && w.Object != nil {
return &WrappedMap{
Object: runtime.DeepCopyJSON(w.Object),
}
}
c := NewWrappedMap()
return &c
}

// DeepCopyInto is an ~autogenerated~ deepcopy function, copying the receiver, writing into out. in must be non-nil.
// Works around https://github.com/kubernetes/code-generator/issues/50
func (w *WrappedMap) DeepCopyInto(out *WrappedMap) {
bytes, err := json.Marshal(w.Object)
if err != nil {
// we assume that it marshals cleanly because otherwise the resource would not have been
// created in the API server
panic(err)
}
var clone map[string]interface{}
err = json.Unmarshal(bytes, &clone)
if err != nil {
// we assume again optimistically because we just marshalled that the round trip works as well
panic(err)
}
out.Object = clone
}

// NewWrappedMap returns an empty WrappedMap
func NewWrappedMap() WrappedMap {
return WrappedMap{Object: map[string]interface{}{}}
}

type DimensionMappings struct {
Expand All @@ -146,3 +248,5 @@ type DimensionMappings struct {
// +kubebuilder:validation:Optional
Join *string `yaml:"join,omitempty" json:"join,omitempty"`
}

type DimensionMappingsInput DimensionMappings
Loading

0 comments on commit 7c8d767

Please sign in to comment.