-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(executor): Executor now sends the ExecutionStep event
This event unifies the old `log_trace` table and `heap_trace` table in one event. This pr now makes it so the executor only calls one function and it will emit this event, and also append to the old tables for now. In the future we will be able to remove those appends. This also allowed some more refactoring of the handlers, we no longer use the `EventLogEmitter` so this could be removed. This also simplied the `Executor` type.
- Loading branch information
1 parent
239bd2a
commit 47a2b75
Showing
6 changed files
with
119 additions
and
116 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package executor | ||
|
||
import ( | ||
"database/sql" | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/symbiont-io/detsys-testkit/src/lib" | ||
) | ||
|
||
// We should probably have what kind of step this is, message vs. timer | ||
type ExecutionStepEvent struct { | ||
Meta lib.MetaInfo | ||
Reactor string | ||
SimulatedTime time.Time | ||
LogLines []string | ||
HeapDiff json.RawMessage | ||
} | ||
|
||
// This should be removed when are not using the old events anymore | ||
func emitOldEvents(db *sql.DB, event ExecutionStepEvent) { | ||
appendHeapTrace(db, event.Meta.TestId, event.Meta.RunId, event.Reactor, event.HeapDiff, event.SimulatedTime) | ||
|
||
for _, p := range event.LogLines { | ||
lib.AddLogStamp(db, event.Meta.TestId, event.Meta.RunId, event.Reactor, []byte(p), event.SimulatedTime) | ||
} | ||
} | ||
|
||
func EmitExecutionStepEvent(db *sql.DB, event ExecutionStepEvent) { | ||
metaBlob, err := json.Marshal(struct { | ||
Component string `json:"component"` | ||
RunId lib.RunId `json:"run-id"` | ||
TestId lib.TestId `json:"test-id"` | ||
}{ | ||
Component: "executor", | ||
RunId: event.Meta.RunId, | ||
TestId: event.Meta.TestId, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
dataBlob, err := json.Marshal(struct { | ||
Reactor string `json:"reactor"` | ||
LogicalTime int `json:"logical-time"` | ||
SimulatedTime time.Time `json:"simulated-time"` | ||
LogLines []string `json:"log-lines"` | ||
HeapDiff json.RawMessage `json:"diff"` | ||
}{ | ||
Reactor: event.Reactor, | ||
LogicalTime: event.Meta.LogicalTime, | ||
SimulatedTime: event.SimulatedTime, | ||
LogLines: event.LogLines, | ||
HeapDiff: event.HeapDiff, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
stmt, err := db.Prepare(`INSERT INTO event_log(event, meta, data) VALUES(?,?,?)`) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer stmt.Close() | ||
|
||
_, err = stmt.Exec("ExecutionStep", metaBlob, dataBlob) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Remove when we no longer use old events | ||
emitOldEvents(db, event) | ||
} |
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 was deleted.
Oops, something went wrong.
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