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

Commit

Permalink
add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
okedeji committed Jul 4, 2024
1 parent c782f27 commit 1a20021
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
10 changes: 7 additions & 3 deletions cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/allora-network/b7s/api"
"github.com/allora-network/b7s/models/blockless"
Expand Down Expand Up @@ -68,8 +67,14 @@ func sendResultsToChain(log zerolog.Logger, appChainClient *AppChain, res node.C
}
if appChainClient.Config.WorkerMode == WorkerModeWorker { // for inference or forecast
appChainClient.SendWorkerModeData(reqCtx, topicId, aggregate.Aggregate(res.Data))

// increament the number of commits made by worker
workerChainCommit.Inc()
} else { // for losses
appChainClient.SendReputerModeData(reqCtx, topicId, aggregate.Aggregate(res.Data))

// increament the number of commits made by reputer
reputerChainCommit.Inc()
}
}

Expand Down Expand Up @@ -111,8 +116,7 @@ func createExecutor(a api.API) func(ctx echo.Context) error {
res.Message = err.Error()
}

// record metics
headRequestEveryHour.Observe(float64(time.Now().Hour()))
// increament the number of responses made by reputer
headRequests.Inc()

// Send the response.
Expand Down
50 changes: 31 additions & 19 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,34 @@ var (
Help: "The total number of request made by head node",
})

headRequestEveryHour = prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "allora_head_node_request_every_hour",
Help: "The number of requests made by head node every hour",
Buckets: prometheus.LinearBuckets(0, 3600, 24), // 24 buckets, one for each hour
},
)

workerLatestInference = prometheus.NewSummary(
prometheus.SummaryOpts{
Name: "allora_worker_node_latest_inference_value",
Help: "The latest inference value from the worker node",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
)
workerResponse = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_worker_node_total_response",
Help: "The total number of responds from worker node",
})

reputerResponse = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_reputer_node_total_response",
Help: "The total number of responds from reputer node",
})

workerChainCommit = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_worker_node_chain_commit",
Help: "The total number of worker commits to the chain",
})

reputerChainCommit = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_reputer_node_chain_commit",
Help: "The total number of reputer commits to the chain",
})
)

func init() {
prometheus.MustRegister(opsProcessed)
prometheus.MustRegister(headRequests)
prometheus.MustRegister(headRequestEveryHour)
prometheus.MustRegister(workerLatestInference)
prometheus.MustRegister(workerResponse)
prometheus.MustRegister(reputerResponse)
prometheus.MustRegister(workerChainCommit)
prometheus.MustRegister(reputerChainCommit)
}

func main() {
Expand Down Expand Up @@ -184,8 +190,6 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
// Build inference if existent
if responseValue.InfererValue != "" {
infererValue := alloraMath.MustNewDecFromString(responseValue.InfererValue)
// record inferer value as summary
workerLatestInference.Observe(infererValue.SdkLegacyDec().MustFloat64())
inference := &types.Inference{
TopicId: topicId,
Inferer: e.appChain.Address,
Expand Down Expand Up @@ -256,6 +260,10 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
fmt.Println("Error serializing WorkerDataBundle: ", err)
return result, err
}

// increament the number of responses made by worker
workerResponse.Inc()

outputJson := string(workerDataBundleBytes)
fmt.Println("Signed OutputJson sent to consensus: ", outputJson)
result.Result.Stdout = outputJson
Expand Down Expand Up @@ -444,6 +452,10 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
fmt.Println("Error serializing WorkerDataBundle: ", err)
return result, err
}

// increament the number of responses made by reputer
workerResponse.Inc()

outputJson := string(reputerDataResponseBytes)
fmt.Println("Signed OutputJson sent to consensus: ", outputJson)
result.Result.Stdout = outputJson
Expand Down

0 comments on commit 1a20021

Please sign in to comment.