Skip to content

Commit

Permalink
moving map
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramadon committed Dec 5, 2024
1 parent 6a48268 commit af57c05
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
32 changes: 32 additions & 0 deletions extension/agenthealth/handler/stats/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,38 @@ var StatusCodeOperations = []string{ // all the operations that are allowed
"CreateLogStream",
}

// GetShortOperationName maps long operation names to short ones.
func GetShortOperationName(operation string) string {
switch operation {
case "PutRetentionPolicy":
return "pmd"
case "DescribeInstances":
return "di"
case "DescribeTags":
return "dt"
case "DescribeTasks":
return "dts"
case "DescribeVolumes":
return "dv"
case "DescribeContainerInstances":
return "dci"
case "DescribeServices":
return "ds"
case "DescribeTaskDefinition":
return "dtd"
case "ListServices":
return "ls"
case "ListTasks":
return "lt"
case "CreateLogGroup":
return "clg"
case "CreateLogStream":
return "cls"
default:
return ""
}
}

type StatsConfig struct {
// Operations are the allowed operation names to gather stats for.
Operations []string `mapstructure:"operations,omitempty"`
Expand Down
39 changes: 2 additions & 37 deletions extension/agenthealth/handler/stats/provider/statuscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func (sp *StatsProvider) processStatusCode(entry statusCodeEntry) {

// updateStatusCodeCount updates the count for the specific status code.
func (sp *StatsProvider) updateStatusCodeCount(stats *[5]int, statusCode int) {
log.Printf("Updating stats for status code: %d\n", statusCode)
switch statusCode {
case 200:
stats[0]++
Expand All @@ -117,17 +116,15 @@ func (sp *StatsProvider) updateStatusCodeCount(stats *[5]int, statusCode int) {
case 429:
stats[4]++
default:
log.Printf("Ignored status code: %d\n", statusCode)

}
}

// startResetTimer initializes a reset timer to clear stats periodically.
func (sp *StatsProvider) startResetTimer() {
log.Println("Starting stats reset timer...")
sp.resetTimer = time.AfterFunc(statusResetInterval, func() {
sp.mu.Lock()
defer sp.mu.Unlock()
log.Println("Resetting stats...")
for key := range sp.statsByOperation {
delete(sp.statsByOperation, key)
}
Expand Down Expand Up @@ -161,46 +158,14 @@ func (h *StatusCodeHandler) HandleResponse(ctx context.Context, r *http.Response
return
}

operation = GetShortOperationName(operation)
operation = agent.GetShortOperationName(operation)
if operation == "" {
return
}

h.statsProvider.EnqueueStatusCode(operation, r.StatusCode)
}

// GetShortOperationName maps long operation names to short ones.
func GetShortOperationName(operation string) string {
switch operation {
case "PutRetentionPolicy":
return "pmd"
case "DescribeInstances":
return "di"
case "DescribeTags":
return "dt"
case "DescribeTasks":
return "dts"
case "DescribeVolumes":
return "dv"
case "DescribeContainerInstances":
return "dci"
case "DescribeServices":
return "ds"
case "DescribeTaskDefinition":
return "dtd"
case "ListServices":
return "ls"
case "ListTasks":
return "lt"
case "CreateLogGroup":
return "clg"
case "CreateLogStream":
return "cls"
default:
return ""
}
}

// Stats returns the aggregated stats for operations.
func (sp *StatsProvider) Stats(_ string) agent.Stats {
sp.mu.Lock()
Expand Down

0 comments on commit af57c05

Please sign in to comment.