Skip to content

Commit

Permalink
api/vmagent: changes diskMaxUsage bytes param from int32 to int64
Browse files Browse the repository at this point in the history
int32 doesn't allow to correctly use this option
  • Loading branch information
f41gh7 committed Sep 29, 2022
1 parent 2bb5d02 commit 47f2b50
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/vmagent_types.go
Expand Up @@ -385,7 +385,7 @@ type VMAgentRemoteWriteSettings struct {

// The maximum file-based buffer size in bytes at -remoteWrite.tmpDataPath
// +optional
MaxDiskUsagePerURL *int32 `json:"maxDiskUsagePerURL,omitempty"`
MaxDiskUsagePerURL *int64 `json:"maxDiskUsagePerURL,omitempty"`
// The number of concurrent queues
// +optional
Queues *int32 `json:"queues,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/victoriametrics/v1beta1/vmagent_types.go
Expand Up @@ -385,7 +385,7 @@ type VMAgentRemoteWriteSettings struct {

// The maximum file-based buffer size in bytes at -remoteWrite.tmpDataPath
// +optional
MaxDiskUsagePerURL *int32 `json:"maxDiskUsagePerURL,omitempty"`
MaxDiskUsagePerURL *int64 `json:"maxDiskUsagePerURL,omitempty"`
// The number of concurrent queues
// +optional
Queues *int32 `json:"queues,omitempty"`
Expand Down
92 changes: 92 additions & 0 deletions api/victoriametrics/v1beta1/vmalertmanagerconfig_test.go
@@ -0,0 +1,92 @@
package v1beta1

import (
"gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"reflect"
"testing"
)

func TestParsingPagerDutyConfig(t *testing.T) {
f := func(srcYAML string, wantConfig PagerDutyConfig) {
t.Helper()
var gotPD PagerDutyConfig
if err := yaml.Unmarshal([]byte(srcYAML), &gotPD); err != nil {
t.Fatalf("cannot parse from yaml: %s", err)
}
if !reflect.DeepEqual(gotPD, wantConfig) {
t.Fatalf("different configs, got: \n%v\nwant: \n%v", gotPD, wantConfig)
}
}
// prometheus operator format
f(`
sendresolved: true
servicekey:
localobjectreference:
name: pagerduty-config
key: mn
severity: labels.severity
details:
- key: firing
value: '{{ template \"pagerduty.text\" . }}'
- key: num_firing
value: '{{ .Alerts.Firing | len }}'
`, PagerDutyConfig{
SendResolved: pointer.Bool(true),
ServiceKey: &v1.SecretKeySelector{
Key: "mn",
LocalObjectReference: v1.LocalObjectReference{
Name: "pagerduty-config"},
},
Severity: "labels.severity",
Details: map[string]string{
"firing": "{{ template \\\"pagerduty.text\\\" . }}",
"num_firing": "{{ .Alerts.Firing | len }}",
},
})
// normal format
f(`
sendresolved: true
servicekey:
localobjectreference:
name: pagerduty-config
key: mn
severity: labels.severity
details:
firing: '{{ template \"pagerduty.text\" . }}'
num_firing: '{{ .Alerts.Firing | len }}'
`, PagerDutyConfig{
SendResolved: pointer.Bool(true),
ServiceKey: &v1.SecretKeySelector{
Key: "mn",
LocalObjectReference: v1.LocalObjectReference{
Name: "pagerduty-config"},
},
Severity: "labels.severity",
Details: map[string]string{
"firing": "{{ template \\\"pagerduty.text\\\" . }}",
"num_firing": "{{ .Alerts.Firing | len }}",
},
})

// w/o details
f(`
sendresolved: true
servicekey:
localobjectreference:
name: pagerduty-config
key: mn
severity: labels.severity
`, PagerDutyConfig{
SendResolved: pointer.Bool(true),
ServiceKey: &v1.SecretKeySelector{
Key: "mn",
LocalObjectReference: v1.LocalObjectReference{
Name: "pagerduty-config"},
},
Severity: "labels.severity",
})
}
30 changes: 29 additions & 1 deletion api/victoriametrics/v1beta1/vmalertmanagerconfig_types.go
Expand Up @@ -22,6 +22,7 @@ import (
v1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)

// VMAlertmanagerConfigSpec defines configuration for VMAlertmanagerConfig
Expand Down Expand Up @@ -670,12 +671,39 @@ type PagerDutyConfig struct {
Component string `json:"component,omitempty"`
// Arbitrary key/value pairs that provide further detail about the incident.
// +optional
Details map[string]string `json:"details,omitempty"`
Details PagerDutyDetails `json:"details,omitempty"`
// HTTP client configuration.
// +optional
HTTPConfig *HTTPConfig `json:"http_config,omitempty"`
}

// PagerDutyDetails details for config
type PagerDutyDetails map[string]string

// UnmarshalYAML implements interface
func (pdd *PagerDutyDetails) UnmarshalYAML(unmarshal func(interface{}) error) error {
pddm := make(map[string]string)
if err := unmarshal(&pddm); err != nil {
if !strings.Contains(err.Error(), "seq into map") {
return err
}
// fallback to the prometheus-operator data format
type pagerDutyPromDetails struct {
Key string
Value string
}
var promPDD []pagerDutyPromDetails
if err := unmarshal(&promPDD); err != nil {
return fmt.Errorf("cannot parse pager duty details :%w", err)
}
for _, kv := range promPDD {
pddm[kv.Key] = kv.Value
}
}
*pdd = pddm
return nil
}

// ImageConfig is used to attach images to the incident.
// See https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event#the-images-property
// for more information.
Expand Down
25 changes: 23 additions & 2 deletions api/victoriametrics/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47f2b50

Please sign in to comment.