Skip to content

Commit

Permalink
Add unit/e2e tests for NVMe log page metrics
Browse files Browse the repository at this point in the history
Signed-off-by: torredil <torredil@amazon.com>
  • Loading branch information
torredil committed Nov 7, 2024
1 parent 248c13c commit 5927a72
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ e2e/single-az: bin/helm bin/ginkgo
TEST_PATH=./tests/e2e/... \
GINKGO_FOCUS="\[ebs-csi-e2e\] \[single-az\]" \
GINKGO_PARALLEL=5 \
HELM_EXTRA_FLAGS="--set=controller.volumeModificationFeature.enabled=true,sidecars.provisioner.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true',sidecars.resizer.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true'" \
HELM_EXTRA_FLAGS="--set=controller.volumeModificationFeature.enabled=true,sidecars.provisioner.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true',sidecars.resizer.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true',node.enableMetrics=true" \
./hack/e2e/run.sh

.PHONY: e2e/multi-az
Expand Down
4 changes: 4 additions & 0 deletions pkg/driver/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func TestAddFlags(t *testing.T) {
t.Errorf("error setting legacy-xfs: %v", err)
}

if err := f.Set("csi-mount-point-prefix", "/var/lib/kubelet"); err != nil {
t.Errorf("error setting csi-mount-point-prefix: %v", err)
}

if o.Endpoint != "custom-endpoint" {
t.Errorf("unexpected Endpoint: got %s, want custom-endpoint", o.Endpoint)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestMetricRecorder(t *testing.T) {
m.IncreaseCount("test_total", map[string]string{"key": "value"})
},
expected: `
# HELP test_total [ALPHA] ebs_csi_aws_com metric
# HELP test_total ebs_csi_aws_com metric
# TYPE test_total counter
test_total{key="value"} 1
`,
Expand All @@ -46,7 +46,7 @@ test_total{key="value"} 1
m.ObserveHistogram("test", 1.5, map[string]string{"key": "value"}, []float64{1, 2, 3})
},
expected: `
# HELP test [ALPHA] ebs_csi_aws_com metric
# HELP test ebs_csi_aws_com metric
# TYPE test histogram
test{key="value",le="1"} 0
test{key="value",le="2"} 1
Expand All @@ -66,7 +66,7 @@ test_count{key="value"} 1
m.IncreaseCount("test_re_register_total", map[string]string{"key": "value2"})
},
expected: `
# HELP test_re_register_total [ALPHA] ebs_csi_aws_com metric
# HELP test_re_register_total ebs_csi_aws_com metric
# TYPE test_re_register_total counter
test_re_register_total{key="value1"} 2
test_re_register_total{key="value2"} 1
Expand Down
9 changes: 7 additions & 2 deletions pkg/metrics/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ type NVMECollector struct {
scrapeErrorsTotal prometheus.Counter
}

var (
ErrInvalidEBSMagic = errors.New("invalid EBS magic number")
ErrParseLogPage = errors.New("failed to parse log page")
)

// NewNVMECollector creates a new instance of NVMECollector.
func NewNVMECollector(path, instanceID string) *NVMECollector {
variableLabels := []string{"volume_id"}
Expand Down Expand Up @@ -295,11 +300,11 @@ func parseLogPage(data []byte) (EBSMetrics, error) {
reader := bytes.NewReader(data)

if err := binary.Read(reader, binary.LittleEndian, &metrics); err != nil {
return EBSMetrics{}, fmt.Errorf("failed to parse log page: %w", err)
return EBSMetrics{}, fmt.Errorf("%w: %w", ErrParseLogPage, err)
}

if metrics.EBSMagic != 0x3C23B510 {
return EBSMetrics{}, fmt.Errorf("invalid EBS magic number: %x", metrics.EBSMagic)
return EBSMetrics{}, fmt.Errorf("%w: %x", ErrInvalidEBSMagic, metrics.EBSMagic)
}

return metrics, nil
Expand Down
Loading

0 comments on commit 5927a72

Please sign in to comment.