Skip to content

Commit

Permalink
frontend: Tidy up log messages
Browse files Browse the repository at this point in the history
Add a logger attribute for the request's "api-version" parameter
from MiddlewareValidateAPIVersion.

Also remove the "<api-version>: <function-name>" log messages from
the HTTP handler methods. I added these messages when the handlers
were no more than stubs to test request routing but they no longer
add value to the frontend logs.
  • Loading branch information
Matthew Barnes committed Dec 4, 2024
1 parent bf3d7fc commit dc243b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
38 changes: 0 additions & 38 deletions frontend/pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ func (f *Frontend) ArmResourceList(writer http.ResponseWriter, request *http.Req
return
}

logger.Info(fmt.Sprintf("%s: ArmResourceList", versionedInterface))

var pageSizeHint int32 = 20
var continuationToken *string
var pagedResponse arm.PagedResponse
Expand Down Expand Up @@ -290,8 +288,6 @@ func (f *Frontend) ArmResourceRead(writer http.ResponseWriter, request *http.Req
return
}

logger.Info(fmt.Sprintf("%s: ArmResourceRead", versionedInterface))

responseBody, cloudError := f.MarshalResource(ctx, resourceID, versionedInterface)
if cloudError != nil {
arm.WriteCloudError(writer, cloudError)
Expand Down Expand Up @@ -350,8 +346,6 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request
return
}

logger.Info(fmt.Sprintf("%s: ArmResourceCreateOrUpdate", versionedInterface))

doc, err := f.dbClient.GetResourceDoc(ctx, resourceID)
if err != nil && !errors.Is(err, database.ErrNotFound) {
logger.Error(err.Error())
Expand Down Expand Up @@ -563,22 +557,13 @@ func (f *Frontend) ArmResourceDelete(writer http.ResponseWriter, request *http.R
ctx := request.Context()
logger := LoggerFromContext(ctx)

versionedInterface, err := VersionFromContext(ctx)
if err != nil {
logger.Error(err.Error())
arm.WriteInternalServerError(writer)
return
}

resourceID, err := ResourceIDFromContext(ctx)
if err != nil {
logger.Error(err.Error())
arm.WriteInternalServerError(writer)
return
}

logger.Info(fmt.Sprintf("%s: ArmResourceDelete", versionedInterface))

resourceDoc, err := f.dbClient.GetResourceDoc(ctx, resourceID)
if err != nil {
// For resource not found errors on deletion, ARM requires
Expand Down Expand Up @@ -623,18 +608,6 @@ func (f *Frontend) ArmResourceDelete(writer http.ResponseWriter, request *http.R
}

func (f *Frontend) ArmResourceAction(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()
logger := LoggerFromContext(ctx)

versionedInterface, err := VersionFromContext(ctx)
if err != nil {
logger.Error(err.Error())
arm.WriteInternalServerError(writer)
return
}

logger.Info(fmt.Sprintf("%s: ArmResourceAction", versionedInterface))

writer.WriteHeader(http.StatusOK)
}

Expand Down Expand Up @@ -869,22 +842,13 @@ func (f *Frontend) OperationStatus(writer http.ResponseWriter, request *http.Req
ctx := request.Context()
logger := LoggerFromContext(ctx)

versionedInterface, err := VersionFromContext(ctx)
if err != nil {
logger.Error(err.Error())
writer.WriteHeader(http.StatusInternalServerError)
return
}

resourceID, err := ResourceIDFromContext(ctx)
if err != nil {
logger.Error(err.Error())
arm.WriteInternalServerError(writer)
return
}

logger.Info(fmt.Sprintf("%s: OperationStatus", versionedInterface))

doc, err := f.dbClient.GetOperationDoc(ctx, resourceID.Name)
if err != nil {
logger.Error(err.Error())
Expand Down Expand Up @@ -974,8 +938,6 @@ func (f *Frontend) OperationResult(writer http.ResponseWriter, request *http.Req
return
}

logger.Info(fmt.Sprintf("%s: OperationResult", versionedInterface))

doc, err := f.dbClient.GetOperationDoc(ctx, resourceID.Name)
if err != nil {
logger.Error(err.Error())
Expand Down
7 changes: 6 additions & 1 deletion frontend/pkg/frontend/middleware_validateapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
)

func MiddlewareValidateAPIVersion(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
ctx := r.Context()
logger := LoggerFromContext(ctx)

apiVersion := r.URL.Query().Get(APIVersionKey)
if apiVersion == "" {
arm.WriteError(
Expand All @@ -26,7 +29,9 @@ func MiddlewareValidateAPIVersion(w http.ResponseWriter, r *http.Request, next h
api.ClusterResourceType,
apiVersion)
} else {
ctx := ContextWithVersion(r.Context(), version)
logger = logger.With("api_version", apiVersion)
ctx = ContextWithLogger(ctx, logger)
ctx = ContextWithVersion(ctx, version)
r = r.WithContext(ctx)
next(w, r)
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/pkg/frontend/node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func (f *Frontend) CreateOrUpdateNodePool(writer http.ResponseWriter, request *h
return
}

logger.Info(fmt.Sprintf("%s: CreateNodePool", versionedInterface))

doc, err := f.dbClient.GetResourceDoc(ctx, resourceID)
if err != nil && !errors.Is(err, database.ErrNotFound) {
logger.Error(err.Error())
Expand Down

0 comments on commit dc243b6

Please sign in to comment.