diff --git a/pkg/origin/process.go b/pkg/origin/process.go index 00a7130..f8a27f4 100644 --- a/pkg/origin/process.go +++ b/pkg/origin/process.go @@ -113,7 +113,7 @@ func Process(response *Response, serviceID, serviceName, serviceVersion string, 0.0005: stats.Latency0to1, // yolo } { for i := uint64(0); i < n; i++ { - m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin).Observe(v) + m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin, srcDelivery).Observe(v) } } @@ -132,7 +132,7 @@ func Process(response *Response, serviceID, serviceName, serviceVersion string, 0.0005: stats.WafLatency0to1, // yolo } { for i := uint64(0); i < n; i++ { - m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin).Observe(v) + m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin, srcWaf).Observe(v) } } @@ -151,7 +151,7 @@ func Process(response *Response, serviceID, serviceName, serviceVersion string, 0.0005: stats.ComputeLatency0to1, // yolo } { for i := uint64(0); i < n; i++ { - m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin).Observe(v) + m.LatencySeconds.WithLabelValues(serviceID, serviceName, datacenter, origin, srcCompute).Observe(v) } } } diff --git a/pkg/origin/response.go b/pkg/origin/response.go index 40b2d2c..543a496 100644 --- a/pkg/origin/response.go +++ b/pkg/origin/response.go @@ -22,45 +22,44 @@ type ByOrigin map[string]Stats // Stats for a specific datacenter and origin. type Stats struct { - RespBodyBytes uint64 `json:"resp_body_bytes"` // Number of body bytes from origin. - RespHeaderBytes uint64 `json:"resp_header_bytes"` // Number of header bytes from origin. - Responses uint64 `json:"responses"` // Number of responses from origin. - Status1xx uint64 `json:"status_1xx"` // Number of 1xx "Informational" status codes delivered from origin. - Status200 uint64 `json:"status_200"` // Number of responses received with status code 200 (Success) from origin. - Status204 uint64 `json:"status_204"` // Number of responses received with status code 204 (No Content) from origin. - Status2xx uint64 `json:"status_2xx"` // Number of 2xx "Success" status codes delivered from origin. - Status301 uint64 `json:"status_301"` // Number of responses received with status code 301 (Moved Permanently) from origin. - Status302 uint64 `json:"status_302"` // Number of responses received with status code 302 (Found) from origin. - Status304 uint64 `json:"status_304"` // Number of responses received with status code 304 (Not Modified) from origin. - Status3xx uint64 `json:"status_3xx"` // Number of 3xx "Redirection" codes delivered from origin. - Status400 uint64 `json:"status_400"` // Number of responses received with status code 400 (Bad Request) from origin. - Status401 uint64 `json:"status_401"` // Number of responses received with status code 401 (Unauthorized) from origin. - Status403 uint64 `json:"status_403"` // Number of responses received with status code 403 (Forbidden) from origin. - Status404 uint64 `json:"status_404"` // Number of responses received with status code 404 (Not Found) from origin. - Status416 uint64 `json:"status_416"` // Number of responses received with status code 416 (Range Not Satisfiable) from origin. - Status4xx uint64 `json:"status_4xx"` // Number of 4xx "Client Error" codes delivered from origin. - Status500 uint64 `json:"status_500"` // Number of responses received with status code 500 (Internal Server Error) from origin. - Status501 uint64 `json:"status_501"` // Number of responses received with status code 501 (Not Implemented) from origin. - Status502 uint64 `json:"status_502"` // Number of responses received with status code 502 (Bad Gateway) from origin. - Status503 uint64 `json:"status_503"` // Number of responses received with status code 503 (Service Unavailable) from origin. - Status504 uint64 `json:"status_504"` // Number of responses received with status code 504 (Gateway Timeout) from origin. - Status505 uint64 `json:"status_505"` // Number of responses received with status code 505 (HTTP Version Not Supported) from origin. - Status5xx uint64 `json:"status_5xx"` // Number of 5xx "Server Error" codes delivered from origin. - Latency0to1 uint64 `json:"latency_0_to_1ms"` // Number of responses from origin with latency between 0 and 1 millisecond. - Latency1to5 uint64 `json:"latency_1_to_5ms"` // Number of responses from origin with latency between 1 and 5 milliseconds. - Latency5to10 uint64 `json:"latency_5_to_10ms"` // Number of responses from origin with latency between 5 and 10 milliseconds. - Latency10to50 uint64 `json:"latency_10_to_50ms"` // Number of responses from origin with latency between 10 and 50 milliseconds. - Latency50to100 uint64 `json:"latency_50_to_100ms"` // Number of responses from origin with latency between 50 and 100 milliseconds. - Latency100to250 uint64 `json:"latency_100_to_250ms"` // Number of responses from origin with latency between 100 and 250 milliseconds. - Latency250to500 uint64 `json:"latency_250_to_500ms"` // Number of responses from origin with latency between 250 and 500 milliseconds. - Latency500to1000 uint64 `json:"latency_500_to_1000ms"` // Number of responses from origin with latency between 500 and 1,000 milliseconds. - Latency1000to5000 uint64 `json:"latency_1000_to_5000ms"` // Number of responses from origin with latency between 1,000 and 5,000 milliseconds. - Latency5000to10000 uint64 `json:"latency_5000_to_10000ms"` // Number of responses from origin with latency between 5,000 and 10,000 milliseconds. - Latency10000to60000 uint64 `json:"latency_10000_to_60000ms"` // Number of responses from origin with latency between 10,000 and 60,000 milliseconds. - Latency60000plus uint64 `json:"latency_60000ms"` // Number of responses from origin with latency of 60,000 milliseconds and above. - + RespBodyBytes uint64 `json:"resp_body_bytes"` // Number of body bytes from origin. + RespHeaderBytes uint64 `json:"resp_header_bytes"` // Number of header bytes from origin. + Responses uint64 `json:"responses"` // Number of responses from origin. + Status1xx uint64 `json:"status_1xx"` // Number of 1xx "Informational" status codes delivered from origin. + Status200 uint64 `json:"status_200"` // Number of responses received with status code 200 (Success) from origin. + Status204 uint64 `json:"status_204"` // Number of responses received with status code 204 (No Content) from origin. Status206 uint64 `json:"status_206"` // Number of responses received with status code 206 (Partial Content) from origin. + Status2xx uint64 `json:"status_2xx"` // Number of 2xx "Success" status codes delivered from origin. + Status301 uint64 `json:"status_301"` // Number of responses received with status code 301 (Moved Permanently) from origin. + Status302 uint64 `json:"status_302"` // Number of responses received with status code 302 (Found) from origin. + Status304 uint64 `json:"status_304"` // Number of responses received with status code 304 (Not Modified) from origin. + Status3xx uint64 `json:"status_3xx"` // Number of 3xx "Redirection" codes delivered from origin. + Status400 uint64 `json:"status_400"` // Number of responses received with status code 400 (Bad Request) from origin. + Status401 uint64 `json:"status_401"` // Number of responses received with status code 401 (Unauthorized) from origin. + Status403 uint64 `json:"status_403"` // Number of responses received with status code 403 (Forbidden) from origin. + Status404 uint64 `json:"status_404"` // Number of responses received with status code 404 (Not Found) from origin. + Status416 uint64 `json:"status_416"` // Number of responses received with status code 416 (Range Not Satisfiable) from origin. Status429 uint64 `json:"status_429"` // Number of responses received with status code 429 (Too Many Requests) from origin. + Status4xx uint64 `json:"status_4xx"` // Number of 4xx "Client Error" codes delivered from origin. + Status500 uint64 `json:"status_500"` // Number of responses received with status code 500 (Internal Server Error) from origin. + Status501 uint64 `json:"status_501"` // Number of responses received with status code 501 (Not Implemented) from origin. + Status502 uint64 `json:"status_502"` // Number of responses received with status code 502 (Bad Gateway) from origin. + Status503 uint64 `json:"status_503"` // Number of responses received with status code 503 (Service Unavailable) from origin. + Status504 uint64 `json:"status_504"` // Number of responses received with status code 504 (Gateway Timeout) from origin. + Status505 uint64 `json:"status_505"` // Number of responses received with status code 505 (HTTP Version Not Supported) from origin. + Status5xx uint64 `json:"status_5xx"` // Number of 5xx "Server Error" codes delivered from origin. + Latency0to1 uint64 `json:"latency_0_to_1ms"` // Number of responses from origin with latency between 0 and 1 millisecond. + Latency1to5 uint64 `json:"latency_1_to_5ms"` // Number of responses from origin with latency between 1 and 5 milliseconds. + Latency5to10 uint64 `json:"latency_5_to_10ms"` // Number of responses from origin with latency between 5 and 10 milliseconds. + Latency10to50 uint64 `json:"latency_10_to_50ms"` // Number of responses from origin with latency between 10 and 50 milliseconds. + Latency50to100 uint64 `json:"latency_50_to_100ms"` // Number of responses from origin with latency between 50 and 100 milliseconds. + Latency100to250 uint64 `json:"latency_100_to_250ms"` // Number of responses from origin with latency between 100 and 250 milliseconds. + Latency250to500 uint64 `json:"latency_250_to_500ms"` // Number of responses from origin with latency between 250 and 500 milliseconds. + Latency500to1000 uint64 `json:"latency_500_to_1000ms"` // Number of responses from origin with latency between 500 and 1,000 milliseconds. + Latency1000to5000 uint64 `json:"latency_1000_to_5000ms"` // Number of responses from origin with latency between 1,000 and 5,000 milliseconds. + Latency5000to10000 uint64 `json:"latency_5000_to_10000ms"` // Number of responses from origin with latency between 5,000 and 10,000 milliseconds. + Latency10000to60000 uint64 `json:"latency_10000_to_60000ms"` // Number of responses from origin with latency between 10,000 and 60,000 milliseconds. + Latency60000plus uint64 `json:"latency_60000ms"` // Number of responses from origin with latency of 60,000 milliseconds and above. WafResponses uint64 `json:"waf_responses"` // Number of responses received for origin requests made by the Fastly WAF. WafRespHeaderBytes uint64 `json:"waf_resp_header_bytes"` // Number of header bytes received for origin requests made by the Fastly WAF. WafRespBodyBytes uint64 `json:"waf_resp_body_bytes"` // Number of body bytes received for origin requests made by the Fastly WAF. diff --git a/pkg/rt/common_test.go b/pkg/rt/common_test.go index 212e557..46285c7 100644 --- a/pkg/rt/common_test.go +++ b/pkg/rt/common_test.go @@ -248,7 +248,7 @@ func prometheusOutput(t *testing.T, registry *prometheus.Registry, prefix string } // -// +// rt fixtures // const rtResponseFixture = `{ @@ -1920,7 +1920,7 @@ const rtResponseFixture = `{ } ` -var expetedMetricsOutputMap = map[string]float64{ +var expectedRTMetricsOutputMap = map[string]float64{ `testspace_testsystem_attack_blocked_req_body_bytes_total{datacenter="BUR",service_id="my-service-id",service_name="my-service-name"}`: 0, `testspace_testsystem_attack_blocked_req_body_bytes_total{datacenter="BWI",service_id="my-service-id",service_name="my-service-name"}`: 0, `testspace_testsystem_attack_blocked_req_body_bytes_total{datacenter="FRA",service_id="my-service-id",service_name="my-service-name"}`: 0, @@ -4344,3 +4344,324 @@ var expetedMetricsOutputMap = map[string]float64{ `testspace_testsystem_websocket_resp_header_bytes_total{datacenter="YUL",service_id="my-service-id",service_name="my-service-name"}`: 0, `testspace_testsystem_websocket_resp_header_bytes_total{datacenter="YYZ",service_id="my-service-id",service_name="my-service-name"}`: 0, } + +// +// origin fixtures +// + +const originsResponseFixture = `{ + "Data": [ + { + "datacenter": { + "TYO": { + "testorigin": { + "resp_body_bytes": 1024, + "resp_header_bytes": 64, + "responses": 10, + "status_200": 9, + "status_2xx": 9, + "status_301": 1, + "status_3xx": 1, + "latency_0_to_1ms": 1, + "latency_1_to_5ms": 1, + "latency_5_to_10ms": 1, + "latency_10_to_50ms": 1, + "latency_50_to_100ms": 6, + "waf_responses": 10, + "waf_resp_header_bytes": 1024, + "waf_resp_body_bytes": 64, + "waf_status_2xx": 10, + "waf_status_200": 10, + "waf_latency_5_to_10ms": 5, + "waf_latency_10_to_50ms": 5, + "compute_responses": 10, + "compute_resp_header_bytes": 128, + "compute_resp_body_bytes": 1024, + "compute_status_2xx": 6, + "compute_status_4xx": 4, + "compute_status_200": 6, + "compute_status_403": 4, + "compute_latency_0_to_1ms": 5, + "compute_latency_1_to_5ms": 5 + } + } + }, + "aggregated": { + "testorigin": { + "resp_body_bytes": 1024, + "resp_header_bytes": 64, + "responses": 10, + "status_200": 9, + "status_2xx": 9, + "status_301": 1, + "status_3xx": 1, + "latency_0_to_1ms": 1, + "latency_1_to_5ms": 1, + "latency_5_to_10ms": 1, + "latency_10_to_50ms": 1, + "latency_50_to_100ms": 6, + "waf_responses": 10, + "waf_resp_header_bytes": 1024, + "waf_resp_body_bytes": 64, + "waf_status_2xx": 10, + "waf_status_200": 10, + "waf_latency_5_to_10ms": 5, + "waf_latency_10_to_50ms": 5, + "compute_responses": 10, + "compute_resp_header_bytes": 128, + "compute_resp_body_bytes": 1024, + "compute_status_2xx": 6, + "compute_status_4xx": 4, + "compute_status_200": 6, + "compute_status_403": 4, + "compute_latency_0_to_1ms": 5, + "compute_latency_1_to_5ms": 5 + } + } + } + ] +}` + +var expectedOriginsMetricsOutputMap = map[string]float64{ + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="+Inf"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.001"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.005"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.01"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.05"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.25"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="0.5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="10"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",le="60"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="+Inf"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.001"}`: 2, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.005"}`: 3, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.01"}`: 4, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.05"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.25"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="0.5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="10"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",le="60"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="+Inf"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.001"}`: 0, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.005"}`: 5, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.01"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.05"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.25"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="0.5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="1"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="10"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="5"}`: 10, + `testspace_origin_latency_seconds_bucket{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",le="60"}`: 10, + `testspace_origin_latency_seconds_count{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute"}`: 10, + `testspace_origin_latency_seconds_count{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery"}`: 10, + `testspace_origin_latency_seconds_count{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf"}`: 10, + `testspace_origin_latency_seconds_sum{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute"}`: 0.008, + `testspace_origin_latency_seconds_sum{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery"}`: 0.317, + `testspace_origin_latency_seconds_sum{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf"}`: 0.075, + `testspace_origin_resp_body_bytes_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute"}`: 1152, + `testspace_origin_resp_body_bytes_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery"}`: 1024, + `testspace_origin_resp_body_bytes_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf"}`: 1088, + `testspace_origin_resp_header_bytes_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery"}`: 64, + `testspace_origin_responses_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute"}`: 10, + `testspace_origin_responses_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery"}`: 10, + `testspace_origin_responses_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf"}`: 10, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="200"}`: 6, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="204"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="301"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="302"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="304"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="400"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="401"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="403"}`: 4, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="404"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="416"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="500"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="501"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="502"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="503"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="504"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_code="505"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="200"}`: 9, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="204"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="206"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="301"}`: 1, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="302"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="304"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="400"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="401"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="403"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="404"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="416"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="429"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="500"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="501"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="502"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="503"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="504"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_code="505"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="200"}`: 10, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="204"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="206"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="301"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="302"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="304"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="400"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="401"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="403"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="404"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="416"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="429"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="500"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="501"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="502"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="503"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="504"}`: 0, + `testspace_origin_status_code_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_code="505"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_group="1xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_group="2xx"}`: 6, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_group="3xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_group="4xx"}`: 4, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="compute",status_group="5xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_group="1xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_group="2xx"}`: 9, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_group="3xx"}`: 1, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_group="4xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="delivery",status_group="5xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_group="1xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_group="2xx"}`: 10, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_group="3xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_group="4xx"}`: 0, + `testspace_origin_status_group_total{datacenter="TYO",origin="testorigin",service_id="my-service-id",service_name="my-service-name",source="waf",status_group="5xx"}`: 0, +} + +// +// domain fixtures +// + +const domainsResponseFixture = `{ + "Data": [ + { + "datacenter": { + "TYO": { + "testhost": { + "bandwidth": 1048, + "bereq_body_bytes": 16, + "bereq_header_bytes": 16, + "edge_hit_ratio": 0.5, + "edge_hit_requests": 5, + "edge_miss_requests": 5, + "edge_requests": 10, + "edge_resp_body_bytes": 1024, + "edge_resp_header_bytes": 48, + "origin_fetch_resp_body_bytes": 1024, + "origin_fetch_resp_header_bytes": 48, + "origin_fetches": 5, + "origin_offload": 5, + "origin_status_200": 5, + "origin_status_2xx": 5, + "requests": 10, + "resp_body_bytes": 1024, + "resp_header_bytes": 48, + "status_200": 10, + "status_2xx": 10 + } + } + }, + "aggregated": { + "testorigin": { + "bandwidth": 1048, + "bereq_body_bytes": 16, + "bereq_header_bytes": 16, + "edge_hit_ratio": 0.5, + "edge_hit_requests": 5, + "edge_miss_requests": 5, + "edge_requests": 10, + "edge_resp_body_bytes": 1024, + "edge_resp_header_bytes": 48, + "origin_fetch_resp_body_bytes": 1024, + "origin_fetch_resp_header_bytes": 48, + "origin_fetches": 5, + "origin_offload": 5, + "origin_status_200": 5, + "origin_status_2xx": 5, + "requests": 10, + "resp_body_bytes": 1024, + "resp_header_bytes": 48, + "status_200": 10, + "status_2xx": 10 + } + } + } + ] +}` + +var expectedDomainsMetricsOutputMap = map[string]float64{ + `testspace_domain_bereq_body_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 16, + `testspace_domain_bereq_header_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 16, + `testspace_domain_edge_hit_ratio{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 0.5, + `testspace_domain_edge_hit_requests_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 5, + `testspace_domain_edge_miss_requests_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 5, + `testspace_domain_edge_requests_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 10, + `testspace_domain_edge_resp_body_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 1024, + `testspace_domain_edge_resp_header_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 48, + `testspace_domain_origin_fetch_resp_body_bytes{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 1024, + `testspace_domain_origin_fetch_resp_header_bytes{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 48, + `testspace_domain_origin_fetches{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 5, + `testspace_domain_origin_offload{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 5, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="200"}`: 5, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="204"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="206"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="301"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="302"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="304"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="400"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="401"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="403"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="404"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="416"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="429"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="500"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="501"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="502"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="503"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="504"}`: 0, + `testspace_domain_origin_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="505"}`: 0, + `testspace_domain_origin_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="1xx"}`: 0, + `testspace_domain_origin_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="2xx"}`: 5, + `testspace_domain_origin_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="3xx"}`: 0, + `testspace_domain_origin_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="4xx"}`: 0, + `testspace_domain_origin_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="5xx"}`: 0, + `testspace_domain_requests_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 10, + `testspace_domain_resp_body_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 1024, + `testspace_domain_resp_header_bytes_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name"}`: 48, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="200"}`: 10, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="204"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="206"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="301"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="302"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="304"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="400"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="401"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="403"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="404"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="416"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="429"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="500"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="501"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="502"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="503"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="504"}`: 0, + `testspace_domain_status_code_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_code="505"}`: 0, + `testspace_domain_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="1xx"}`: 0, + `testspace_domain_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="2xx"}`: 10, + `testspace_domain_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="3xx"}`: 0, + `testspace_domain_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="4xx"}`: 0, + `testspace_domain_status_group_total{datacenter="TYO",domain="testhost",service_id="my-service-id",service_name="my-service-name",status_group="5xx"}`: 0, +} diff --git a/pkg/rt/subscriber_test.go b/pkg/rt/subscriber_test.go index e9019c0..c6c0030 100644 --- a/pkg/rt/subscriber_test.go +++ b/pkg/rt/subscriber_test.go @@ -14,7 +14,7 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -func TestSubscriberFixture(t *testing.T) { +func TestRTSubscriberFixture(t *testing.T) { var ( namespace = "testspace" subsystem = "testsystem" @@ -49,7 +49,103 @@ func TestSubscriberFixture(t *testing.T) { // Assert the Prometheus metrics. output := prometheusOutput(t, registry, namespace+"_"+subsystem+"_") - assertMetricOutput(t, expetedMetricsOutputMap, output) + assertMetricOutput(t, expectedRTMetricsOutputMap, output) + + // Kill the subscriber's goroutine, and wait for it to finish. + cancel() + err := <-errc + switch { + case err == nil: + case errors.Is(err, context.Canceled): + case err != nil: + t.Fatal(err) + } +} + +func TestOriginSubscriberFixture(t *testing.T) { + var ( + namespace = "testspace" + subsystem = "testsytem" + registry = prometheus.NewRegistry() + nameFilter = filter.Filter{} + metrics = prom.NewMetrics(namespace, subsystem, nameFilter, registry) + ) + + // Set up a subscriber. + var ( + client = newMockRealtimeClient(originsResponseFixture, `{}`) + serviceID = "my-service-id" + serviceName = "my-service-name" + serviceVersion = 123 + cache = &mockCache{} + processed = make(chan struct{}) + postprocess = func() { close(processed) } + options = []rt.SubscriberOption{rt.WithMetadataProvider(cache), rt.WithPostprocess(postprocess)} + subscriber = rt.NewSubscriber(client, "irrelevant token", serviceID, metrics, options...) + ) + + // Prep the mock cache. + cache.update([]api.Service{{ID: serviceID, Name: serviceName, Version: serviceVersion}}) + + // Tell the subscriber to fetch real-time stats. + ctx, cancel := context.WithCancel(context.Background()) + errc := make(chan error, 1) + go func() { errc <- subscriber.RunOrigins(ctx) }() + + // Block until the subscriber does finishes one fetch + <-processed + + // Assert the Prometheus metrics. + output := prometheusOutput(t, registry, namespace+"_origin_") + assertMetricOutput(t, expectedOriginsMetricsOutputMap, output) + + // Kill the subscriber's goroutine, and wait for it to finish. + cancel() + err := <-errc + switch { + case err == nil: + case errors.Is(err, context.Canceled): + case err != nil: + t.Fatal(err) + } +} + +func TestDomainSubscriberFixture(t *testing.T) { + var ( + namespace = "testspace" + subsystem = "testsytem" + registry = prometheus.NewRegistry() + nameFilter = filter.Filter{} + metrics = prom.NewMetrics(namespace, subsystem, nameFilter, registry) + ) + + // Set up a subscriber. + var ( + client = newMockRealtimeClient(domainsResponseFixture, `{}`) + serviceID = "my-service-id" + serviceName = "my-service-name" + serviceVersion = 123 + cache = &mockCache{} + processed = make(chan struct{}) + postprocess = func() { close(processed) } + options = []rt.SubscriberOption{rt.WithMetadataProvider(cache), rt.WithPostprocess(postprocess)} + subscriber = rt.NewSubscriber(client, "irrelevant token", serviceID, metrics, options...) + ) + + // Prep the mock cache. + cache.update([]api.Service{{ID: serviceID, Name: serviceName, Version: serviceVersion}}) + + // Tell the subscriber to fetch real-time stats. + ctx, cancel := context.WithCancel(context.Background()) + errc := make(chan error, 1) + go func() { errc <- subscriber.RunDomains(ctx) }() + + // Block until the subscriber does finishes one fetch + <-processed + + // Assert the Prometheus metrics. + output := prometheusOutput(t, registry, namespace+"_domain_") + assertMetricOutput(t, expectedDomainsMetricsOutputMap, output) // Kill the subscriber's goroutine, and wait for it to finish. cancel()