Skip to content

Commit d83508c

Browse files
authored
fix: add missing prometheus config to AutomationConfig (#243)
1 parent c93a707 commit d83508c

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

opsmngr/automation_config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type AutomationConfig struct {
8888
Mongots []*map[string]interface{} `json:"mongots"`
8989
Options *map[string]interface{} `json:"options"`
9090
Processes []*Process `json:"processes"`
91+
Prometheus *Prometheus `json:"prometheus,omitempty"`
9192
ReplicaSets []*ReplicaSet `json:"replicaSets"`
9293
Roles []*map[string]interface{} `json:"roles"`
9394
Sharding []*ShardingConfig `json:"sharding"`
@@ -442,3 +443,18 @@ type Process struct {
442443
ProcessType string `json:"processType,omitempty"`
443444
Version string `json:"version,omitempty"`
444445
}
446+
447+
type Prometheus struct {
448+
Enabled bool `json:"enabled"`
449+
Username string `json:"username"`
450+
PasswordHash string `json:"passwordHash,omitempty"`
451+
PasswordSalt string `json:"passwordSalt,omitempty"`
452+
Scheme string `json:"scheme"`
453+
TLSPemPath string `json:"tlsPemPath"`
454+
TLSPemPassword string `json:"tlsPemPassword"`
455+
Mode string `json:"mode"`
456+
ListenAddress string `json:"listenAddress"`
457+
MetricsPath string `json:"metricsPath"`
458+
TokenFillRateSeconds int `json:"tokenFillRateSeconds"`
459+
BurstTokenCount int `json:"burstTokenCount"`
460+
}

opsmngr/automation_config_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,130 @@ func TestAutomation_Sharding(t *testing.T) {
848848
t.Error(diff)
849849
}
850850
}
851+
852+
func TestAutomation_GetPrometheusConfig(t *testing.T) {
853+
client, mux, teardown := setup()
854+
defer teardown()
855+
856+
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/automationConfig", projectID), func(w http.ResponseWriter, r *http.Request) {
857+
testMethod(t, r, http.MethodGet)
858+
_, _ = fmt.Fprint(w, `{
859+
"prometheus" : {
860+
"enabled": true,
861+
"listenAddress": "0.0.0.0:9216",
862+
"metricsPath": "/metrics",
863+
"mode": "opsManager",
864+
"passwordHash": "",
865+
"passwordSalt": "",
866+
"scheme": "http",
867+
"tlsPemPassword": "",
868+
"tlsPemPath": "",
869+
"username": "user"
870+
}}`)
871+
})
872+
873+
config, _, err := client.Automation.GetConfig(ctx, projectID)
874+
if err != nil {
875+
t.Fatalf("Automation.GetConfig returned error: %v", err)
876+
}
877+
878+
expected := &AutomationConfig{
879+
Prometheus: &Prometheus{
880+
Enabled: true,
881+
ListenAddress: "0.0.0.0:9216",
882+
MetricsPath: "/metrics",
883+
Mode: "opsManager",
884+
Scheme: "http",
885+
Username: "user",
886+
},
887+
}
888+
if diff := deep.Equal(config, expected); diff != nil {
889+
t.Error(diff)
890+
}
891+
}
892+
893+
func TestAutomation_UpdatePrometheusConfig(t *testing.T) {
894+
client, mux, teardown := setup()
895+
defer teardown()
896+
897+
updateRequest := &AutomationConfig{
898+
Prometheus: &Prometheus{
899+
Enabled: true,
900+
ListenAddress: "0.0.0.0:9216",
901+
MetricsPath: "/metrics",
902+
Mode: "opsManager",
903+
Scheme: "http",
904+
Username: "user",
905+
TokenFillRateSeconds: 1,
906+
BurstTokenCount: 1,
907+
},
908+
Auth: Auth{
909+
AuthoritativeSet: false,
910+
AutoAuthMechanism: "MONGODB-CR",
911+
Disabled: true,
912+
UsersWanted: []*MongoDBUser{
913+
{
914+
Database: "admin",
915+
},
916+
},
917+
},
918+
}
919+
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/automationConfig", projectID), func(w http.ResponseWriter, r *http.Request) {
920+
expected := map[string]interface{}{
921+
"prometheus": map[string]interface{}{
922+
"enabled": true,
923+
"listenAddress": "0.0.0.0:9216",
924+
"metricsPath": "/metrics",
925+
"mode": "opsManager",
926+
"scheme": "http",
927+
"tlsPemPassword": "",
928+
"tlsPemPath": "",
929+
"username": "user",
930+
"tokenFillRateSeconds": 1.0,
931+
"burstTokenCount": 1.0,
932+
},
933+
"auth": map[string]interface{}{
934+
"authoritativeSet": false,
935+
"autoAuthMechanism": "MONGODB-CR",
936+
"autoAuthRestrictions": interface{}(nil),
937+
"disabled": true,
938+
"usersDeleted": interface{}(nil),
939+
"usersWanted": []interface{}{
940+
map[string]interface{}{
941+
"authenticationRestrictions": interface{}(nil),
942+
"db": "admin",
943+
"roles": interface{}(nil),
944+
"user": "",
945+
},
946+
},
947+
},
948+
"backupVersions": interface{}(nil),
949+
"balancer": interface{}(nil),
950+
"cpsModules": interface{}(nil),
951+
"indexConfigs": interface{}(nil),
952+
"mongosqlds": interface{}(nil),
953+
"mongots": interface{}(nil),
954+
"onlineArchiveModules": interface{}(nil),
955+
"options": interface{}(nil),
956+
"processes": interface{}(nil),
957+
"replicaSets": interface{}(nil),
958+
"roles": interface{}(nil),
959+
"sharding": interface{}(nil),
960+
}
961+
var v map[string]interface{}
962+
err := json.NewDecoder(r.Body).Decode(&v)
963+
if err != nil {
964+
t.Fatalf("decode json: %v", err)
965+
}
966+
t.Logf("v=%#v\n", v)
967+
if diff := deep.Equal(v, expected); diff != nil {
968+
t.Error(diff)
969+
}
970+
_, _ = fmt.Fprint(w, `{}`)
971+
})
972+
973+
_, err := client.Automation.UpdateConfig(ctx, projectID, updateRequest)
974+
if err != nil {
975+
t.Fatalf("Automation.UpdateConfig returned error: %v", err)
976+
}
977+
}

0 commit comments

Comments
 (0)