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

update dependencies, fix linting #581

Merged
merged 7 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ifndef HAS_SWAGGER
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
endif
ifndef HAS_GOLANGCI_LINT
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
endif
ifndef HAS_MOCKGEN
go install github.com/golang/mock/mockgen@v1.6.0
Expand Down
77 changes: 58 additions & 19 deletions api/alerting/alerting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
radixhttp "github.com/equinor/radix-common/net/http"
crdutils "github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -81,7 +82,9 @@ func EnvironmentRouteAccessCheck(handler models.RadixHandlerFunc) models.RadixHa
envNamespace := crdutils.GetEnvironmentNamespace(appName, envName)

if _, err := a.ServiceAccount.RadixClient.RadixV1().RadixEnvironments().Get(r.Context(), envNamespace, v1.GetOptions{}); err != nil {
radixhttp.ErrorResponse(rw, r, err)
if err = radixhttp.ErrorResponse(rw, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

Expand Down Expand Up @@ -142,19 +145,25 @@ func UpdateEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWr

var updateAlertingConfig alertingModels.UpdateAlertingConfig
if err := json.NewDecoder(r.Body).Decode(&updateAlertingConfig); err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this logging to the method radixhttp.ErrorResponse to avoid repetition?
%v can be used for error
log.Errorf("%s: failed to write response: %v", r.URL.Path, err)

}
return
}

alertHandler := NewEnvironmentHandler(accounts, appName, envName)
alertsConfig, err := alertHandler.UpdateAlertingConfig(r.Context(), updateAlertingConfig)

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// GetEnvironmentAlertingConfig returns alerts configuration
Expand Down Expand Up @@ -203,11 +212,15 @@ func GetEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWrite
alertsConfig, err := alertHandler.GetAlertingConfig(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// EnableEnvironmentAlerting enables alerting for application environment
Expand Down Expand Up @@ -258,11 +271,15 @@ func EnableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
alertsConfig, err := alertHandler.EnableAlerting(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// DisableEnvironmentAlerting disables alerting for application environment
Expand Down Expand Up @@ -312,11 +329,15 @@ func DisableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
alertHandler := NewEnvironmentHandler(accounts, appName, envName)
alertsConfig, err := alertHandler.DisableAlerting(r.Context())
if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// UpdateApplicationAlertingConfig Configures alert settings
Expand Down Expand Up @@ -366,19 +387,25 @@ func UpdateApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWr

var updateAlertingConfig alertingModels.UpdateAlertingConfig
if err := json.NewDecoder(r.Body).Decode(&updateAlertingConfig); err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

alertHandler := NewApplicationHandler(accounts, appName)
alertsConfig, err := alertHandler.UpdateAlertingConfig(r.Context(), updateAlertingConfig)

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// GetApplicationAlertingConfig returns alerts configuration
Expand Down Expand Up @@ -421,11 +448,15 @@ func GetApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWrite
alertsConfig, err := alertHandler.GetAlertingConfig(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// EnableApplicationAlerting enables alerting for application
Expand Down Expand Up @@ -470,11 +501,15 @@ func EnableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
alertsConfig, err := alertHandler.EnableAlerting(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}

// DisableApplicationAlerting disables alerting for application
Expand Down Expand Up @@ -518,9 +553,13 @@ func DisableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
alertHandler := NewApplicationHandler(accounts, appName)
alertsConfig, err := alertHandler.DisableAlerting(r.Context())
if err != nil {
radixhttp.ErrorResponse(w, r, err)
if err = radixhttp.ErrorResponse(w, r, err); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
if err = radixhttp.JSONResponse(w, r, alertsConfig); err != nil {
log.Errorf("%s: failed to write response: %s", r.URL.Path, err.Error())
}
}
Loading