github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/requester/publicapi/endpoint_debug.go (about)

     1  package publicapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  
     7  	"github.com/rs/zerolog/log"
     8  )
     9  
    10  // debug godoc
    11  //
    12  //	@ID			pkg/requester/publicapi/debug
    13  //	@Summary	Returns debug information on what the current node is doing.
    14  //	@Tags		Health
    15  //	@Produce	json
    16  //	@Success	200	{object}	string
    17  //	@Failure	500	{object}	string
    18  //	@Router		/requester/debug [get]
    19  func (s *RequesterAPIServer) debug(res http.ResponseWriter, req *http.Request) {
    20  	debugInfoMap := make(map[string]interface{})
    21  	for _, provider := range s.debugInfoProviders {
    22  		debugInfo, err := provider.GetDebugInfo()
    23  		if err != nil {
    24  			log.Ctx(req.Context()).Error().Msgf("could not get debug info from some providers: %s", err)
    25  			continue
    26  		}
    27  		debugInfoMap[debugInfo.Component] = debugInfo.Info
    28  	}
    29  
    30  	res.WriteHeader(http.StatusOK)
    31  	err := json.NewEncoder(res).Encode(debugInfoMap)
    32  	if err != nil {
    33  		http.Error(res, err.Error(), http.StatusInternalServerError)
    34  	}
    35  }