Performance for ListFileSystem
This commit is contained in:
@ -8,7 +8,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/getsentry/sentry-go"
|
|
||||||
nomadApi "github.com/hashicorp/nomad/api"
|
nomadApi "github.com/hashicorp/nomad/api"
|
||||||
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||||
"github.com/openHPI/poseidon/internal/nomad"
|
"github.com/openHPI/poseidon/internal/nomad"
|
||||||
@ -137,7 +136,7 @@ func (r *NomadJob) ListFileSystem(
|
|||||||
command = lsCommandRecursive
|
command = lsCommandRecursive
|
||||||
}
|
}
|
||||||
|
|
||||||
ls2json := &nullio.Ls2JsonWriter{Target: content}
|
ls2json := &nullio.Ls2JsonWriter{Target: content, Ctx: ctx}
|
||||||
defer ls2json.Close()
|
defer ls2json.Close()
|
||||||
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand()
|
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand()
|
||||||
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
||||||
@ -167,11 +166,9 @@ func (r *NomadJob) UpdateFileSystem(copyRequest *dto.UpdateFileSystemRequest, ct
|
|||||||
updateFileCommand := (&dto.ExecutionRequest{Command: fileDeletionCommand + copyCommand}).FullCommand()
|
updateFileCommand := (&dto.ExecutionRequest{Command: fileDeletionCommand + copyCommand}).FullCommand()
|
||||||
stdOut := bytes.Buffer{}
|
stdOut := bytes.Buffer{}
|
||||||
stdErr := bytes.Buffer{}
|
stdErr := bytes.Buffer{}
|
||||||
span := sentry.StartSpan(ctx, "Execute Update File System")
|
|
||||||
exitCode, err := r.api.ExecuteCommand(r.id, context.Background(), updateFileCommand, false,
|
exitCode, err := r.api.ExecuteCommand(r.id, context.Background(), updateFileCommand, false,
|
||||||
nomad.PrivilegedExecution, // All files should be written and owned by a privileged user #211.
|
nomad.PrivilegedExecution, // All files should be written and owned by a privileged user #211.
|
||||||
&tarBuffer, &stdOut, &stdErr)
|
&tarBuffer, &stdOut, &stdErr)
|
||||||
span.Finish()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"%w: nomad error during file copy: %v",
|
"%w: nomad error during file copy: %v",
|
||||||
|
@ -2,8 +2,10 @@ package nullio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/openHPI/poseidon/pkg/dto"
|
"github.com/openHPI/poseidon/pkg/dto"
|
||||||
"github.com/openHPI/poseidon/pkg/logging"
|
"github.com/openHPI/poseidon/pkg/logging"
|
||||||
"io"
|
"io"
|
||||||
@ -34,10 +36,12 @@ const (
|
|||||||
// It streams the passed data to the Target and transforms the data into the json format.
|
// It streams the passed data to the Target and transforms the data into the json format.
|
||||||
type Ls2JsonWriter struct {
|
type Ls2JsonWriter struct {
|
||||||
Target io.Writer
|
Target io.Writer
|
||||||
|
Ctx context.Context
|
||||||
jsonStartSent bool
|
jsonStartSent bool
|
||||||
setCommaPrefix bool
|
setCommaPrefix bool
|
||||||
remaining []byte
|
remaining []byte
|
||||||
latestPath []byte
|
latestPath []byte
|
||||||
|
sentrySpan *sentry.Span
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Ls2JsonWriter) HasStartedWriting() bool {
|
func (w *Ls2JsonWriter) HasStartedWriting() bool {
|
||||||
@ -87,6 +91,7 @@ func (w *Ls2JsonWriter) initializeJSONObject() (count int, err error) {
|
|||||||
err = fmt.Errorf("could not write to target: %w", err)
|
err = fmt.Errorf("could not write to target: %w", err)
|
||||||
} else {
|
} else {
|
||||||
w.jsonStartSent = true
|
w.jsonStartSent = true
|
||||||
|
w.sentrySpan = sentry.StartSpan(w.Ctx, "Forwarding")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count, err
|
return count, err
|
||||||
@ -98,6 +103,7 @@ func (w *Ls2JsonWriter) Close() {
|
|||||||
if count == 0 || err != nil {
|
if count == 0 || err != nil {
|
||||||
log.WithError(err).Warn("Could not Close ls2json writer")
|
log.WithError(err).Warn("Could not Close ls2json writer")
|
||||||
}
|
}
|
||||||
|
w.sentrySpan.Finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package nullio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -18,7 +19,7 @@ type Ls2JsonTestSuite struct {
|
|||||||
|
|
||||||
func (s *Ls2JsonTestSuite) SetupTest() {
|
func (s *Ls2JsonTestSuite) SetupTest() {
|
||||||
s.buf = &bytes.Buffer{}
|
s.buf = &bytes.Buffer{}
|
||||||
s.writer = &Ls2JsonWriter{Target: s.buf}
|
s.writer = &Ls2JsonWriter{Target: s.buf, Ctx: context.Background()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ls2JsonTestSuite) TestLs2JsonWriter_WriteCreationAndClose() {
|
func (s *Ls2JsonTestSuite) TestLs2JsonWriter_WriteCreationAndClose() {
|
||||||
|
Reference in New Issue
Block a user