Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Statuscode Handler to Agent Health Extension #1423

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2348639
fixing issue
Paramadon Nov 12, 2024
b7fac5e
trying to fix logs
Paramadon Nov 12, 2024
45536b8
fixing issue
Paramadon Nov 12, 2024
75b024a
adding debug statements (swapping logger with log.print)
Paramadon Nov 13, 2024
b41de09
adding more log statments
Paramadon Nov 13, 2024
90a22a3
fixing tags
Paramadon Nov 13, 2024
8c6d037
fixing logs
Paramadon Nov 13, 2024
6ff99f8
fixing logs
Paramadon Nov 13, 2024
667f608
adding a log
Paramadon Nov 13, 2024
9de9448
fixing stats function for statuscodehandler
Paramadon Nov 13, 2024
1e690e3
fixing issue
Paramadon Nov 13, 2024
4c6adcf
making operation names shorter
Paramadon Nov 13, 2024
dc129c9
Last commit works to reduce name- this one is for filtering operation…
Paramadon Nov 13, 2024
07a06fa
adding status code only filter
Paramadon Nov 13, 2024
0f76726
removing status code from otel config
Paramadon Nov 13, 2024
965ccdb
had to add return statments to filter
Paramadon Nov 13, 2024
a8268fd
commenting out try configure for ec2tagger
Paramadon Nov 13, 2024
8ddb463
adding ecw client for ec2 tagger
Paramadon Nov 13, 2024
3c15e81
changing the middleware to metricID
Paramadon Nov 13, 2024
947b8f3
trying to get stat
Paramadon Nov 14, 2024
a76ef49
everything works just removing some debug statement and filter from h…
Paramadon Nov 15, 2024
abf484b
fixing filter issue
Paramadon Nov 15, 2024
c849f61
previous commit works, just cleaning up debug statemtns
Paramadon Nov 15, 2024
bd33dbc
adding unit tests
Paramadon Nov 15, 2024
822680f
fixing test
Paramadon Nov 19, 2024
d547e1c
fixing unit tests
Paramadon Nov 19, 2024
5dc40f4
running make fmt
Paramadon Nov 19, 2024
e5bf295
fixing unit tests
Paramadon Nov 19, 2024
e07463a
fixing tests
Paramadon Nov 19, 2024
a5ba52e
fixing yamls
Paramadon Nov 19, 2024
f3c8d46
fixing yamls
Paramadon Nov 19, 2024
f64b332
removing internal changes
Paramadon Nov 19, 2024
fa4c163
restoring files
Paramadon Nov 19, 2024
457e48c
removing unnecessary file changes and passing unit test
Paramadon Nov 19, 2024
2705e87
cleaning up code
Paramadon Nov 19, 2024
3083626
fixing up pointer issue and passing in operations
Paramadon Nov 20, 2024
9e40bd8
adding agent health to prometheus
Paramadon Nov 20, 2024
5745ee6
resolving comments
Paramadon Nov 22, 2024
6e0fdd3
resolving comments
Paramadon Nov 22, 2024
8aee0d9
adding tests
Paramadon Nov 22, 2024
f344518
resolving comments
Paramadon Nov 22, 2024
a7e0415
resolving comments
Paramadon Nov 22, 2024
d91706d
adding tests
Paramadon Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func runAgent(ctx context.Context,
c.OutputFilters = outputFilters
c.InputFilters = inputFilters
c.AllowUnusedFields = true

err = loadTomlConfigIntoAgent(c)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions extension/agenthealth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Config struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO status code stats should have to be enabled. agenthealth/metrics and agenthealth/traces won't have any allowlisted operations, but are still going to have the handlers created and attached.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this and I changed it so that we would have to enable statuscodes

IsUsageDataEnabled bool `mapstructure:"is_usage_data_enabled"`
Stats agent.StatsConfig `mapstructure:"stats"`
StatusCodeOnly *bool `mapstructure:"is_status_code_only,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick - can be renamed to is_only_status_code_enabled
also keep it consistent with IsUsageDataEnabled with IsOnlyStatusCodeEnabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also any reason to make it a pointer ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bool with omitempty in the tag is enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with mitali. Instead of a pointer, can we treat the default value as false?

Additionally, can you explain a bit more what this field is used for? It seems like a way to set the agent health extension such that it turns the other things off. I think that may be confusing because you could set IsUsageDataEnabled to true and also set StatusCodeOnly to true, so it's not clear what it would actually do (without looking at the implementation).

Copy link
Contributor Author

@Paramadon Paramadon Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I will rename it. The pointer is used so we can emit it even if it's empty (nil). As for its functionality, I can add a comment, but the main purpose is to ensure that we only use the statuscodehandler when calling the agenthealthextension for a processor, exporter, or receiver, without including other handlers like processstats, clientstats, etc.

}

var _ component.Config = (*Config)(nil)
17 changes: 13 additions & 4 deletions extension/agenthealth/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ var _ awsmiddleware.Extension = (*agentHealth)(nil)
func (ah *agentHealth) Handlers() ([]awsmiddleware.RequestHandler, []awsmiddleware.ResponseHandler) {
var responseHandlers []awsmiddleware.ResponseHandler
requestHandlers := []awsmiddleware.RequestHandler{useragent.NewHandler(ah.cfg.IsUsageDataEnabled)}
if ah.cfg.IsUsageDataEnabled {
req, res := stats.NewHandlers(ah.logger, ah.cfg.Stats)
requestHandlers = append(requestHandlers, req...)
responseHandlers = append(responseHandlers, res...)

if !ah.cfg.IsUsageDataEnabled {
ah.logger.Debug("Usage data is disabled, skipping stats handlers")
return requestHandlers, responseHandlers
}

statusCodeOnly := false
if ah.cfg.StatusCodeOnly != nil {
statusCodeOnly = *ah.cfg.StatusCodeOnly
}
statsRequestHandlers, statsResponseHandlers := stats.NewHandlers(ah.logger, ah.cfg.Stats, statusCodeOnly)
requestHandlers = append(requestHandlers, statsRequestHandlers...)
responseHandlers = append(responseHandlers, statsResponseHandlers...)

return requestHandlers, responseHandlers
}

Expand Down
2 changes: 1 addition & 1 deletion extension/agenthealth/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestExtension(t *testing.T) {
assert.NoError(t, extension.Start(ctx, componenttest.NewNopHost()))
requestHandlers, responseHandlers := extension.Handlers()
// user agent, client stats, stats
assert.Len(t, requestHandlers, 3)
assert.Len(t, requestHandlers, 4)
// client stats
assert.Len(t, responseHandlers, 1)
cfg.IsUsageDataEnabled = false
Expand Down
107 changes: 92 additions & 15 deletions extension/agenthealth/handler/stats/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package agent

import (
"encoding/json"
"log"
"strings"

"github.com/aws/amazon-cloudwatch-agent/internal/util/collections"
Expand All @@ -15,21 +16,22 @@ const (
)

type Stats struct {
CpuPercent *float64 `json:"cpu,omitempty"`
MemoryBytes *uint64 `json:"mem,omitempty"`
FileDescriptorCount *int32 `json:"fd,omitempty"`
ThreadCount *int32 `json:"th,omitempty"`
LatencyMillis *int64 `json:"lat,omitempty"`
PayloadBytes *int `json:"load,omitempty"`
StatusCode *int `json:"code,omitempty"`
SharedConfigFallback *int `json:"scfb,omitempty"`
ImdsFallbackSucceed *int `json:"ifs,omitempty"`
AppSignals *int `json:"as,omitempty"`
EnhancedContainerInsights *int `json:"eci,omitempty"`
RunningInContainer *int `json:"ric,omitempty"`
RegionType *string `json:"rt,omitempty"`
Mode *string `json:"m,omitempty"`
EntityRejected *int `json:"ent,omitempty"`
CpuPercent *float64 `json:"cpu,omitempty"`
MemoryBytes *uint64 `json:"mem,omitempty"`
FileDescriptorCount *int32 `json:"fd,omitempty"`
ThreadCount *int32 `json:"th,omitempty"`
LatencyMillis *int64 `json:"lat,omitempty"`
PayloadBytes *int `json:"load,omitempty"`
StatusCode *int `json:"code,omitempty"`
SharedConfigFallback *int `json:"scfb,omitempty"`
ImdsFallbackSucceed *int `json:"ifs,omitempty"`
AppSignals *int `json:"as,omitempty"`
EnhancedContainerInsights *int `json:"eci,omitempty"`
RunningInContainer *int `json:"ric,omitempty"`
RegionType *string `json:"rt,omitempty"`
Mode *string `json:"m,omitempty"`
EntityRejected *int `json:"ent,omitempty"`
StatusCodes map[string][5]int `json:"codes,omitempty"` //represents status codes 200,400,408,413,429,
}

// Merge the other Stats into the current. If the field is not nil,
Expand Down Expand Up @@ -80,6 +82,45 @@ func (s *Stats) Merge(other Stats) {
if other.EntityRejected != nil {
s.EntityRejected = other.EntityRejected
}
if other.StatusCodes != nil {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
log.Println("Merging status codes from another source.")
Paramadon marked this conversation as resolved.
Show resolved Hide resolved

if s.StatusCodes == nil {
log.Println("Initializing status codes map as it was nil.")
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
s.StatusCodes = make(map[string][5]int)
}

for key, value := range other.StatusCodes {
log.Printf("Processing key: %s with value: 200=%d, 400=%d, 408=%d, 413=%d, 429=%d", key, value[0], value[1], value[2], value[3], value[4])

if existing, ok := s.StatusCodes[key]; ok {
log.Printf(
"Key %s already exists. Existing: 200=%d, 400=%d, 408=%d, 413=%d, 429=%d. Merging with: 200=%d, 400=%d, 408=%d, 413=%d, 429=%d",
key, existing[0], existing[1], existing[2], existing[3], existing[4],
value[0], value[1], value[2], value[3], value[4],
)

//Merge the values for each status code
s.StatusCodes[key] = [5]int{
existing[0] + value[0], // 200
existing[1] + value[1], // 400
existing[2] + value[2], // 408
existing[3] + value[3], // 413
existing[4] + value[4], // 429
}

log.Printf(
"Updated key %s: 200=%d, 400=%d, 408=%d, 413=%d, 429=%d",
key, s.StatusCodes[key][0], s.StatusCodes[key][1], s.StatusCodes[key][2], s.StatusCodes[key][3], s.StatusCodes[key][4],
)
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
} else {
log.Printf("Key %s does not exist. Adding it with: 200=%d, 400=%d, 408=%d, 413=%d, 429=%d", key, value[0], value[1], value[2], value[3], value[4])
s.StatusCodes[key] = value
}
}
log.Println("Merging of status codes completed.")
}

}

func (s *Stats) Marshal() (string, error) {
Expand Down Expand Up @@ -118,3 +159,39 @@ type StatsConfig struct {
// UsageFlags are the usage flags to set on start up.
UsageFlags map[Flag]any `mapstructure:"usage_flags,omitempty"`
}

var StatusCodeOperations = []string{ // all the operations that are allowed
"DescribeInstances",
"DescribeTags",
"DescribeVolumes",
"DescribeContainerInstances",
"DescribeServices",
"DescribeTaskDefinition",
"ListServices",
"ListTasks",
"CreateLogGroup",
"CreateLogStream",
}

// NewStatusCodeOperationsFilter creates a new filter for allowed operations and status codes.
func NewStatusCodeOperationsFilter() OperationsFilter {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
allowed := collections.NewSet[string](StatusCodeOperations...)
Paramadon marked this conversation as resolved.
Show resolved Hide resolved

return OperationsFilter{
operations: allowed,
allowAll: allowed.Contains(AllowAllOperations),
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
}
}

func NewStatusCodeAndOtherOperationsFilter(operations []string) OperationsFilter {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
allowed := collections.NewSet[string](StatusCodeOperations...)

for _, operation := range operations {
allowed.Add(operation)
}

return OperationsFilter{
operations: allowed,
allowAll: allowed.Contains(AllowAllOperations),
}
}
117 changes: 42 additions & 75 deletions extension/agenthealth/handler/stats/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,105 +10,72 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMerge(t *testing.T) {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
stats := &Stats{CpuPercent: aws.Float64(1.2)}
assert.EqualValues(t, 1.2, *stats.CpuPercent)
assert.Nil(t, stats.MemoryBytes)
func TestMergeWithStatusCodes(t *testing.T) {
stats := &Stats{
StatusCodes: map[string][5]int{
"operation1": {1, 2, 3, 4, 5},
},
}

stats.Merge(Stats{
CpuPercent: aws.Float64(1.3),
MemoryBytes: aws.Uint64(123),
StatusCodes: map[string][5]int{
"operation1": {2, 3, 4, 5, 6}, // Existing operation with new values
"operation2": {0, 1, 2, 3, 4}, // New operation
},
})
assert.EqualValues(t, 1.3, *stats.CpuPercent)
assert.EqualValues(t, 123, *stats.MemoryBytes)

assert.Equal(t, [5]int{3, 5, 7, 9, 11}, stats.StatusCodes["operation1"]) // Values should sum
assert.Equal(t, [5]int{0, 1, 2, 3, 4}, stats.StatusCodes["operation2"]) // New operation added

stats.Merge(Stats{
CpuPercent: aws.Float64(1.5),
MemoryBytes: aws.Uint64(133),
FileDescriptorCount: aws.Int32(456),
ThreadCount: aws.Int32(789),
LatencyMillis: aws.Int64(1234),
PayloadBytes: aws.Int(5678),
StatusCode: aws.Int(200),
SharedConfigFallback: aws.Int(1),
ImdsFallbackSucceed: aws.Int(1),
AppSignals: aws.Int(1),
EnhancedContainerInsights: aws.Int(1),
RunningInContainer: aws.Int(0),
RegionType: aws.String("RegionType"),
Mode: aws.String("Mode"),
StatusCodes: nil,
})
assert.EqualValues(t, 1.5, *stats.CpuPercent)
assert.EqualValues(t, 133, *stats.MemoryBytes)
assert.EqualValues(t, 456, *stats.FileDescriptorCount)
assert.EqualValues(t, 789, *stats.ThreadCount)
assert.EqualValues(t, 1234, *stats.LatencyMillis)
assert.EqualValues(t, 5678, *stats.PayloadBytes)
assert.EqualValues(t, 200, *stats.StatusCode)
assert.EqualValues(t, 1, *stats.ImdsFallbackSucceed)
assert.EqualValues(t, 1, *stats.SharedConfigFallback)
assert.EqualValues(t, 1, *stats.AppSignals)
assert.EqualValues(t, 1, *stats.EnhancedContainerInsights)
assert.EqualValues(t, 0, *stats.RunningInContainer)
assert.EqualValues(t, "RegionType", *stats.RegionType)
assert.EqualValues(t, "Mode", *stats.Mode)

assert.Equal(t, [5]int{3, 5, 7, 9, 11}, stats.StatusCodes["operation1"])
assert.Equal(t, [5]int{0, 1, 2, 3, 4}, stats.StatusCodes["operation2"])
}

func TestMarshal(t *testing.T) {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
func TestMarshalWithStatusCodes(t *testing.T) {
testCases := map[string]struct {
stats *Stats
want string
}{
"WithEmpty": {
stats: &Stats{},
want: "",
},
"WithPartial": {
"WithEmptyStatusCodes": {
stats: &Stats{
CpuPercent: aws.Float64(1.2),
MemoryBytes: aws.Uint64(123),
ThreadCount: aws.Int32(789),
PayloadBytes: aws.Int(5678),
StatusCodes: map[string][5]int{},
},
want: `"cpu":1.2,"mem":123,"th":789,"load":5678`,
want: "",
},
"WithFull": {
"WithStatusCodes": {
stats: &Stats{
CpuPercent: aws.Float64(1.2),
MemoryBytes: aws.Uint64(123),
FileDescriptorCount: aws.Int32(456),
ThreadCount: aws.Int32(789),
LatencyMillis: aws.Int64(1234),
PayloadBytes: aws.Int(5678),
StatusCode: aws.Int(200),
ImdsFallbackSucceed: aws.Int(1),
StatusCodes: map[string][5]int{
"operation1": {1, 2, 3, 4, 5},
"operation2": {0, 1, 2, 3, 4},
},
},
want: `"cpu":1.2,"mem":123,"fd":456,"th":789,"lat":1234,"load":5678,"code":200,"ifs":1`,
want: `"codes":{"operation1":[1,2,3,4,5],"operation2":[0,1,2,3,4]}`,
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
got, err := testCase.stats.Marshal()
assert.NoError(t, err)
assert.Equal(t, testCase.want, got)
assert.Contains(t, got, testCase.want)
})
}
}

func TestOperationFilter(t *testing.T) {
testCases := map[string]struct {
allowedOperations []string
testOperations []string
want []bool
}{
"WithNoneAllowed": {allowedOperations: nil, testOperations: []string{"nothing", "is", "allowed"}, want: []bool{false, false, false}},
"WithSomeAllowed": {allowedOperations: []string{"are"}, testOperations: []string{"some", "are", "allowed"}, want: []bool{false, true, false}},
"WithAllAllowed": {allowedOperations: []string{"*"}, testOperations: []string{"all", "are", "allowed"}, want: []bool{true, true, true}},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
filter := NewOperationsFilter(testCase.allowedOperations...)
for index, testOperation := range testCase.testOperations {
assert.Equal(t, testCase.want[index], filter.IsAllowed(testOperation))
}
})
func TestMergeFullWithStatusCodes(t *testing.T) {
stats := &Stats{
CpuPercent: aws.Float64(1.0),
StatusCodes: map[string][5]int{"operation1": {1, 0, 0, 0, 0}},
}
stats.Merge(Stats{
CpuPercent: aws.Float64(2.0),
StatusCodes: map[string][5]int{"operation1": {0, 1, 0, 0, 0}, "operation2": {1, 1, 1, 1, 1}},
})

assert.Equal(t, 2.0, *stats.CpuPercent)
assert.Equal(t, [5]int{1, 1, 0, 0, 0}, stats.StatusCodes["operation1"])
assert.Equal(t, [5]int{1, 1, 1, 1, 1}, stats.StatusCodes["operation2"])
}
21 changes: 17 additions & 4 deletions extension/agenthealth/handler/stats/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,25 @@ const (
headerKeyAgentStats = "X-Amz-Agent-Stats"
)

func NewHandlers(logger *zap.Logger, cfg agent.StatsConfig) ([]awsmiddleware.RequestHandler, []awsmiddleware.ResponseHandler) {
filter := agent.NewOperationsFilter(cfg.Operations...)
func NewHandlers(logger *zap.Logger, cfg agent.StatsConfig, statuscodeonly bool) ([]awsmiddleware.RequestHandler, []awsmiddleware.ResponseHandler) {
statusCodeFilter := agent.NewStatusCodeOperationsFilter()
if statuscodeonly {
statusCodeStats := provider.GetStatusCodeStats(statusCodeFilter)
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
return []awsmiddleware.RequestHandler{statusCodeStats}, []awsmiddleware.ResponseHandler{statusCodeStats}
}
filter := agent.NewStatusCodeAndOtherOperationsFilter(cfg.Operations)
clientStats := client.NewHandler(filter)
stats := newStatsHandler(logger, filter, []agent.StatsProvider{clientStats, provider.GetProcessStats(), provider.GetFlagsStats()})
statusCodeStats := provider.GetStatusCodeStats(statusCodeFilter)

stats := newStatsHandler(logger, filter, []agent.StatsProvider{
clientStats,
provider.GetProcessStats(),
provider.GetFlagsStats(),
statusCodeStats,
})
agent.UsageFlags().SetValues(cfg.UsageFlags)
return []awsmiddleware.RequestHandler{stats, clientStats}, []awsmiddleware.ResponseHandler{clientStats}

return []awsmiddleware.RequestHandler{stats, clientStats, statusCodeStats}, []awsmiddleware.ResponseHandler{statusCodeStats}
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
}

type statsHandler struct {
Expand Down
15 changes: 6 additions & 9 deletions extension/agenthealth/handler/stats/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ func TestStatsHandler(t *testing.T) {
ThreadCount: aws.Int32(789),
LatencyMillis: aws.Int64(1234),
PayloadBytes: aws.Int(5678),
StatusCode: aws.Int(200),
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
ImdsFallbackSucceed: aws.Int(1),
SharedConfigFallback: aws.Int(1),
StatusCodes: map[string][5]int{
"pmd": {1, 0, 0, 0, 0},
"di": {0, 1, 0, 0, 0},
},
}
handler := newStatsHandler(
zap.NewNop(),
Expand All @@ -59,15 +62,9 @@ func TestStatsHandler(t *testing.T) {
assert.Equal(t, "", req.Header.Get(headerKeyAgentStats))
handler.filter = agent.NewOperationsFilter(agent.AllowAllOperations)
handler.HandleRequest(ctx, req)
assert.Equal(t, `"cpu":1.2,"mem":123,"fd":456,"th":789,"lat":1234,"load":5678,"code":200,"scfb":1,"ifs":1`, req.Header.Get(headerKeyAgentStats))
assert.Equal(t, `"cpu":1.2,"mem":123,"fd":456,"th":789,"lat":1234,"load":5678,"scfb":1,"ifs":1,"codes":{"di":[0,1,0,0,0],"pmd":[1,0,0,0,0]}`, req.Header.Get(headerKeyAgentStats))
stats.StatusCode = aws.Int(404)
stats.LatencyMillis = nil
handler.HandleRequest(ctx, req)
assert.Equal(t, `"cpu":1.2,"mem":123,"fd":456,"th":789,"load":5678,"code":404,"scfb":1,"ifs":1`, req.Header.Get(headerKeyAgentStats))
}

func TestNewHandlers(t *testing.T) {
Paramadon marked this conversation as resolved.
Show resolved Hide resolved
requestHandlers, responseHandlers := NewHandlers(zap.NewNop(), agent.StatsConfig{})
assert.Len(t, requestHandlers, 2)
assert.Len(t, responseHandlers, 1)
assert.Equal(t, `"cpu":1.2,"mem":123,"fd":456,"th":789,"load":5678,"code":404,"scfb":1,"ifs":1,"codes":{"di":[0,1,0,0,0],"pmd":[1,0,0,0,0]}`, req.Header.Get(headerKeyAgentStats))
}
Loading
Loading