Commit 032e3101 authored by Akshay Bharambe's avatar Akshay Bharambe
Browse files

Add: Display branchwise activity statistics

parent fcb88377
Branches
Tags MEP19.03.2020
2 merge requests!220Release v2.0.0 alpha,!219Add: Support for branches
Showing with 22 additions and 4 deletions
...@@ -101,7 +101,7 @@ func executeServiceWithBranch(name, branch string, data []byte, isRestricted, is ...@@ -101,7 +101,7 @@ func executeServiceWithBranch(name, branch string, data []byte, isRestricted, is
serviceCache.preHooksExec(&rs, &principalObj) serviceCache.preHooksExec(&rs, &principalObj)
go serviceCache.Service(&rs, principalObj) go serviceCache.Service(&rs, principalObj)
servingTime := time.Since(start) servingTime := time.Since(start)
go statemdl.UpdateServiceState(name, servingTime, serviceError, isRestricted, isRoleBased) go statemdl.UpdateServiceStateWithBranch(name, branch, servingTime, serviceError, isRestricted, isRoleBased)
return asyncToken, nil, isCompressed, errormdl.NOERROR, nil return asyncToken, nil, isCompressed, errormdl.NOERROR, nil
} }
rs := gjson.ParseBytes(data) rs := gjson.ParseBytes(data)
...@@ -112,7 +112,7 @@ func executeServiceWithBranch(name, branch string, data []byte, isRestricted, is ...@@ -112,7 +112,7 @@ func executeServiceWithBranch(name, branch string, data []byte, isRestricted, is
servingTime := time.Since(start) servingTime := time.Since(start)
// Record State for every service // Record State for every service
go statemdl.UpdateServiceState(name, servingTime, serviceError, isRestricted, isRoleBased) go statemdl.UpdateServiceStateWithBranch(name, branch, servingTime, serviceError, isRestricted, isRoleBased)
if serviceError == nil { if serviceError == nil {
serviceCache.postHooksExec(result, &principalObj) serviceCache.postHooksExec(result, &principalObj)
......
...@@ -29,6 +29,7 @@ type Statistic struct { ...@@ -29,6 +29,7 @@ type Statistic struct {
Description string `json:"description"` Description string `json:"description"`
IsRestricted bool `json:"isRestricted"` IsRestricted bool `json:"isRestricted"`
IsRoleBased bool `json:"isRoleBased"` IsRoleBased bool `json:"isRoleBased"`
Branch string `json:"branch"` // Only applicable to activity stats
} }
type groupResponse struct { type groupResponse struct {
...@@ -196,17 +197,34 @@ func updateGroupCache(hitCount int64) { ...@@ -196,17 +197,34 @@ func updateGroupCache(hitCount int64) {
// UpdateServiceState - update entry of service in state map // UpdateServiceState - update entry of service in state map
func UpdateServiceState(serviceName string, servingTime time.Duration, serviceError error, isRestricted, isRoleBased bool) { func UpdateServiceState(serviceName string, servingTime time.Duration, serviceError error, isRestricted, isRoleBased bool) {
UpdateServiceStateWithBranch(serviceName, "main", servingTime, serviceError, isRestricted, isRoleBased)
}
func concatenateNameWithBranch(name, branch string) string {
if branch == "" {
return name + "_main"
}
return name + "_" + branch
}
// UpdateServiceStateWithBranch - update entry of service from a branch in state map
func UpdateServiceStateWithBranch(serviceName, branch string, servingTime time.Duration, serviceError error, isRestricted, isRoleBased bool) {
if !initStatus { if !initStatus {
return return
} }
stateMutex.Lock() stateMutex.Lock()
serviceState, ok := stateCache[serviceName]
key := concatenateNameWithBranch(serviceName, branch)
serviceState, ok := stateCache[key]
if !ok { if !ok {
serviceState = Statistic{ serviceState = Statistic{
ServiceName: serviceName, ServiceName: serviceName,
Name: serviceName, Name: serviceName,
IsRestricted: isRestricted, IsRestricted: isRestricted,
IsRoleBased: isRoleBased, IsRoleBased: isRoleBased,
Branch: branch,
} }
} }
serviceState.TotalHits++ serviceState.TotalHits++
...@@ -224,7 +242,7 @@ func UpdateServiceState(serviceName string, servingTime time.Duration, serviceEr ...@@ -224,7 +242,7 @@ func UpdateServiceState(serviceName string, servingTime time.Duration, serviceEr
serviceState.MinTime = servingTime serviceState.MinTime = servingTime
} }
} }
stateCache[serviceName] = serviceState stateCache[key] = serviceState
stateMutex.Unlock() stateMutex.Unlock()
updateGlobalHit() updateGlobalHit()
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment