-
Notifications
You must be signed in to change notification settings - Fork 397
feat(telemetry): modify the aggregator to use the elixir Tracker #1105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JuArce
merged 9 commits into
1075-feattelemetry-implement-telemetry-for-aggregator
from
modify-aggregator-to-use-tracker
Oct 1, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8d7ea02
feat: modify the aggregator to use the elixir Tracker
avilagaston9 72d21d4
fix: linter
avilagaston9 bd6465e
feat: add operatorResponse and quorumReached endpoints
avilagaston9 6a5ce43
feat: add task error logs
avilagaston9 c6bb3f7
refactor: telemetry module
avilagaston9 b9895c8
refactor: address aggregator comments
avilagaston9 65759ef
refactor: remove updating the context on every event
avilagaston9 54e2e1a
refactor elixir trace
avilagaston9 ac8e957
fix: addressed comments
avilagaston9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package pkg | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "time" | ||
|
|
||
| "github.com/Layr-Labs/eigensdk-go/logging" | ||
| ) | ||
|
|
||
| type TraceMessage struct { | ||
| MerkleRoot string `json:"merkle_root"` | ||
| } | ||
|
|
||
| type OperatorResponseMessage struct { | ||
| MerkleRoot string `json:"merkle_root"` | ||
| OperatorId string `json:"operator_id"` | ||
| } | ||
| type QuorumReachedMessage struct { | ||
| MerkleRoot string `json:"merkle_root"` | ||
| } | ||
|
|
||
| type TaskErrorMessage struct { | ||
| MerkleRoot string `json:"merkle_root"` | ||
| TaskError string `json:"error"` | ||
| } | ||
|
|
||
| type Telemetry struct { | ||
| client *http.Client | ||
| baseURL *url.URL | ||
| logger logging.Logger | ||
| } | ||
|
|
||
| func NewTelemetry(serverAddress string, logger logging.Logger) *Telemetry { | ||
| client := &http.Client{} | ||
|
|
||
| baseURL := &url.URL{ | ||
| Scheme: "http", | ||
| Host: serverAddress, | ||
| } | ||
| logger.Info("[Telemetry] Starting Telemetry client.", "server_address", | ||
| serverAddress) | ||
|
|
||
| return &Telemetry{ | ||
| client: client, | ||
| baseURL: baseURL, | ||
| logger: logger, | ||
| } | ||
| } | ||
|
|
||
| func (t *Telemetry) InitNewTrace(batchMerkleRoot [32]byte) { | ||
| body := TraceMessage{ | ||
| MerkleRoot: fmt.Sprintf("0x%s", hex.EncodeToString(batchMerkleRoot[:])), | ||
| } | ||
| if err := t.sendTelemetryMessage("/api/initTaskTrace", body); err != nil { | ||
| t.logger.Error("[Telemetry] Error in InitNewTrace", "error", err) | ||
| } | ||
| } | ||
|
|
||
| func (t *Telemetry) LogOperatorResponse(batchMerkleRoot [32]byte, operatorId [32]byte) { | ||
| body := OperatorResponseMessage{ | ||
| MerkleRoot: fmt.Sprintf("0x%s", hex.EncodeToString(batchMerkleRoot[:])), | ||
| OperatorId: fmt.Sprintf("0x%s", hex.EncodeToString(operatorId[:])), | ||
| } | ||
| if err := t.sendTelemetryMessage("/api/operatorResponse", body); err != nil { | ||
| t.logger.Error("[Telemetry] Error in LogOperatorResponse", "error", err) | ||
| } | ||
| } | ||
|
|
||
| func (t *Telemetry) LogQuorumReached(batchMerkleRoot [32]byte) { | ||
| body := QuorumReachedMessage{ | ||
| MerkleRoot: fmt.Sprintf("0x%s", hex.EncodeToString(batchMerkleRoot[:])), | ||
| } | ||
| if err := t.sendTelemetryMessage("/api/quorumReached", body); err != nil { | ||
| t.logger.Error("[Telemetry] Error in LogQuorumReached", "error", err) | ||
| } | ||
| } | ||
|
|
||
| func (t *Telemetry) LogTaskError(batchMerkleRoot [32]byte, taskError error) { | ||
| body := TaskErrorMessage{ | ||
| MerkleRoot: fmt.Sprintf("0x%s", hex.EncodeToString(batchMerkleRoot[:])), | ||
| TaskError: taskError.Error(), | ||
| } | ||
| if err := t.sendTelemetryMessage("/api/taskError", body); err != nil { | ||
| t.logger.Error("[Telemetry] Error in LogTaskError", "error", err) | ||
| } | ||
| } | ||
|
|
||
| func (t *Telemetry) FinishTrace(batchMerkleRoot [32]byte) { | ||
| // In order to wait for all operator responses, even if the quorum is reached, this function has a delayed execution | ||
| go func() { | ||
| time.Sleep(10 * time.Second) | ||
|
JuArce marked this conversation as resolved.
|
||
| body := TraceMessage{ | ||
| MerkleRoot: fmt.Sprintf("0x%s", hex.EncodeToString(batchMerkleRoot[:])), | ||
| } | ||
| if err := t.sendTelemetryMessage("/api/finishTaskTrace", body); err != nil { | ||
| t.logger.Error("[Telemetry] Error in FinishTrace", "error", err) | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| func (t *Telemetry) sendTelemetryMessage(endpoint string, message interface{}) error { | ||
| encodedBody, err := json.Marshal(message) | ||
| if err != nil { | ||
| t.logger.Error("[Telemetry] Error marshalling JSON", "error", err) | ||
| return fmt.Errorf("error marshalling JSON: %w", err) | ||
| } | ||
|
|
||
| t.logger.Info("[Telemetry] Sending message.", "endpoint", endpoint, "message", message) | ||
|
|
||
| fullURL := t.baseURL.ResolveReference(&url.URL{Path: endpoint}) | ||
|
|
||
| resp, err := t.client.Post(fullURL.String(), "application/json", bytes.NewBuffer(encodedBody)) | ||
| if err != nil { | ||
| t.logger.Error("[Telemetry] Error sending POST request", "error", err) | ||
| return fmt.Errorf("error making POST request: %w", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| respBody, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| t.logger.Error("[Telemetry] Error reading response body", "error", err) | ||
| return fmt.Errorf("error reading response body: %w", err) | ||
| } | ||
|
|
||
| t.logger.Info("[Telemetry] Response received", "status", resp.Status, "response_body", string(respBody)) | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.