-
Notifications
You must be signed in to change notification settings - Fork 723
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
event log #1989
Merged
Merged
event log #1989
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3399e66
event log
ToniRamirezM 2311593
event log
ToniRamirezM 1a82c23
event log
ToniRamirezM c15f2ba
event log
ToniRamirezM 30f3077
event log
ToniRamirezM d74df98
fix config
ToniRamirezM 2c6d83c
reuse code
ToniRamirezM 9f48e7d
fix
ToniRamirezM 9ad11d0
fix
ToniRamirezM df2c953
fix Makefile
ToniRamirezM 7a51c30
remove default config
ToniRamirezM b48e562
remove default config
ToniRamirezM 5c20576
remove default config
ToniRamirezM 561e1c5
remove default config
ToniRamirezM 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 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 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 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 |
---|---|---|
|
@@ -145,4 +145,3 @@ Enabled = false | |
ProfilingHost = "0.0.0.0" | ||
ProfilingPort = 6060 | ||
ProfilingEnabled = false | ||
|
This file contains 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,20 @@ | ||
-- +migrate Up | ||
DROP table state.event; | ||
DROP table state.debug; | ||
|
||
-- +migrate Down | ||
CREATE TABLE state.event | ||
( | ||
event_type VARCHAR NOT NULL, | ||
timestamp TIMESTAMP WITH TIME ZONE NOT NULL, | ||
ip VARCHAR, | ||
tx_hash VARCHAR, | ||
payload VARCHAR | ||
); | ||
|
||
CREATE TABLE state.debug | ||
( | ||
error_type VARCHAR, | ||
timestamp timestamp, | ||
payload VARCHAR | ||
); |
This file contains 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,14 @@ | ||
CREATE TYPE level_t AS ENUM ('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug'); | ||
|
||
CREATE TABLE public.event ( | ||
id BIGSERIAL PRIMARY KEY, | ||
received_at timestamp WITH TIME ZONE default CURRENT_TIMESTAMP, | ||
ip_address inet, | ||
source varchar(32) not null, | ||
component varchar(32), | ||
level level_t not null, | ||
event_id varchar(32) not null, | ||
description text, | ||
data bytea, | ||
json jsonb | ||
); |
This file contains 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,9 @@ | ||
package event | ||
|
||
import "github.com/0xPolygonHermez/zkevm-node/db" | ||
|
||
// Config for event | ||
type Config struct { | ||
// DB is the database configuration | ||
DB db.Config `mapstructure:"DB"` | ||
} |
This file contains 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,88 @@ | ||
package event | ||
|
||
import ( | ||
"math/big" | ||
"time" | ||
) | ||
|
||
// EventID is the ID of the event | ||
type EventID string | ||
|
||
// Source is the source of the event | ||
type Source string | ||
|
||
// Component is the component that triggered the event | ||
type Component string | ||
|
||
// Level is the level of the event | ||
type Level string | ||
|
||
const ( | ||
// EventID_NodeComponentStarted is triggered when the node starts | ||
EventID_NodeComponentStarted = "NODE COMPONENT STARTED" | ||
// EventID_PreexecutionOOC is triggered when an OOC error is detected during the preexecution | ||
EventID_PreexecutionOOC EventID = "PRE EXECUTION OOC" | ||
// EventID_PreexecutionOOG is triggered when an OOG error is detected during the preexecution | ||
EventID_PreexecutionOOG EventID = "PRE EXECUTION OOG" | ||
// EventID_ExecutorError is triggered when an error is detected during the execution | ||
EventID_ExecutorError EventID = "EXECUTOR ERROR" | ||
// EventID_ReprocessFullBatchOOC is triggered when an OOC error is detected during the reprocessing of a full batch | ||
EventID_ReprocessFullBatchOOC EventID = "REPROCESS FULL BATCH OOC" | ||
// EventID_ExecutorRLPError is triggered when an RLP error is detected during the execution | ||
EventID_ExecutorRLPError EventID = "EXECUTOR RLP ERROR" | ||
// EventID_FinalizerHalt is triggered when the finalizer halts | ||
EventID_FinalizerHalt EventID = "FINALIZER HALT" | ||
|
||
// Source_Node is the source of the event | ||
Source_Node Source = "node" | ||
|
||
// Component_RPC is the component that triggered the event | ||
Component_RPC Component = "rpc" | ||
// Component_Pool is the component that triggered the event | ||
Component_Pool Component = "pool" | ||
// Component_Sequencer is the component that triggered the event | ||
Component_Sequencer Component = "sequencer" | ||
// Component_Synchronizer is the component that triggered the event | ||
Component_Synchronizer Component = "synchronizer" | ||
// Component_Aggregator is the component that triggered the event | ||
Component_Aggregator Component = "aggregator" | ||
// Component_EthTxManager is the component that triggered the event | ||
Component_EthTxManager Component = "ethtxmanager" | ||
// Component_GasPricer is the component that triggered the event | ||
Component_GasPricer Component = "gaspricer" | ||
// Component_Executor is the component that triggered the event | ||
Component_Executor Component = "executor" | ||
// Component_Broadcast is the component that triggered the event | ||
Component_Broadcast Component = "broadcast" | ||
|
||
// Level_Emergency is the most severe level | ||
Level_Emergency Level = "emerg" | ||
// Level_Alert is the second most severe level | ||
Level_Alert Level = "alert" | ||
// Level_Critical is the third most severe level | ||
Level_Critical Level = "crit" | ||
// Level_Error is the fourth most severe level | ||
Level_Error Level = "err" | ||
// Level_Warning is the fifth most severe level | ||
Level_Warning Level = "warning" | ||
// Level_Notice is the sixth most severe level | ||
Level_Notice Level = "notice" | ||
// Level_Info is the seventh most severe level | ||
Level_Info Level = "info" | ||
// Level_Debug is the least severe level | ||
Level_Debug Level = "debug" | ||
) | ||
|
||
// Event represents a event that may be investigated | ||
type Event struct { | ||
Id big.Int | ||
ReceivedAt time.Time | ||
IPAddress string | ||
Source Source | ||
Component Component | ||
Level Level | ||
EventID EventID | ||
Description string | ||
Data []byte | ||
Json interface{} | ||
} |
This file contains 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,53 @@ | ||
package event | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node/log" | ||
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor/pb" | ||
) | ||
|
||
// EventLog is the main struct for the event log | ||
type EventLog struct { | ||
cfg Config | ||
storage Storage | ||
} | ||
|
||
// NewEventLog creates and initializes an instance of EventLog | ||
func NewEventLog(cfg Config, storage Storage) *EventLog { | ||
return &EventLog{ | ||
cfg: cfg, | ||
storage: storage, | ||
} | ||
} | ||
|
||
// LogEvent is used to store an event for runtime debugging | ||
func (e *EventLog) LogEvent(ctx context.Context, event *Event) error { | ||
return e.storage.LogEvent(ctx, event) | ||
} | ||
|
||
// LogExecutorError is used to store Executor error for runtime debugging | ||
func (e *EventLog) LogExecutorError(ctx context.Context, responseError pb.ExecutorError, processBatchRequest *pb.ProcessBatchRequest) { | ||
timestamp := time.Now() | ||
log.Errorf("error found in the executor: %v at %v", responseError, timestamp) | ||
payload, err := json.Marshal(processBatchRequest) | ||
if err != nil { | ||
log.Errorf("error marshaling payload: %v", err) | ||
} else { | ||
event := &Event{ | ||
ReceivedAt: timestamp, | ||
Source: Source_Node, | ||
Component: Component_Executor, | ||
Level: Level_Error, | ||
EventID: EventID_ExecutorError, | ||
Description: responseError.String(), | ||
Json: string(payload), | ||
} | ||
err = e.storage.LogEvent(ctx, event) | ||
if err != nil { | ||
log.Errorf("error storing event: %v", err) | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to use
IF NOT EXIST
to avoid problems. I know this situation shouldn't happen in theory