Skip to content

Commit 9236ffb

Browse files
add operator_bad_objects_count metric for vmauth and vmagent, additionally unified it
1 parent 1ac959b commit 9236ffb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+824
-1090
lines changed

api/operator/v1beta1/vmalertmanagerconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ func (hc *HTTPConfig) validate() error {
12561256
return nil
12571257
}
12581258

1259-
func (r *VMAlertmanagerConfig) AsKey() string {
1259+
func (r *VMAlertmanagerConfig) AsKey(_ bool) string {
12601260
return fmt.Sprintf("%s/%s", r.Namespace, r.Name)
12611261
}
12621262

api/operator/v1beta1/vmnodescrape_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ func (cr *VMNodeScrape) GetStatusMetadata() *StatusMetadata {
8787
return &cr.Status.StatusMetadata
8888
}
8989

90+
func (cr *VMNodeScrape) AsKey(_ bool) string {
91+
return cr.Namespace + "/" + cr.Name
92+
}
93+
9094
func init() {
9195
SchemeBuilder.Register(&VMNodeScrape{}, &VMNodeScrapeList{})
9296
}

api/operator/v1beta1/vmpodscrape_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ func (cr *VMPodScrape) Validate() error {
142142
return nil
143143
}
144144

145+
func (cr *VMPodScrape) AsKey(_ bool) string {
146+
return cr.Namespace + "/" + cr.Name
147+
}
148+
145149
// GetStatusMetadata implements reconcile.objectWithStatus interface
146150
func (cr *VMPodScrape) GetStatusMetadata() *StatusMetadata {
147151
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmprobe_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (cr *VMProbe) GetStatusMetadata() *StatusMetadata {
141141
return &cr.Status.StatusMetadata
142142
}
143143

144+
func (cr *VMProbe) AsKey(_ bool) string {
145+
return cr.Namespace + "/" + cr.Name
146+
}
147+
144148
// Validate returns error if CR is invalid
145149
func (cr *VMProbe) Validate() error {
146150
if MustSkipCRValidation(cr) {

api/operator/v1beta1/vmrule_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func (cr *VMRule) GetStatusMetadata() *StatusMetadata {
144144
return &cr.Status.StatusMetadata
145145
}
146146

147+
func (cr *VMRule) AsKey(_ bool) string {
148+
return fmt.Sprintf("%s-%s.yaml", cr.Namespace, cr.Name)
149+
}
150+
147151
// Validate performs semantic validation of object
148152
func (cr *VMRule) Validate() error {
149153
if MustSkipCRValidation(cr) {

api/operator/v1beta1/vmscrapeconfig_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ func (cr *VMScrapeConfig) Validate() error {
530530
return cr.Spec.validate()
531531
}
532532

533+
func (cr *VMScrapeConfig) AsKey(_ bool) string {
534+
return cr.Namespace + "/" + cr.Name
535+
}
536+
533537
// GetStatusMetadata implements reconcile.objectWithStatus interface
534538
func (cr *VMScrapeConfig) GetStatusMetadata() *StatusMetadata {
535539
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmservicescrape_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (cr *VMServiceScrape) Validate() error {
164164
return nil
165165
}
166166

167+
func (cr *VMServiceScrape) AsKey(_ bool) string {
168+
return cr.Namespace + "/" + cr.Name
169+
}
170+
167171
// GetStatusMetadata implements reconcile.objectWithStatus interface
168172
func (cr *VMServiceScrape) GetStatusMetadata() *StatusMetadata {
169173
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmstaticscrape_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func (cr *VMStaticScrape) GetStatusMetadata() *StatusMetadata {
9393
return &cr.Status.StatusMetadata
9494
}
9595

96+
func (cr *VMStaticScrape) AsKey(_ bool) string {
97+
return cr.Namespace + "/" + cr.Name
98+
}
99+
96100
func init() {
97101
SchemeBuilder.Register(&VMStaticScrape{}, &VMStaticScrapeList{})
98102
}

api/operator/v1beta1/vmuser_types.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1beta1
22

33
import (
44
"fmt"
5+
"strings"
56

67
corev1 "k8s.io/api/core/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -15,10 +16,10 @@ type VMUserSpec struct {
1516
// Name of the VMUser object.
1617
// +optional
1718
Name *string `json:"name,omitempty"`
18-
// UserName basic auth user name for accessing protected endpoint,
19+
// Username basic auth user name for accessing protected endpoint,
1920
// will be replaced with metadata.name of VMUser if omitted.
2021
// +optional
21-
UserName *string `json:"username,omitempty"`
22+
Username *string `json:"username,omitempty"`
2223
// Password basic auth password for accessing protected endpoint.
2324
// +optional
2425
Password *string `json:"password,omitempty"`
@@ -232,11 +233,37 @@ func (cr *VMUser) GetStatusMetadata() *StatusMetadata {
232233
return &cr.Status.StatusMetadata
233234
}
234235

236+
func (cr *VMUser) AsKey(hide bool) string {
237+
var id string
238+
if cr.Spec.Username != nil {
239+
v := *cr.Spec.Username
240+
if hide {
241+
v = strings.Repeat("*", 5)
242+
}
243+
id = "basicAuth:" + v
244+
}
245+
if cr.Spec.Password != nil {
246+
v := *cr.Spec.Password
247+
if hide {
248+
v = strings.Repeat("*", 5)
249+
}
250+
return id + ":" + v
251+
}
252+
if cr.Spec.BearerToken != nil {
253+
v := *cr.Spec.BearerToken
254+
if hide {
255+
v = strings.Repeat("*", 5)
256+
}
257+
return "bearerToken:" + v
258+
}
259+
return id
260+
}
261+
235262
func (cr *VMUser) Validate() error {
236263
if MustSkipCRValidation(cr) {
237264
return nil
238265
}
239-
if cr.Spec.UserName != nil && cr.Spec.BearerToken != nil {
266+
if cr.Spec.Username != nil && cr.Spec.BearerToken != nil {
240267
return fmt.Errorf("one of spec.username and spec.bearerToken must be defined for user, got both")
241268
}
242269
if cr.Spec.PasswordRef != nil && cr.Spec.Password != nil {

api/operator/v1beta1/vmuser_types_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ func TestVMUser_Validate(t *testing.T) {
1818
// invalid auths
1919
f(&VMUser{
2020
Spec: VMUserSpec{
21-
UserName: ptr.To("user"),
21+
Username: ptr.To("user"),
2222
BearerToken: ptr.To("bearer"),
2323
},
2424
}, true)
2525

2626
// invalid ref
2727
f(&VMUser{
2828
Spec: VMUserSpec{
29-
UserName: ptr.To("some-user"),
29+
Username: ptr.To("some-user"),
3030
TargetRefs: []TargetRef{
3131
{
3232
CRD: &CRDRef{Name: "sm"},
@@ -39,7 +39,7 @@ func TestVMUser_Validate(t *testing.T) {
3939
// invalid ref wo targets
4040
f(&VMUser{
4141
Spec: VMUserSpec{
42-
UserName: ptr.To("some-user"),
42+
Username: ptr.To("some-user"),
4343
TargetRefs: []TargetRef{
4444
{
4545
Paths: []string{"/some-path"},
@@ -51,7 +51,7 @@ func TestVMUser_Validate(t *testing.T) {
5151
// invalid ref crd, bad empty ns
5252
f(&VMUser{
5353
Spec: VMUserSpec{
54-
UserName: ptr.To("some-user"),
54+
Username: ptr.To("some-user"),
5555
TargetRefs: []TargetRef{
5656
{
5757
CRD: &CRDRef{
@@ -68,7 +68,7 @@ func TestVMUser_Validate(t *testing.T) {
6868
// incorrect password
6969
f(&VMUser{
7070
Spec: VMUserSpec{
71-
UserName: ptr.To("some-user"),
71+
Username: ptr.To("some-user"),
7272
Password: ptr.To("some-password"),
7373
PasswordRef: &corev1.SecretKeySelector{
7474
Key: "some-key",

0 commit comments

Comments
 (0)