diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a69588c3..fdfb76d5 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -35,7 +35,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '1.18' - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: @@ -54,18 +54,18 @@ jobs: fetch-depth: "0" - uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '1.18' - name: Unit Tests run: make mod_download && make test_unit_codecov - name: Push CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3.1.1 with: file: coverage.txt flags: unittests - fail_ci_if_error: true + fail_ci_if_error: false - uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '1.18' - name: Lint run: make install && make lint - name: Bench tests diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index fbc7b27c..88d81f62 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -17,11 +17,11 @@ jobs: - name: Unit Tests run: make mod_download && make test_unit_codecov - name: Push CodeCov - uses: codecov/codecov-action@v1.5.2 + uses: codecov/codecov-action@v3.1.1 with: file: coverage.txt flags: unittests - fail_ci_if_error: true + fail_ci_if_error: false - name: Bench tests run: make install && make test_benchmark lint: diff --git a/Makefile b/Makefile index 80ed5f01..0b5dae5a 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,3 @@ compile: .PHONY: test_unit_codecov test_unit_codecov: go test ./... -race -coverprofile=coverage.txt -covermode=atomic - curl -s https://codecov.io/bash > codecov_bash.sh && bash codecov_bash.sh diff --git a/contextutils/context.go b/contextutils/context.go index 9bc6a48d..3b8224a7 100644 --- a/contextutils/context.go +++ b/contextutils/context.go @@ -24,6 +24,7 @@ const ( RoutineLabelKey Key = "routine" LaunchPlanIDKey Key = "lp" ResourceVersionKey Key = "res_ver" + SignalIDKey Key = "signal" ) func (k Key) String() string { @@ -126,6 +127,11 @@ func WithTaskType(ctx context.Context, taskType string) context.Context { return context.WithValue(ctx, TaskTypeKey, taskType) } +// Gets a new context with SignalID set. +func WithSignalID(ctx context.Context, signalID string) context.Context { + return context.WithValue(ctx, SignalIDKey, signalID) +} + // Gets a new context with Go Routine label key set and a label assigned to the context using pprof.Labels. // You can then call pprof.SetGoroutineLabels(ctx) to annotate the current go-routine and have that show up in // pprof analysis. diff --git a/contextutils/context_test.go b/contextutils/context_test.go index e2effe3a..f6cb8427 100644 --- a/contextutils/context_test.go +++ b/contextutils/context_test.go @@ -102,6 +102,13 @@ func TestWithTaskID(t *testing.T) { assert.Equal(t, "task", ctx.Value(TaskIDKey)) } +func TestWithSignalID(t *testing.T) { + ctx := context.Background() + assert.Nil(t, ctx.Value(SignalIDKey)) + ctx = WithSignalID(ctx, "signal") + assert.Equal(t, "signal", ctx.Value(SignalIDKey)) +} + func TestGetFields(t *testing.T) { ctx := context.Background() ctx = WithJobID(WithNamespace(ctx, "ns123"), "job123") diff --git a/storage/mocks/composed_protobuf_store.go b/storage/mocks/composed_protobuf_store.go index 6e28fbbf..0b645eda 100644 --- a/storage/mocks/composed_protobuf_store.go +++ b/storage/mocks/composed_protobuf_store.go @@ -89,6 +89,38 @@ func (_m *ComposedProtobufStore) CreateSignedURL(ctx context.Context, reference return r0, r1 } +type ComposedProtobufStore_Delete struct { + *mock.Call +} + +func (_m ComposedProtobufStore_Delete) Return(_a0 error) *ComposedProtobufStore_Delete { + return &ComposedProtobufStore_Delete{Call: _m.Call.Return(_a0)} +} + +func (_m *ComposedProtobufStore) OnDelete(ctx context.Context, reference storage.DataReference) *ComposedProtobufStore_Delete { + c := _m.On("Delete", ctx, reference) + return &ComposedProtobufStore_Delete{Call: c} +} + +func (_m *ComposedProtobufStore) OnDeleteMatch(matchers ...interface{}) *ComposedProtobufStore_Delete { + c := _m.On("Delete", matchers...) + return &ComposedProtobufStore_Delete{Call: c} +} + +// Delete provides a mock function with given fields: ctx, reference +func (_m *ComposedProtobufStore) Delete(ctx context.Context, reference storage.DataReference) error { + ret := _m.Called(ctx, reference) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) error); ok { + r0 = rf(ctx, reference) + } else { + r0 = ret.Error(0) + } + + return r0 +} + type ComposedProtobufStore_GetBaseContainerFQN struct { *mock.Call } diff --git a/storage/mocks/raw_store.go b/storage/mocks/raw_store.go index 9bda8187..cb9d9b15 100644 --- a/storage/mocks/raw_store.go +++ b/storage/mocks/raw_store.go @@ -87,6 +87,38 @@ func (_m *RawStore) CreateSignedURL(ctx context.Context, reference storage.DataR return r0, r1 } +type RawStore_Delete struct { + *mock.Call +} + +func (_m RawStore_Delete) Return(_a0 error) *RawStore_Delete { + return &RawStore_Delete{Call: _m.Call.Return(_a0)} +} + +func (_m *RawStore) OnDelete(ctx context.Context, reference storage.DataReference) *RawStore_Delete { + c := _m.On("Delete", ctx, reference) + return &RawStore_Delete{Call: c} +} + +func (_m *RawStore) OnDeleteMatch(matchers ...interface{}) *RawStore_Delete { + c := _m.On("Delete", matchers...) + return &RawStore_Delete{Call: c} +} + +// Delete provides a mock function with given fields: ctx, reference +func (_m *RawStore) Delete(ctx context.Context, reference storage.DataReference) error { + ret := _m.Called(ctx, reference) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, storage.DataReference) error); ok { + r0 = rf(ctx, reference) + } else { + r0 = ret.Error(0) + } + + return r0 +} + type RawStore_GetBaseContainerFQN struct { *mock.Call } diff --git a/storage/protobuf_store.go b/storage/protobuf_store.go index 6847e91a..bf736154 100644 --- a/storage/protobuf_store.go +++ b/storage/protobuf_store.go @@ -99,7 +99,11 @@ func newProtoMetrics(scope promutils.Scope) *protoMetrics { } } -func NewDefaultProtobufStore(store RawStore, metrics *protoMetrics) DefaultProtobufStore { +func NewDefaultProtobufStore(store RawStore, scope promutils.Scope) DefaultProtobufStore { + return NewDefaultProtobufStoreWithMetrics(store, newProtoMetrics(scope)) +} + +func NewDefaultProtobufStoreWithMetrics(store RawStore, metrics *protoMetrics) DefaultProtobufStore { return DefaultProtobufStore{ RawStore: store, metrics: metrics, diff --git a/storage/protobuf_store_test.go b/storage/protobuf_store_test.go index d662ef53..78b10ba8 100644 --- a/storage/protobuf_store_test.go +++ b/storage/protobuf_store_test.go @@ -157,7 +157,7 @@ func TestDefaultProtobufStore_HardErrors(t *testing.T) { return nil, fmt.Errorf(dummyReadErrorMsg) }, } - pbErroneousStore := NewDefaultProtobufStore(store, metrics.protoMetrics) + pbErroneousStore := NewDefaultProtobufStoreWithMetrics(store, metrics.protoMetrics) t.Run("Test if hard write errors are handled correctly", func(t *testing.T) { err := pbErroneousStore.WriteProtobuf(ctx, k1, Options{}, &mockProtoMessage{X: 5}) assert.False(t, IsFailedWriteToCache(err)) diff --git a/storage/rawstores.go b/storage/rawstores.go index f99cd8e3..eafeff54 100644 --- a/storage/rawstores.go +++ b/storage/rawstores.go @@ -106,7 +106,7 @@ func (ds *DataStore) RefreshConfig(cfg *Config) error { } rawStore = newCachedRawStore(cfg, rawStore, ds.metrics.cacheMetrics) - protoStore := NewDefaultProtobufStore(rawStore, ds.metrics.protoMetrics) + protoStore := NewDefaultProtobufStoreWithMetrics(rawStore, ds.metrics.protoMetrics) newDS := NewCompositeDataStore(NewURLPathConstructor(), protoStore) newDS.metrics = ds.metrics *ds = *newDS