Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Improve logging around inferences (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmariachi authored Feb 14, 2024
1 parent 5520d22 commit 188e851
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/node/appchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ func (ap *AppChain) SendInferences(ctx context.Context, topicId uint64, results
txResp, err := ap.Client.BroadcastTx(ctx, ap.ReputerAccount, req)
if err != nil {
ap.Logger.Info().Err(err).Msg("failed to send inferences to allora blockchain")
} else {
ap.Logger.Info().Any("Tx Resp:", txResp).Msg("successfully sent inferences to allora blockchain")
}

ap.Logger.Info().Any("Tx Resp:", txResp).Msg("successfully sent inferences to allora blockchain")

return workersInferences
}

Expand Down
29 changes: 19 additions & 10 deletions cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ExecuteResult struct {

func sendResultsToChain(ctx echo.Context, a api.API, appChainClient AppChain, req ExecuteRequest, res ExecuteResponse) {

// Only in weight functions that we will have a "type" in the response
// Only in weight functions that we will have a "type" in the response
functionType := "inferences"
functionType, err := getResponseInfo(res.Results[0].Result.Stdout)
if err != nil {
Expand All @@ -50,19 +50,20 @@ func sendResultsToChain(ctx echo.Context, a api.API, appChainClient AppChain, re

var topicId uint64 = 0
for _, envVar := range req.Config.Environment {
if envVar.Name == "TOPIC_ID" {
fmt.Println("Found TOPIC_ID:", envVar.Value)
if envVar.Name == "TOPIC_ID" {
fmt.Println("Found TOPIC_ID:", envVar.Value)
topicId, err = strconv.ParseUint(envVar.Value, 10, 64)
if err != nil {
a.Log.Warn().Str("function", req.FunctionID).Err(err).Msg("node failed to parse topic id")
return
}
break
}
}
break
}
}

// TODO: We can move this context to the AppChain struct (previous context was breaking the tx broadcast response)
reqCtx := context.Background()
fmt.Println("Function Type:", functionType)
if functionType == inferenceType {
appChainClient.SendInferences(reqCtx, topicId, res.Results)
} else if functionType == weightsType {
Expand Down Expand Up @@ -90,8 +91,7 @@ func createExecutor(a api.API, appChainClient *AppChain) func(ctx echo.Context)
return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("could not unpack request: %w", err))
}

fmt.Printf("Request: %+v \n", req)

a.Log.Debug().Msgf("Request: %+v", req)
// Get the execution result.
code, id, results, cluster, err := a.Node.ExecuteFunction(ctx.Request().Context(), execute.Request(req.Request), req.Topic)
if err != nil {
Expand All @@ -105,7 +105,7 @@ func createExecutor(a api.API, appChainClient *AppChain) func(ctx echo.Context)
Results: aggregate.Aggregate(results),
Cluster: cluster,
}
fmt.Printf("Response: %+v \n", res)
a.Log.Debug().Msgf("Response: %+v", res)
// Communicate the reason for failure in these cases.
if errors.Is(err, blockless.ErrRollCallTimeout) || errors.Is(err, blockless.ErrExecutionNotEnoughNodes) {
res.Message = err.Error()
Expand All @@ -116,7 +116,16 @@ func createExecutor(a api.API, appChainClient *AppChain) func(ctx echo.Context)
// don't block the return to the consumer to send these to chain
go sendResultsToChain(ctx, a, *appChainClient, req, res)
} else {
a.Log.Debug().Msg("inference results would have been submitted to chain")
a.Log.Debug().Msg("Inference results would have been submitted to chain.")
reason := "unknown"
if appChainClient == nil {
reason = "AppChainClient is disabled"
} else if !appChainClient.Config.SubmitTx {
reason = "Submitting transactions is disabled in AppChainClient"
} else if res.Code != codes.OK {
reason = fmt.Sprintf("Response code is not OK: %s", res.Message)
}
a.Log.Warn().Msgf("Inference results not submitted to chain, not attempted. Reason: %s", reason)
}

// Send the response.
Expand Down

0 comments on commit 188e851

Please sign in to comment.