Add additional performance spans
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
@ -37,7 +38,8 @@ func (n *AbstractManager) Get(_ dto.EnvironmentID, _ bool) (runner.ExecutionEnvi
|
||||
return nil, runner.ErrRunnerNotFound
|
||||
}
|
||||
|
||||
func (n *AbstractManager) CreateOrUpdate(_ dto.EnvironmentID, _ dto.ExecutionEnvironmentRequest) (bool, error) {
|
||||
func (n *AbstractManager) CreateOrUpdate(_ dto.EnvironmentID, _ dto.ExecutionEnvironmentRequest, _ context.Context) (
|
||||
bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
@ -41,9 +42,9 @@ func (a *AWSEnvironmentManager) Get(id dto.EnvironmentID, fetch bool) (runner.Ex
|
||||
}
|
||||
|
||||
func (a *AWSEnvironmentManager) CreateOrUpdate(
|
||||
id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest) (bool, error) {
|
||||
id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest, ctx context.Context) (bool, error) {
|
||||
if !isAWSEnvironment(request) {
|
||||
isCreated, err := a.NextHandler().CreateOrUpdate(id, request)
|
||||
isCreated, err := a.NextHandler().CreateOrUpdate(id, request, ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("aws wrapped: %w", err)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
@ -18,7 +19,8 @@ func TestAWSEnvironmentManager_CreateOrUpdate(t *testing.T) {
|
||||
|
||||
t.Run("can create default Java environment", func(t *testing.T) {
|
||||
config.Config.AWS.Functions = []string{uniqueImage}
|
||||
_, err := m.CreateOrUpdate(tests.AnotherEnvironmentIDAsInteger, dto.ExecutionEnvironmentRequest{Image: uniqueImage})
|
||||
_, err := m.CreateOrUpdate(
|
||||
tests.AnotherEnvironmentIDAsInteger, dto.ExecutionEnvironmentRequest{Image: uniqueImage}, context.Background())
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
@ -31,14 +33,14 @@ func TestAWSEnvironmentManager_CreateOrUpdate(t *testing.T) {
|
||||
t.Run("non-handleable requests are forwarded to the next manager", func(t *testing.T) {
|
||||
nextHandler := &ManagerHandlerMock{}
|
||||
nextHandler.On("CreateOrUpdate", mock.AnythingOfType("dto.EnvironmentID"),
|
||||
mock.AnythingOfType("dto.ExecutionEnvironmentRequest")).Return(true, nil)
|
||||
mock.AnythingOfType("dto.ExecutionEnvironmentRequest"), mock.Anything).Return(true, nil)
|
||||
m.SetNextHandler(nextHandler)
|
||||
|
||||
request := dto.ExecutionEnvironmentRequest{}
|
||||
_, err := m.CreateOrUpdate(tests.DefaultEnvironmentIDAsInteger, request)
|
||||
_, err := m.CreateOrUpdate(tests.DefaultEnvironmentIDAsInteger, request, context.Background())
|
||||
assert.NoError(t, err)
|
||||
nextHandler.AssertCalled(t, "CreateOrUpdate",
|
||||
dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), request)
|
||||
dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), request, mock.Anything)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
)
|
||||
@ -30,6 +31,7 @@ type Manager interface {
|
||||
CreateOrUpdate(
|
||||
id dto.EnvironmentID,
|
||||
request dto.ExecutionEnvironmentRequest,
|
||||
ctx context.Context,
|
||||
) (bool, error)
|
||||
|
||||
// Delete removes the specified execution environment.
|
||||
|
@ -1,8 +1,10 @@
|
||||
// Code generated by mockery v2.12.3. DO NOT EDIT.
|
||||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
|
||||
package environment
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
dto "github.com/openHPI/poseidon/pkg/dto"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
@ -14,20 +16,20 @@ type ManagerHandlerMock struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// CreateOrUpdate provides a mock function with given fields: id, request
|
||||
func (_m *ManagerHandlerMock) CreateOrUpdate(id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest) (bool, error) {
|
||||
ret := _m.Called(id, request)
|
||||
// CreateOrUpdate provides a mock function with given fields: id, request, ctx
|
||||
func (_m *ManagerHandlerMock) CreateOrUpdate(id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest, ctx context.Context) (bool, error) {
|
||||
ret := _m.Called(id, request, ctx)
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(dto.EnvironmentID, dto.ExecutionEnvironmentRequest) bool); ok {
|
||||
r0 = rf(id, request)
|
||||
if rf, ok := ret.Get(0).(func(dto.EnvironmentID, dto.ExecutionEnvironmentRequest, context.Context) bool); ok {
|
||||
r0 = rf(id, request, ctx)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(dto.EnvironmentID, dto.ExecutionEnvironmentRequest) error); ok {
|
||||
r1 = rf(id, request)
|
||||
if rf, ok := ret.Get(1).(func(dto.EnvironmentID, dto.ExecutionEnvironmentRequest, context.Context) error); ok {
|
||||
r1 = rf(id, request, ctx)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@ -153,13 +155,13 @@ func (_m *ManagerHandlerMock) Statistics() map[dto.EnvironmentID]*dto.Statistica
|
||||
return r0
|
||||
}
|
||||
|
||||
type NewManagerHandlerMockT interface {
|
||||
type mockConstructorTestingTNewManagerHandlerMock interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewManagerHandlerMock creates a new instance of ManagerHandlerMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewManagerHandlerMock(t NewManagerHandlerMockT) *ManagerHandlerMock {
|
||||
func NewManagerHandlerMock(t mockConstructorTestingTNewManagerHandlerMock) *ManagerHandlerMock {
|
||||
mock := &ManagerHandlerMock{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"github.com/getsentry/sentry-go"
|
||||
nomadApi "github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/openHPI/poseidon/internal/nomad"
|
||||
@ -89,8 +90,8 @@ func (m *NomadEnvironmentManager) List(fetch bool) ([]runner.ExecutionEnvironmen
|
||||
return m.runnerManager.ListEnvironments(), nil
|
||||
}
|
||||
|
||||
func (m *NomadEnvironmentManager) CreateOrUpdate(id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest) (
|
||||
created bool, err error) {
|
||||
func (m *NomadEnvironmentManager) CreateOrUpdate(
|
||||
id dto.EnvironmentID, request dto.ExecutionEnvironmentRequest, ctx context.Context) (created bool, err error) {
|
||||
// Check if execution environment is already existing (in the local memory).
|
||||
environment, isExistingEnvironment := m.runnerManager.GetEnvironment(id)
|
||||
if isExistingEnvironment {
|
||||
@ -112,13 +113,17 @@ func (m *NomadEnvironmentManager) CreateOrUpdate(id dto.EnvironmentID, request d
|
||||
m.runnerManager.StoreEnvironment(environment)
|
||||
|
||||
// Register template Job with Nomad.
|
||||
span := sentry.StartSpan(ctx, "Register Environment")
|
||||
err = environment.Register()
|
||||
span.Finish()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error registering template job in API: %w", err)
|
||||
}
|
||||
|
||||
// Launch idle runners based on the template job.
|
||||
span = sentry.StartSpan(ctx, "Apply Prewarming Pool Size")
|
||||
err = environment.ApplyPrewarmingPoolSize()
|
||||
span.Finish()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error scaling template job in API: %w", err)
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ func (s *CreateOrUpdateTestSuite) TestReturnsErrorIfCreatesOrUpdateEnvironmentRe
|
||||
s.apiMock.On("DeleteJob", mock.AnythingOfType("string")).Return(nil)
|
||||
s.runnerManagerMock.On("GetEnvironment", mock.AnythingOfType("dto.EnvironmentID")).Return(nil, false)
|
||||
s.runnerManagerMock.On("StoreEnvironment", mock.AnythingOfType("*environment.NomadEnvironment")).Return(true)
|
||||
_, err := s.manager.CreateOrUpdate(dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), s.request)
|
||||
_, err := s.manager.CreateOrUpdate(
|
||||
dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), s.request, context.Background())
|
||||
s.ErrorIs(err, tests.ErrDefault)
|
||||
}
|
||||
|
||||
@ -87,7 +88,8 @@ func (s *CreateOrUpdateTestSuite) TestCreateOrUpdatesSetsForcePullFlag() {
|
||||
|
||||
call.ReturnArguments = mock.Arguments{nil}
|
||||
})
|
||||
_, err := s.manager.CreateOrUpdate(dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), s.request)
|
||||
_, err := s.manager.CreateOrUpdate(
|
||||
dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger), s.request, context.Background())
|
||||
s.NoError(err)
|
||||
s.True(count > 1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user