Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Signed-off-by: gordonhu7 <hu.gordon@hotmail.com>
  • Loading branch information
gordonhu7 committed Jul 18, 2023
1 parent 5a4855b commit c5de92a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The following metrics are emitted:
| Sample | `cache_manager`, `outdated_svids` | | The number of outdated SVIDs that the Cache Manager has. |
| Counter | `lru_cache_entry_add` | | The number of entries added to the LRU cache. |
| Counter | `lru_cache_entry_remove` | | The number of entries removed from the LRU cache. |
| Counter | `lru_cache_entry_update` | | The number of entries update in the LRU cache. |
| Counter | `lru_cache_entry_update` | | The number of entries updated in the LRU cache. |
| Call Counter | `manager`, `sync`, `fetch_entries_updates` | | The Sync Manager is fetching entries updates. |
| Call Counter | `manager`, `sync`, `fetch_svids_updates` | | The Sync Manager is fetching SVIDs updates. |
| Call Counter | `node`, `attestor`, `new_svid` | | The Node Attestor is calling to get an SVID. |
Expand Down
12 changes: 6 additions & 6 deletions pkg/agent/manager/cache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spiffe/go-spiffe/v2/spiffeid"
"github.com/spiffe/spire/pkg/agent/common/backoff"
"github.com/spiffe/spire/pkg/common/telemetry"
"github.com/spiffe/spire/pkg/common/telemetry/agent"
agentmetrics "github.com/spiffe/spire/pkg/common/telemetry/agent"
"github.com/spiffe/spire/proto/spire/common"
)

Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *LRUCache) NewSubscriber(selectors []*common.Selector) Subscriber {
// updated through a call to UpdateSVIDs.
func (c *LRUCache) UpdateEntries(update *UpdateEntries, checkSVID func(*common.RegistrationEntry, *common.RegistrationEntry, *X509SVID) bool) {
c.mu.Lock()
defer func() { agent.SetEntriesMapSize(c.metrics, c.CountRecords()) }()
defer func() { agentmetrics.SetEntriesMapSize(c.metrics, c.CountRecords()) }()
defer c.mu.Unlock()

// Remove bundles that no longer exist. The bundle for the agent trust
Expand Down Expand Up @@ -294,7 +294,7 @@ func (c *LRUCache) UpdateEntries(update *UpdateEntries, checkSVID func(*common.R
delete(c.staleEntries, id)
}
}
agent.IncrementEntriesRemoved(c.metrics, entriesRemoved)
agentmetrics.IncrementEntriesRemoved(c.metrics, entriesRemoved)

outdatedEntries := make(map[string]struct{})
entriesUpdated := 0
Expand Down Expand Up @@ -387,8 +387,8 @@ func (c *LRUCache) UpdateEntries(update *UpdateEntries, checkSVID func(*common.R
}
}
}
agent.IncrementEntriesAdded(c.metrics, entriesCreated)
agent.IncrementEntriesUpdated(c.metrics, entriesUpdated)
agentmetrics.IncrementEntriesAdded(c.metrics, entriesCreated)
agentmetrics.IncrementEntriesUpdated(c.metrics, entriesUpdated)

// entries with active subscribers which are not cached will be put in staleEntries map;
// irrespective of what svid cache size as we cannot deny identity to a subscriber
Expand Down Expand Up @@ -440,7 +440,7 @@ func (c *LRUCache) UpdateEntries(update *UpdateEntries, checkSVID func(*common.R

func (c *LRUCache) UpdateSVIDs(update *UpdateSVIDs) {
c.mu.Lock()
defer func() { agent.SetSVIDMapSize(c.metrics, c.CountSVIDs()) }()
defer func() { agentmetrics.SetSVIDMapSize(c.metrics, c.CountSVIDs()) }()
defer c.mu.Unlock()

// Allocate a set of selectors that
Expand Down
21 changes: 19 additions & 2 deletions pkg/agent/manager/cache/lru_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,19 +897,36 @@ func TestMetrics(t *testing.T) {
Bundles: makeBundles(bundleV1),
RegistrationEntries: makeRegistrationEntries(foo, bar),
}

// add entries to cache
cache.UpdateEntries(updateEntries, nil)
assert.Equal(t, []fakemetrics.MetricItem{
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryRemoved}, Val: 0},
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryAdded}, Val: 2},
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryUpdated}, Val: 0},
{Type: fakemetrics.SetGaugeType, Key: []string{telemetry.RecordMapSize}, Val: 2},
}, fakeMetrics.AllMetrics())

// add SVIDs to cache
updateSVIDs := &UpdateSVIDs{
X509SVIDs: makeX509SVIDs(foo),
}
cache.UpdateEntries(updateEntries, nil)
cache.UpdateSVIDs(updateSVIDs)
assert.Equal(t, []fakemetrics.MetricItem{
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryRemoved}, Val: 0},
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryAdded}, Val: 2},
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryUpdated}, Val: 0},
{Type: fakemetrics.SetGaugeType, Key: []string{telemetry.RecordMapSize}, Val: 2},
{Type: fakemetrics.SetGaugeType, Key: []string{telemetry.SVIDMapSize}, Val: 1},
}, fakeMetrics.AllMetrics())

// update entries in cache
fooUpdate := makeRegistrationEntry("FOO", "A", "B")
cache.UpdateEntries(&UpdateEntries{
Bundles: makeBundles(bundleV1),
RegistrationEntries: makeRegistrationEntries(fooUpdate),
}, nil)
cache.UpdateEntries(updateEntries, nil)

assert.Equal(t, []fakemetrics.MetricItem{
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryRemoved}, Val: 0},
{Type: fakemetrics.IncrCounterType, Key: []string{telemetry.EntryAdded}, Val: 2},
Expand Down

0 comments on commit c5de92a

Please sign in to comment.