Skip to content

Commit

Permalink
Rename AddEventToFragment->AddActivityToFragment
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
  • Loading branch information
cipherboy and mpalmi committed May 17, 2023
1 parent 3b64ef7 commit 0c402e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions vault/acme_billing_system_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *acmeBillingSystemViewImpl) CreateActivityCountEventForIdentifiers(ctx c
// Fake our clientID from the identifiers, but ensure it is
// independent of ordering.
//
// TODO: Because of prefixing currently handled by AddEventToFragment,
// TODO: Because of prefixing currently handled by AddActivityToFragment,
// we do not need to ensure it is globally unique.
sort.Strings(identifiers)
joinedIdentifiers := "[" + strings.Join(identifiers, "]"+hopeDelim+"[") + "]"
Expand All @@ -54,7 +54,7 @@ func (a *acmeBillingSystemViewImpl) CreateActivityCountEventForIdentifiers(ctx c
// Log so users can correlate ACME requests to client count tokens.
activityType := "acme"
a.core.activityLog.logger.Debug(fmt.Sprintf("Handling ACME client count event for [%v] -> %v", identifiers, clientID))
a.core.activityLog.AddEventToFragment(clientID, a.entry.NamespaceID, time.Now().Unix(), activityType, a.entry.Accessor)
a.core.activityLog.AddActivityToFragment(clientID, a.entry.NamespaceID, time.Now().Unix(), activityType, a.entry.Accessor)

return nil
}
18 changes: 9 additions & 9 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const (
// Known types of activity events; there's presently two internal event
// types (tokens/clients with and without entities), but we're beginning
// to support additional buckets for e.g., ACME requests.
nonEntityTokenEventType = "non-entity-token"
entityEventType = "entity"
nonEntityTokenActivityType = "non-entity-token"
entityActivityType = "entity"
)

type segmentInfo struct {
Expand Down Expand Up @@ -1408,23 +1408,23 @@ func (a *ActivityLog) AddEntityToFragment(entityID string, namespaceID string, t
// AddClientToFragment checks a client ID for uniqueness and
// if not already present, adds it to the current fragment.
//
// See note below about AddEventToFragment.
// See note below about AddActivityToFragment.
func (a *ActivityLog) AddClientToFragment(clientID string, namespaceID string, timestamp int64, isTWE bool, mountAccessor string) {
// TWE == token without entity
if isTWE {
a.AddEventToFragment(clientID, namespaceID, timestamp, nonEntityTokenEventType, mountAccessor)
a.AddActivityToFragment(clientID, namespaceID, timestamp, nonEntityTokenActivityType, mountAccessor)
return
}

a.AddEventToFragment(clientID, namespaceID, timestamp, entityEventType, mountAccessor)
a.AddActivityToFragment(clientID, namespaceID, timestamp, entityActivityType, mountAccessor)
}

// AddEventToFragment adds a client count event of any type to
// AddActivityToFragment adds a client count event of any type to
// add to the current fragment. ClientIDs must be unique across
// all types; if not already present, we will add it to the current
// fragment. The timestamp is a Unix timestamp *without* nanoseconds,
// as that is what token.CreationTime uses.
func (a *ActivityLog) AddEventToFragment(clientID string, namespaceID string, timestamp int64, activityType string, mountAccessor string) {
func (a *ActivityLog) AddActivityToFragment(clientID string, namespaceID string, timestamp int64, activityType string, mountAccessor string) {
// Check whether entity ID already recorded
var present bool

Expand All @@ -1433,7 +1433,7 @@ func (a *ActivityLog) AddEventToFragment(clientID string, namespaceID string, ti
// removing if the event type is otherwise clear; notably though, this
// does help ensure clientID uniqueness across different types of tokens,
// assuming it does not break any other downstream systems.
if activityType != nonEntityTokenEventType && activityType != entityEventType {
if activityType != nonEntityTokenActivityType && activityType != entityActivityType {
clientID = activityType + "." + clientID
}

Expand Down Expand Up @@ -1470,7 +1470,7 @@ func (a *ActivityLog) AddEventToFragment(clientID string, namespaceID string, ti
// Track whether the clientID corresponds to a token without an entity or not.
// This field is backward compatible, as the default is 0, so records created
// from pre-1.9 activityLog code will automatically be marked as having an entity.
if activityType != entityEventType {
if activityType != entityActivityType {
// TODO: This part needs to be modified potentially for separate
// storage buckets of custom event types. Consider setting the above
// condition to activityType == nonEntityTokenEventType in the future.
Expand Down

0 comments on commit 0c402e5

Please sign in to comment.