-
Notifications
You must be signed in to change notification settings - Fork 34
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
5 changed files
with
65 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 | ||
|
||
import ( | ||
"time" | ||
"net/http" | ||
"encoding/json" | ||
) | ||
|
||
type ActivationEvent struct { | ||
MarbleType string `json:"marbleType"` | ||
UUID string `json:"uuid"` | ||
Quote []byte `json:"quote"` | ||
} | ||
|
||
type Event struct { | ||
Timestamp time.Time `json:"time"` | ||
Activation *ActivationEvent `json:"activation"` | ||
} | ||
|
||
type Log struct { | ||
events []Event | ||
} | ||
|
||
func NewLog() *Log { | ||
return &Log{} | ||
} | ||
|
||
func (ev *Log) Activation(marbleType string, uuid string, quote []byte) { | ||
ev.events = append(ev.events, Event{ | ||
Timestamp: time.Now(), | ||
Activation: &ActivationEvent{MarbleType: marbleType, UUID: uuid, Quote: quote}, | ||
}) | ||
} | ||
|
||
func (ev *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(ev.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