Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing prometheus config to AutomationConfig #243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions opsmngr/automation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type AutomationConfig struct {
Mongots []*map[string]interface{} `json:"mongots"`
Options *map[string]interface{} `json:"options"`
Processes []*Process `json:"processes"`
Prometheus *Prometheus `json:"prometheus,omitempty"`
ReplicaSets []*ReplicaSet `json:"replicaSets"`
Roles []*map[string]interface{} `json:"roles"`
Sharding []*ShardingConfig `json:"sharding"`
Expand Down Expand Up @@ -442,3 +443,18 @@ type Process struct {
ProcessType string `json:"processType,omitempty"`
Version string `json:"version,omitempty"`
}

type Prometheus struct {
Enabled bool `json:"enabled"`
Username string `json:"username"`
PasswordHash string `json:"passwordHash,omitempty"`
PasswordSalt string `json:"passwordSalt,omitempty"`
Scheme string `json:"scheme"`
TLSPemPath string `json:"tlsPemPath"`
TLSPemPassword string `json:"tlsPemPassword"`
Mode string `json:"mode"`
ListenAddress string `json:"listenAddress"`
MetricsPath string `json:"metricsPath"`
TokenFillRateSeconds int `json:"tokenFillRateSeconds"`
BurstTokenCount int `json:"burstTokenCount"`
}
127 changes: 127 additions & 0 deletions opsmngr/automation_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,130 @@ func TestAutomation_Sharding(t *testing.T) {
t.Error(diff)
}
}

func TestAutomation_GetPrometheusConfig(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/automationConfig", projectID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
_, _ = fmt.Fprint(w, `{
"prometheus" : {
"enabled": true,
"listenAddress": "0.0.0.0:9216",
"metricsPath": "/metrics",
"mode": "opsManager",
"passwordHash": "",
"passwordSalt": "",
"scheme": "http",
"tlsPemPassword": "",
"tlsPemPath": "",
"username": "user"
}}`)
})

config, _, err := client.Automation.GetConfig(ctx, projectID)
if err != nil {
t.Fatalf("Automation.GetConfig returned error: %v", err)
}

expected := &AutomationConfig{
Prometheus: &Prometheus{
Enabled: true,
ListenAddress: "0.0.0.0:9216",
MetricsPath: "/metrics",
Mode: "opsManager",
Scheme: "http",
Username: "user",
},
}
if diff := deep.Equal(config, expected); diff != nil {
t.Error(diff)
}
}

func TestAutomation_UpdatePrometheusConfig(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

updateRequest := &AutomationConfig{
Prometheus: &Prometheus{
Enabled: true,
ListenAddress: "0.0.0.0:9216",
MetricsPath: "/metrics",
Mode: "opsManager",
Scheme: "http",
Username: "user",
TokenFillRateSeconds: 1,
BurstTokenCount: 1,
},
Auth: Auth{
AuthoritativeSet: false,
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
UsersWanted: []*MongoDBUser{
{
Database: "admin",
},
},
},
}
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/groups/%s/automationConfig", projectID), func(w http.ResponseWriter, r *http.Request) {
expected := map[string]interface{}{
"prometheus": map[string]interface{}{
"enabled": true,
"listenAddress": "0.0.0.0:9216",
"metricsPath": "/metrics",
"mode": "opsManager",
"scheme": "http",
"tlsPemPassword": "",
"tlsPemPath": "",
"username": "user",
"tokenFillRateSeconds": 1.0,
"burstTokenCount": 1.0,
},
"auth": map[string]interface{}{
"authoritativeSet": false,
"autoAuthMechanism": "MONGODB-CR",
"autoAuthRestrictions": interface{}(nil),
"disabled": true,
"usersDeleted": interface{}(nil),
"usersWanted": []interface{}{
map[string]interface{}{
"authenticationRestrictions": interface{}(nil),
"db": "admin",
"roles": interface{}(nil),
"user": "",
},
},
},
"backupVersions": interface{}(nil),
"balancer": interface{}(nil),
"cpsModules": interface{}(nil),
"indexConfigs": interface{}(nil),
"mongosqlds": interface{}(nil),
"mongots": interface{}(nil),
"onlineArchiveModules": interface{}(nil),
"options": interface{}(nil),
"processes": interface{}(nil),
"replicaSets": interface{}(nil),
"roles": interface{}(nil),
"sharding": interface{}(nil),
}
var v map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&v)
if err != nil {
t.Fatalf("decode json: %v", err)
}
t.Logf("v=%#v\n", v)
if diff := deep.Equal(v, expected); diff != nil {
t.Error(diff)
}
_, _ = fmt.Fprint(w, `{}`)
})

_, err := client.Automation.UpdateConfig(ctx, projectID, updateRequest)
if err != nil {
t.Fatalf("Automation.UpdateConfig returned error: %v", err)
}
}