Skip to content

Commit c35057d

Browse files
add operator_bad_objects_count metric for vmauth and vmagent, additionally unified it
1 parent 5289f17 commit c35057d

Some content is hidden

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

41 files changed

+817
-1090
lines changed

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() 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() 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() 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() 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() 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() 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() 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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type VMUserSpec struct {
1515
// Name of the VMUser object.
1616
// +optional
1717
Name *string `json:"name,omitempty"`
18-
// UserName basic auth user name for accessing protected endpoint,
18+
// Username basic auth user name for accessing protected endpoint,
1919
// will be replaced with metadata.name of VMUser if omitted.
2020
// +optional
21-
UserName *string `json:"username,omitempty"`
21+
Username *string `json:"username,omitempty"`
2222
// Password basic auth password for accessing protected endpoint.
2323
// +optional
2424
Password *string `json:"password,omitempty"`
@@ -232,11 +232,25 @@ func (cr *VMUser) GetStatusMetadata() *StatusMetadata {
232232
return &cr.Status.StatusMetadata
233233
}
234234

235+
func (cr *VMUser) AsKey() string {
236+
var id string
237+
if cr.Spec.Username != nil {
238+
id = "basicAuth:" + *cr.Spec.Username
239+
}
240+
if cr.Spec.Password != nil {
241+
return id + ":" + *cr.Spec.Password
242+
}
243+
if cr.Spec.BearerToken != nil {
244+
return "bearerToken:" + *cr.Spec.BearerToken
245+
}
246+
return id
247+
}
248+
235249
func (cr *VMUser) Validate() error {
236250
if MustSkipCRValidation(cr) {
237251
return nil
238252
}
239-
if cr.Spec.UserName != nil && cr.Spec.BearerToken != nil {
253+
if cr.Spec.Username != nil && cr.Spec.BearerToken != nil {
240254
return fmt.Errorf("one of spec.username and spec.bearerToken must be defined for user, got both")
241255
}
242256
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",

api/operator/v1beta1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)