Skip to content

Commit 033a006

Browse files
authored
CLOUDP-114518: Add an Integration for Prometheus (#528)
- Support Prometheus Integration - Log warning messages when conditions are set
1 parent 69cf55b commit 033a006

File tree

13 files changed

+262
-105
lines changed

13 files changed

+262
-105
lines changed

config/crd/bases/atlas.mongodb.com_atlasprojects.yaml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ spec:
9090
type: object
9191
channelName:
9292
type: string
93+
enabled:
94+
type: boolean
9395
flowName:
9496
type: string
9597
licenseKeyRef:
@@ -106,8 +108,26 @@ spec:
106108
required:
107109
- name
108110
type: object
111+
microsoftTeamsWebhookUrl:
112+
type: string
113+
name:
114+
type: string
109115
orgName:
110116
type: string
117+
passwordRef:
118+
description: ResourceRefNamespaced is a reference to a Kubernetes
119+
Resource that allows to configure the namespace
120+
properties:
121+
name:
122+
description: Name is the name of the Kubernetes Resource
123+
type: string
124+
namespace:
125+
description: Namespace is the namespace of the Kubernetes
126+
Resource
127+
type: string
128+
required:
129+
- name
130+
type: object
111131
readTokenRef:
112132
description: ResourceRefNamespaced is a reference to a Kubernetes
113133
Resource that allows to configure the namespace
@@ -138,7 +158,9 @@ spec:
138158
required:
139159
- name
140160
type: object
141-
secret:
161+
scheme:
162+
type: string
163+
secretRef:
142164
description: ResourceRefNamespaced is a reference to a Kubernetes
143165
Resource that allows to configure the namespace
144166
properties:
@@ -152,6 +174,8 @@ spec:
152174
required:
153175
- name
154176
type: object
177+
serviceDiscovery:
178+
type: string
155179
serviceKeyRef:
156180
description: ResourceRefNamespaced is a reference to a Kubernetes
157181
Resource that allows to configure the namespace
@@ -181,9 +205,12 @@ spec:
181205
- FLOWDOCK
182206
- WEBHOOK
183207
- MICROSOFT_TEAMS
208+
- PROMETHEUS
184209
type: string
185210
url:
186211
type: string
212+
username:
213+
type: string
187214
writeTokenRef:
188215
description: ResourceRefNamespaced is a reference to a Kubernetes
189216
Resource that allows to configure the namespace
@@ -306,7 +333,7 @@ spec:
306333
status:
307334
description: AtlasProjectStatus defines the observed state of AtlasProject
308335
properties:
309-
AuthModes:
336+
authModes:
310337
description: AuthModes contains a list of configured authentication
311338
modes "SCRAM" is default authentication method and requires a password
312339
for each user "X509" signifies that self-managed X.509 authentication
@@ -439,6 +466,15 @@ spec:
439466
- region
440467
type: object
441468
type: array
469+
prometheus:
470+
description: Prometheus contains the status for Prometheus integration
471+
including the prometheusDiscoveryURL
472+
properties:
473+
prometheusDiscoveryURL:
474+
type: string
475+
scheme:
476+
type: string
477+
type: object
442478
required:
443479
- conditions
444480
type: object

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/pborman/uuid v1.2.1
2020
github.com/sethvargo/go-password v0.2.0
2121
github.com/stretchr/testify v1.7.0
22-
go.mongodb.org/atlas v0.15.0
22+
go.mongodb.org/atlas v0.16.0
2323
go.mongodb.org/mongo-driver v1.8.3
2424
go.uber.org/zap v1.21.0
2525
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
9999
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
100100
github.com/aws/aws-sdk-go v1.44.15 h1:z02BVeV6k7hZMfWEQmKh3X23s3F9PBHFCcIVfNlut7A=
101101
github.com/aws/aws-sdk-go v1.44.15/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
102+
github.com/aws/aws-sdk-go v1.43.23 h1:/YmZzPMK6Xzi0B/W9O/Pq7nyIXpBv6mTiJdDDFC7u94=
103+
github.com/aws/aws-sdk-go v1.43.23/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
102104
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
103105
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
104106
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
@@ -577,8 +579,8 @@ go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lL
577579
go.etcd.io/etcd/pkg/v3 v3.5.0/go.mod h1:UzJGatBQ1lXChBkQF0AuAtkRQMYnHubxAEYIrC3MSsE=
578580
go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD00Szc=
579581
go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4=
580-
go.mongodb.org/atlas v0.15.0 h1:YyOBdBIuI//krRITf4r7PSirJ3YDNNUfNmapxwSyDow=
581-
go.mongodb.org/atlas v0.15.0/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
582+
go.mongodb.org/atlas v0.16.0 h1:IqnDuK3XAZUgJ5lPHc4v4z4B8F6mvsS37O4ck7tOYVc=
583+
go.mongodb.org/atlas v0.16.0/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
582584
go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R4=
583585
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
584586
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=

pkg/api/v1/project/integration.go

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
type Integration struct {
1212
// Third Party Integration type such as Slack, New Relic, etc
13-
// +kubebuilder:validation:Enum=PAGER_DUTY;SLACK;DATADOG;NEW_RELIC;OPS_GENIE;VICTOR_OPS;FLOWDOCK;WEBHOOK;MICROSOFT_TEAMS
13+
// +kubebuilder:validation:Enum=PAGER_DUTY;SLACK;DATADOG;NEW_RELIC;OPS_GENIE;VICTOR_OPS;FLOWDOCK;WEBHOOK;MICROSOFT_TEAMS;PROMETHEUS
1414
// +optional
1515
Type string `json:"type,omitempty"`
1616
// +optional
@@ -43,29 +43,74 @@ type Integration struct {
4343
URL string `json:"url,omitempty"`
4444
// +optional
4545
SecretRef common.ResourceRefNamespaced `json:"secretRef,omitempty"`
46+
// +optional
47+
Name string `json:"name,omitempty"`
48+
// +optional
49+
MicrosoftTeamsWebhookURL string `json:"microsoftTeamsWebhookUrl,omitempty"`
50+
// +optional
51+
UserName string `json:"username,omitempty"`
52+
// +optional
53+
PasswordRef common.ResourceRefNamespaced `json:"passwordRef,omitempty"`
54+
// +optional
55+
ServiceDiscovery string `json:"serviceDiscovery,omitempty"`
56+
// +optional
57+
Scheme string `json:"scheme,omitempty"`
58+
// +optional
59+
Enabled bool `json:"enabled,omitempty"`
4660
}
4761

48-
func (i Integration) ToAtlas(defaultNS string, c client.Client) *mongodbatlas.ThirdPartyIntegration {
49-
result := mongodbatlas.ThirdPartyIntegration{}
50-
result.Type = i.Type
51-
result.LicenseKey, _ = i.LicenseKeyRef.ReadPassword(c, defaultNS)
52-
result.AccountID = i.AccountID
53-
result.WriteToken, _ = i.WriteTokenRef.ReadPassword(c, defaultNS)
54-
result.ReadToken, _ = i.ReadTokenRef.ReadPassword(c, defaultNS)
55-
result.APIKey, _ = i.APIKeyRef.ReadPassword(c, defaultNS)
56-
result.Region = i.Region
57-
result.ServiceKey, _ = i.ServiceKeyRef.ReadPassword(c, defaultNS)
58-
result.APIToken, _ = i.APITokenRef.ReadPassword(c, defaultNS)
59-
result.TeamName = i.TeamName
60-
result.ChannelName = i.ChannelName
61-
result.RoutingKey, _ = i.RoutingKeyRef.ReadPassword(c, defaultNS)
62-
result.FlowName = i.FlowName
63-
result.OrgName = i.OrgName
64-
result.URL = i.URL
65-
result.Secret, _ = i.SecretRef.ReadPassword(c, defaultNS)
66-
return &result
62+
func (i Integration) ToAtlas(c client.Client, defaultNS string) (result *mongodbatlas.ThirdPartyIntegration, err error) {
63+
result = &mongodbatlas.ThirdPartyIntegration{
64+
Type: i.Type,
65+
AccountID: i.AccountID,
66+
Region: i.Region,
67+
TeamName: i.TeamName,
68+
ChannelName: i.ChannelName,
69+
FlowName: i.FlowName,
70+
OrgName: i.OrgName,
71+
URL: i.URL,
72+
Name: i.Name,
73+
MicrosoftTeamsWebhookURL: i.MicrosoftTeamsWebhookURL,
74+
UserName: i.UserName,
75+
ServiceDiscovery: i.ServiceDiscovery,
76+
Scheme: i.Scheme,
77+
Enabled: i.Enabled,
78+
}
79+
80+
readPassword := func(passwordField common.ResourceRefNamespaced, target *string, errors *[]error) {
81+
if passwordField.Name == "" {
82+
return
83+
}
84+
85+
*target, err = passwordField.ReadPassword(c, defaultNS)
86+
storeError(err, errors)
87+
}
88+
89+
errorList := make([]error, 0)
90+
readPassword(i.LicenseKeyRef, &result.LicenseKey, &errorList)
91+
readPassword(i.WriteTokenRef, &result.WriteToken, &errorList)
92+
readPassword(i.ReadTokenRef, &result.ReadToken, &errorList)
93+
readPassword(i.APIKeyRef, &result.APIKey, &errorList)
94+
readPassword(i.ServiceKeyRef, &result.ServiceKey, &errorList)
95+
readPassword(i.APITokenRef, &result.APIToken, &errorList)
96+
readPassword(i.RoutingKeyRef, &result.RoutingKey, &errorList)
97+
readPassword(i.SecretRef, &result.Secret, &errorList)
98+
readPassword(i.PasswordRef, &result.Password, &errorList)
99+
100+
if len(errorList) != 0 {
101+
firstError := (errorList)[0]
102+
return nil, firstError
103+
}
104+
105+
return result, nil
67106
}
68107

69108
func (i Integration) Identifier() interface{} {
70109
return i.Type
71110
}
111+
112+
func storeError(err error, errors *[]error) {
113+
if err != nil {
114+
*errors = append(*errors, err)
115+
}
116+
}

pkg/api/v1/status/atlasproject.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,10 @@ type AtlasProjectStatus struct {
8989
// AuthModes contains a list of configured authentication modes
9090
// "SCRAM" is default authentication method and requires a password for each user
9191
// "X509" signifies that self-managed X.509 authentication is configured
92-
AuthModes authmode.AuthModes `json:"AuthModes,omitempty"`
92+
AuthModes authmode.AuthModes `json:"authModes,omitempty"`
93+
94+
// Prometheus contains the status for Prometheus integration
95+
// including the prometheusDiscoveryURL
96+
// +optional
97+
Prometheus Prometheus `json:"prometheus,omitempty"`
9398
}

pkg/api/v1/status/prometheus.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package status
2+
3+
type Prometheus struct {
4+
// +optional
5+
Scheme string `json:"scheme,omitempty"`
6+
// +optional
7+
DiscoveryURL string `json:"prometheusDiscoveryURL,omitempty"`
8+
}

pkg/api/v1/status/zz_generated.deepcopy.go

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

pkg/api/v1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)