Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Wrap stats update with lock during parallel sync (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
aramase authored and kkmsft committed Jul 27, 2019
1 parent a18049c commit 6e83e31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ e2e:

.PHONY: unit-test
unit-test:
go test -count=1 $(shell go list ./... | grep -v /test/e2e) -v
go test -race -count=1 $(shell go list ./... | grep -v /test/e2e) -v

.PHONY: validate-version
validate-version: validate-version-NMI validate-version-MIC validate-version-IDENTITY_VALIDATOR validate-version-DEMO
Expand Down
6 changes: 5 additions & 1 deletion pkg/mic/mic.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ type Client struct {
SyncLoopStarted bool
syncRetryInterval time.Duration

syncing int32 // protect against conucrrent sync's
syncing int32 // protect against conucrrent sync's
statsMutex sync.Mutex

leaderElector *leaderelection.LeaderElector
*LeaderElectionConfig
}
Expand Down Expand Up @@ -842,5 +844,7 @@ func (c *Client) updateUserMSI(newAssignedIDs []aadpodid.AzureAssignedIdentity,
c.EventRecorder.Event(removedBinding, corev1.EventTypeNormal, "binding removed",
fmt.Sprintf("Binding %s removed from node %s for pod %s", removedBinding.Name, delID.Spec.NodeName, delID.Spec.Pod))
}
c.statsMutex.Lock()
stats.Put(stats.TotalCreateOrUpdate, time.Since(beginAdding))
c.statsMutex.Unlock()
}
4 changes: 4 additions & 0 deletions pkg/mic/mic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ type TestVMClient struct {
}

func (c *TestVMClient) SetError(err error) {
c.mu.Lock()
c.err = &err
c.mu.Unlock()
}

func (c *TestVMClient) UnSetError() {
c.mu.Lock()
c.err = nil
c.mu.Unlock()
}

func (c *TestVMClient) Get(rgName string, nodeName string) (ret compute.VirtualMachine, err error) {
Expand Down

0 comments on commit 6e83e31

Please sign in to comment.