Ensure sending of the Sentry End debug message.
This commit is contained in:

committed by
Sebastian Serth

parent
4fb6ab980b
commit
f309d0f70e
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/openHPI/poseidon/internal/config"
|
"github.com/openHPI/poseidon/internal/config"
|
||||||
"github.com/openHPI/poseidon/pkg/logging"
|
"github.com/openHPI/poseidon/pkg/logging"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -89,7 +90,8 @@ func (nc *nomadAPIClient) Execute(runnerID string,
|
|||||||
ctx context.Context, command []string, tty bool,
|
ctx context.Context, command []string, tty bool,
|
||||||
stdin io.Reader, stdout, stderr io.Writer,
|
stdin io.Reader, stdout, stderr io.Writer,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
log.WithField("command", command).Trace("Requesting Nomad Exec")
|
log.WithField("command", strings.ReplaceAll(strings.Join(command, ", "), "\n", "")).
|
||||||
|
Trace("Requesting Nomad Exec")
|
||||||
var allocations []*nomadApi.AllocationListStub
|
var allocations []*nomadApi.AllocationListStub
|
||||||
var err error
|
var err error
|
||||||
logging.StartSpan("nomad.execute.list", "List Allocations for id", ctx, func(_ context.Context) {
|
logging.StartSpan("nomad.execute.list", "List Allocations for id", ctx, func(_ context.Context) {
|
||||||
|
@ -12,11 +12,10 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// timeDebugMessageFormat is the format of messages that will be converted to debug messages.
|
// timeDebugMessageFormat is the format of messages that will be converted to debug messages.
|
||||||
timeDebugMessageFormat = "echo -ne \"\\x1EPoseidon %s $(date +%%s%%3N)\\x1E\""
|
|
||||||
// Format Parameters: 1. Debug Comment, 2. command.
|
// Format Parameters: 1. Debug Comment, 2. command.
|
||||||
timeDebugMessageFormatStart = timeDebugMessageFormat + "; %s"
|
timeDebugMessageFormatStart = `echo -ne "\x1EPoseidon %s $(date +%%s%%3N)\x1E"; %s`
|
||||||
// Format Parameters: 1. command, 2. Debug Comment.
|
// Format Parameters: 1. command, 2. Debug Comment.
|
||||||
timeDebugMessageFormatEnd = "%s && " + timeDebugMessageFormat
|
timeDebugMessageFormatEnd = `%s; bash -c "ec=$?; echo -ne \"\\x1EPoseidon %s \$(date +%%s%%3N)\\x1E\" && exit \$ec"`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -20,3 +20,25 @@ func TestSentryDebugWriter_Write(t *testing.T) {
|
|||||||
assert.Equal(t, len(data), count)
|
assert.Equal(t, len(data), count)
|
||||||
assert.NotContains(t, buf.String(), description)
|
assert.NotContains(t, buf.String(), description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSentryDebugWriter_Close(t *testing.T) {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
s := NewSentryDebugWriter(buf, context.Background())
|
||||||
|
require.Empty(t, s.lastSpan.Tags)
|
||||||
|
|
||||||
|
s.Close(42)
|
||||||
|
require.Contains(t, s.lastSpan.Tags, "exit_code")
|
||||||
|
assert.Equal(t, "42", s.lastSpan.Tags["exit_code"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSentryDebugWriter_handleTimeDebugMessage(t *testing.T) {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
s := NewSentryDebugWriter(buf, context.Background())
|
||||||
|
require.Equal(t, "nomad.execute.connect", s.lastSpan.Op)
|
||||||
|
|
||||||
|
description := "TestDebugMessageDescription"
|
||||||
|
match := map[string][]byte{"time": []byte("1676646791482"), "text": []byte(description)}
|
||||||
|
s.handleTimeDebugMessage(match)
|
||||||
|
assert.Equal(t, "nomad.execute.bash", s.lastSpan.Op)
|
||||||
|
assert.Equal(t, description, s.lastSpan.Description)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user