feat(http): add debug logs in
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/http/middlewares"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type stackStatusResponse struct {
|
||||
@@ -64,16 +65,22 @@ type endpointEdgeStatusInspectResponse struct {
|
||||
// @failure 500 "Server error"
|
||||
// @router /endpoints/{id}/edge/status [get]
|
||||
func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
logrus.Debug("[http,handler,endpointedge] [message: received request to get endpoint edge status]")
|
||||
|
||||
endpoint, err := middlewares.FetchEndpoint(r)
|
||||
if err != nil {
|
||||
return httperror.BadRequest("Unable to find an environment on request context", err)
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: retrieved endpoint information from context] [endpoint: %s] [endpoint_id: %s]", endpoint.Name, endpoint.ID)
|
||||
|
||||
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access environment", err}
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: authorized endpoint operation] [endpoint: %s] [endpoint_id: %s]", endpoint.Name, endpoint.ID)
|
||||
|
||||
if endpoint.EdgeID == "" {
|
||||
edgeIdentifier := r.Header.Get(portainer.PortainerAgentEdgeIDHeader)
|
||||
endpoint.EdgeID = edgeIdentifier
|
||||
@@ -92,6 +99,8 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to Unable to persist environment changes inside the database", err}
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: updated endpoint information in database] [edge_id: %s] [checkin_time: %s]", endpoint.EdgeID, endpoint.LastCheckInDate)
|
||||
|
||||
checkinInterval := endpoint.EdgeCheckinInterval
|
||||
if endpoint.EdgeCheckinInterval == 0 {
|
||||
settings, err := handler.DataStore.Settings().Settings()
|
||||
@@ -110,12 +119,16 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
||||
Credentials: tunnel.Credentials,
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: retrieved tunnel information from mem] [status: %s]", tunnel.Status)
|
||||
|
||||
schedules, handlerErr := handler.buildSchedules(endpoint.ID, tunnel)
|
||||
if handlerErr != nil {
|
||||
return handlerErr
|
||||
}
|
||||
statusResponse.Schedules = schedules
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: built schedules] [schedule_count: %d]", len(schedules))
|
||||
|
||||
if tunnel.Status == portainer.EdgeAgentManagementRequired {
|
||||
handler.ReverseTunnelService.SetTunnelStatusToActive(endpoint.ID)
|
||||
}
|
||||
@@ -126,6 +139,8 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
||||
}
|
||||
statusResponse.Stacks = edgeStacksStatus
|
||||
|
||||
logrus.Debugf("[http,handler,endpointedge] [message: built stacks] [stack_count: %d]", len(edgeStacksStatus))
|
||||
|
||||
return response.JSON(w, statusResponse)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/portainer/portainer/api/crypto"
|
||||
"github.com/portainer/portainer/api/http/client"
|
||||
"github.com/portainer/portainer/api/internal/edge"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type endpointCreatePayload struct {
|
||||
@@ -181,32 +182,44 @@ func (payload *endpointCreatePayload) Validate(r *http.Request) error {
|
||||
// @failure 500 "Server error"
|
||||
// @router /endpoints [post]
|
||||
func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
logrus.Debug("[http,handler,endpoints] [message: received request to create endpoint]")
|
||||
|
||||
payload := &endpointCreatePayload{}
|
||||
err := payload.Validate(r)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: successfully validated payload]")
|
||||
|
||||
endpoint, endpointCreationError := handler.createEndpoint(payload)
|
||||
if endpointCreationError != nil {
|
||||
return endpointCreationError
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpoints] [message: successfully created endpoint] [endpoint: %s] [endpoint_id: %s]", endpoint.Name, endpoint.ID)
|
||||
|
||||
endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an environment group inside the database", err}
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpoints] [message: fetched endpoint group] [group: %s]", endpointGroup.Name)
|
||||
|
||||
edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge groups from the database", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: successfully fetched edge groups]")
|
||||
|
||||
edgeStacks, err := handler.DataStore.EdgeStack().EdgeStacks()
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve edge stacks from the database", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: successfully fetched edge stacks]")
|
||||
|
||||
relationObject := &portainer.EndpointRelation{
|
||||
EndpointID: endpoint.ID,
|
||||
EdgeStacks: map[portainer.EdgeStackID]bool{},
|
||||
@@ -217,6 +230,8 @@ func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *
|
||||
for _, stackID := range relatedEdgeStacks {
|
||||
relationObject.EdgeStacks[stackID] = true
|
||||
}
|
||||
|
||||
logrus.Debugf("[http,handler,endpoints] [message: computed edge stacks relationships] [stack_count: %d]", len(relatedEdgeStacks))
|
||||
}
|
||||
|
||||
err = handler.DataStore.EndpointRelation().Create(relationObject)
|
||||
@@ -224,6 +239,8 @@ func (handler *Handler) endpointCreate(w http.ResponseWriter, r *http.Request) *
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the relation object inside the database", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: created database relation object]")
|
||||
|
||||
return response.JSON(w, endpoint)
|
||||
}
|
||||
|
||||
@@ -308,6 +325,8 @@ func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload)
|
||||
|
||||
edgeKey := handler.ReverseTunnelService.GenerateEdgeKey(payload.URL, portainerHost, endpointID)
|
||||
|
||||
logrus.Debugf("[http,handler,endpoints] [message: successfully generated Edge key] [key: %s]", edgeKey)
|
||||
|
||||
endpoint := &portainer.Endpoint{
|
||||
ID: portainer.EndpointID(endpointID),
|
||||
Name: payload.Name,
|
||||
@@ -334,6 +353,8 @@ func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload)
|
||||
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve the settings from the database", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: successfully fetched settings]")
|
||||
|
||||
if settings.EnforceEdgeID {
|
||||
edgeID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
@@ -348,6 +369,8 @@ func (handler *Handler) createEdgeAgentEndpoint(payload *endpointCreatePayload)
|
||||
return nil, &httperror.HandlerError{http.StatusInternalServerError, "An error occured while trying to create the environment", err}
|
||||
}
|
||||
|
||||
logrus.Debug("[http,handler,endpoints] [message: successfully updated endpoint authorizations]")
|
||||
|
||||
return endpoint, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user