Skip to content

Commit

Permalink
Merge pull request #67 from tensorplex-labs/dev
Browse files Browse the repository at this point in the history
dev to staging
  • Loading branch information
codebender37 authored Dec 20, 2024
2 parents a582075 + 5141e1f commit 0f321ec
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 221 deletions.
56 changes: 0 additions & 56 deletions cmd/blockchain/main.go

This file was deleted.

13 changes: 0 additions & 13 deletions pkg/api/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ func WorkerLoginController(c *gin.Context) {
func CreateTasksController(c *gin.Context) {
log.Info().Msg("Creating Tasks")

// Log the headers of the request
headers := c.Request.Header
log.Info().Interface("headers", headers).Msg("Request headers")

// Log the size of the request
requestSize := c.Request.ContentLength
log.Info().Int64("requestSize", requestSize).Msg("Request size")

log.Debug().Interface("request body", c.Request.Body).Msg("Creating tasks with request body")

minerUserInterface, exists := c.Get("minerUser")
Expand Down Expand Up @@ -157,8 +149,6 @@ func CreateTasksController(c *gin.Context) {
return
}

log.Info().Str("minerUser", fmt.Sprintf("%+v", minerUser)).Msg("Miner user found")

// Here we will handle file upload
// Parse files from the form
form, err := c.MultipartForm()
Expand Down Expand Up @@ -476,9 +466,6 @@ func GetTaskByIdController(c *gin.Context) {
taskID := c.Param("task-id")
taskService := task.NewTaskService()

// TODO: Remove this after testing
log.Info().Interface("Headers", c.Request.Header).Msg("Request Headers")

task, err := taskService.GetTaskResponseById(c.Request.Context(), taskID)
if err != nil {
c.JSON(http.StatusInternalServerError, defaultErrorResponse("Internal server error"))
Expand Down
1 change: 1 addition & 0 deletions pkg/api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func MinerAuthMiddleware() gin.HandlerFunc {

subnetState := blockchain.GetSubnetStateSubscriberInstance()
_, isFound := subnetState.FindMinerHotkeyIndex(foundApiKey.MinerUser().Hotkey)

if !isFound {
log.Error().Msg("Miner hotkey is deregistered")
c.AbortWithStatusJSON(http.StatusUnauthorized, defaultErrorResponse("Unauthorized"))
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func LoginRoutes(router *gin.Engine) {
tasks := apiV1.Group("/tasks")
{
tasks.PUT("/submit-result/:task-id", WriteTaskRateLimiter(), WorkerAuthMiddleware(), SubmitTaskResultController)
tasks.POST("/create-tasks", InMetagraphOnly(), WriteTaskRateLimiter(), MinerAuthMiddleware(), CreateTasksController)
// TODO: re-enable InMetagraphOnly() in future
tasks.POST("/create-tasks", WriteTaskRateLimiter(), MinerAuthMiddleware(), CreateTasksController)
tasks.GET("/task-result/:task-id", ReadTaskRateLimiter(), GetTaskResultsController)
tasks.GET("/:task-id", ReadTaskRateLimiter(), GetTaskByIdController)
tasks.GET("/next-task/:task-id", ReadTaskRateLimiter(), WorkerAuthMiddleware(), GetNextInProgressTaskController)
Expand Down
14 changes: 10 additions & 4 deletions pkg/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,20 @@ func CustomGinLogger(logger *zerolog.Logger) gin.HandlerFunc {

logger := log.With().Logger().Output(consoleWriter)

// Log main request info
logger.Info().
Int("status_code", param.StatusCode).
Str("latency", param.Latency.String()).
Str("ip", param.ClientIP).
Str("method", param.Method).
Str("path", param.Path).
Int("resp_size", param.BodySize).
Int("status_code", param.StatusCode).
Str("latency", param.Latency.String()).
Int("req_size", len(body)).
Int("resp_size", param.BodySize).
Str("ip", param.ClientIP).
Msg("")

// Log headers separately
logger.Info().
Interface("headers", c.Request.Header).
Msg("")
}
}
Loading

0 comments on commit 0f321ec

Please sign in to comment.