-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a log of events queriable from the metrics endpoint
fixes #304 Signed-off-by: Arvid E. Picciani <[email protected]>
- Loading branch information
Showing
9 changed files
with
86 additions
and
19 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
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
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
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,54 @@ | ||
// Copyright (c) Edgeless Systems GmbH. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
// Package events implements a log of coordinator events. | ||
package events | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
// ActivationEvent is an event that is logged when a marble is activated. | ||
type ActivationEvent struct { | ||
MarbleType string `json:"marbleType"` | ||
UUID string `json:"uuid"` | ||
Quote []byte `json:"quote"` | ||
} | ||
|
||
// Event represents a single event in the event log. | ||
type Event struct { | ||
Timestamp time.Time `json:"time"` | ||
Activation *ActivationEvent `json:"activation"` | ||
} | ||
|
||
// Log is a log of coordinator events. | ||
type Log struct { | ||
events []Event | ||
} | ||
|
||
// NewLog creates a new log. | ||
func NewLog() *Log { | ||
return &Log{} | ||
} | ||
|
||
// Activation adds an activation event to the log. | ||
func (l *Log) Activation(marbleType string, uuid string, quote []byte) { | ||
l.events = append(l.events, Event{ | ||
Timestamp: time.Now(), | ||
Activation: &ActivationEvent{MarbleType: marbleType, UUID: uuid, Quote: quote}, | ||
}) | ||
} | ||
|
||
// The http handler retutns the log as JSON array | ||
func (l *Log) Handler() http.HandlerFunc { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
json.NewEncoder(w).Encode(l.events) | ||
}) | ||
} |
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