Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace custom atomic types with stdlib atomic #4963

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ package handlers

import (
"context"
"sync/atomic"
"testing"

"github.com/elastic/elastic-agent-libs/atomic"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
Expand Down Expand Up @@ -43,15 +42,15 @@ func makeComponentState(name string, proxiedActions []string) runtime.ComponentC

type MockActionCoordinator struct {
st coordinator.State
performedActions atomic.Int
performedActions atomic.Int64
}

func (c *MockActionCoordinator) State() coordinator.State {
return c.st
}

func (c *MockActionCoordinator) PerformAction(ctx context.Context, comp component.Component, unit component.Unit, name string, params map[string]interface{}) (map[string]interface{}, error) {
c.performedActions.Inc()
c.performedActions.Add(1)
return nil, nil
}

Expand Down Expand Up @@ -118,7 +117,7 @@ func TestActionUnenrollHandler(t *testing.T) {
name string
st coordinator.State
wantErr error // Handler error
wantPerformedActions int
wantPerformedActions int64
tamperProtectionFn func() bool
}{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ package http

import (
"context"
"sync/atomic"
"time"

"github.com/elastic/elastic-agent-libs/atomic"
)

type downloadProgressReporter struct {
Expand All @@ -17,7 +16,7 @@ type downloadProgressReporter struct {
warnTimeout time.Duration
length float64

downloaded atomic.Int
downloaded atomic.Int64
started time.Time

progressObservers []progressObserver
Expand All @@ -42,7 +41,7 @@ func newDownloadProgressReporter(sourceURI string, timeout time.Duration, length

func (dp *downloadProgressReporter) Write(b []byte) (int, error) {
n := len(b)
dp.downloaded.Add(n)
dp.downloaded.Add(int64(n))
return n, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/component/runtime/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/gofrs/uuid"
Expand All @@ -28,7 +29,6 @@ import (

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent-libs/atomic"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
Expand Down Expand Up @@ -193,7 +193,7 @@ func NewManager(
errCh: make(chan error),
monitor: monitor,
grpcConfig: grpcConfig,
serverReady: atomic.NewBool(false),
serverReady: &atomic.Bool{},
doneChan: make(chan struct{}),
}
return m, nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/component/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"context"
"errors"
"sync"
"sync/atomic"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent-libs/atomic"
"github.com/elastic/elastic-agent/internal/pkg/runner"
"github.com/elastic/elastic-agent/pkg/component"
"github.com/elastic/elastic-agent/pkg/core/logger"
Expand Down Expand Up @@ -188,11 +188,10 @@ func (s *componentRuntimeState) start() error {
}

func (s *componentRuntimeState) stop(teardown bool, signed *component.Signed) error {
if s.shuttingDown.Load() {
if !s.shuttingDown.CompareAndSwap(false, true) {
// already stopping
return nil
}
s.shuttingDown.Store(true)
if teardown {
return s.runtime.Teardown(signed)
}
Expand Down