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 Jan 8, 2025
1 parent 2f0bf6a commit 4f9150c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
36 changes: 0 additions & 36 deletions frontend/pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,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 @@ -330,8 +328,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 @@ -594,22 +590,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 @@ -654,18 +641,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 @@ -900,22 +875,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 @@ -1005,8 +971,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
1 change: 1 addition & 0 deletions frontend/pkg/frontend/middleware_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func MiddlewareLogging(w http.ResponseWriter, r *http.Request, next http.Handler
"request_method", r.Method,
"request_path", r.URL.Path,
"request_proto", r.Proto,
"request_query", r.URL.RawQuery,
"request_remote_addr", r.RemoteAddr,
"request_user_agent", r.UserAgent())

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 4f9150c

Please sign in to comment.