Skip to content

Commit b18bdda

Browse files
authored
Merge pull request #61 from reproio/handle-target-status-code-properly
Set target status code group to "-"
2 parents dbaab59 + 259078d commit b18bdda

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

log_file_reader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ type Metric struct {
118118
}
119119

120120
func (m *Metric) TargetStatusCodeGroup() string {
121-
code := ""
121+
// TargetStatusCode is - when the target does not send a response
122+
// see: https://docs.aws.amazon.com/ja_jp/elasticloadbalancing/latest/application/load-balancer-access-logs.html
123+
code := "-"
122124
switch {
123125
case strings.HasPrefix(m.TargetStatusCode, "1"):
124126
code = "1xx"

metrics_submitter_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,53 @@ func TestMetricsSubmitter_targetProcessingTime(t *testing.T) {
112112
},
113113
wantErr: false,
114114
},
115+
{
116+
name: "TargetStatusCode is -",
117+
fields: fields{
118+
TargetProcessingTimeMetricName: "target_processing_time",
119+
},
120+
args: args{
121+
metric: &Metric{
122+
TargetProcessingTimesMap: map[Timestamp]TargetProcessingTimes{
123+
Timestamp(1): {-1},
124+
Timestamp(2): {-1},
125+
},
126+
Method: "GET",
127+
Path: "/",
128+
ElbStatusCode: "460",
129+
TargetStatusCode: "-",
130+
Elb: "elb",
131+
TargetGroupArn: "arn",
132+
},
133+
},
134+
want: []datadogV1.DistributionPointsSeries{
135+
datadogV1.DistributionPointsSeries{
136+
Metric: "target_processing_time",
137+
Points: [][]datadogV1.DistributionPointItem{
138+
{
139+
{DistributionPointTimestamp: datadog.PtrFloat64(1)},
140+
{DistributionPointData: &[]float64{-1}},
141+
},
142+
{
143+
{DistributionPointTimestamp: datadog.PtrFloat64(2)},
144+
{DistributionPointData: &[]float64{-1}},
145+
},
146+
},
147+
Tags: []string{
148+
"elb:elb",
149+
"target_group_arn:arn",
150+
"path:/",
151+
"method:GET",
152+
"elb_status_code:460",
153+
"target_status_code:-",
154+
"target_status_code_group:-",
155+
"ip_address:172.160.001.192",
156+
},
157+
Type: &typeVar,
158+
},
159+
},
160+
wantErr: false,
161+
},
115162
}
116163
for _, tt := range tests {
117164
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)