|
1 | 1 | package instances |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
4 | 5 | "testing" |
5 | 6 | "time" |
6 | 7 |
|
@@ -113,6 +114,59 @@ func TestSnapshotCompressionMetrics_RecordAndObserve(t *testing.T) { |
113 | 114 | assert.Equal(t, "standby", metricLabel(t, active.DataPoints[0].Attributes, "source")) |
114 | 115 | } |
115 | 116 |
|
| 117 | +func TestEnsureSnapshotMemoryReadyRecordsProvidedPreemptionOperation(t *testing.T) { |
| 118 | + t.Parallel() |
| 119 | + |
| 120 | + reader := otelmetric.NewManualReader() |
| 121 | + provider := otelmetric.NewMeterProvider(otelmetric.WithReader(reader)) |
| 122 | + |
| 123 | + rawDir := t.TempDir() |
| 124 | + rawPath := rawDir + "/memory-ranges" |
| 125 | + require.NoError(t, os.WriteFile(rawPath, []byte("raw snapshot"), 0644)) |
| 126 | + |
| 127 | + jobDone := make(chan struct{}) |
| 128 | + m := &manager{ |
| 129 | + paths: paths.New(t.TempDir()), |
| 130 | + compressionJobs: map[string]*compressionJob{ |
| 131 | + "job-1": { |
| 132 | + done: jobDone, |
| 133 | + target: compressionTarget{ |
| 134 | + Key: "job-1", |
| 135 | + HypervisorType: hypervisor.TypeCloudHypervisor, |
| 136 | + Source: snapshotCompressionSourceStandby, |
| 137 | + Policy: snapshotstore.SnapshotCompressionConfig{ |
| 138 | + Enabled: true, |
| 139 | + Algorithm: snapshotstore.SnapshotCompressionAlgorithmLz4, |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + } |
| 145 | + m.compressionJobs["job-1"].cancel = func() { |
| 146 | + select { |
| 147 | + case <-jobDone: |
| 148 | + default: |
| 149 | + close(jobDone) |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + metrics, err := newInstanceMetrics(provider.Meter("test"), nil, m) |
| 154 | + require.NoError(t, err) |
| 155 | + m.metrics = metrics |
| 156 | + |
| 157 | + err = m.ensureSnapshotMemoryReady(t.Context(), rawDir, "job-1", hypervisor.TypeCloudHypervisor, snapshotCompressionPreemptionForkInstance) |
| 158 | + require.NoError(t, err) |
| 159 | + |
| 160 | + var rm metricdata.ResourceMetrics |
| 161 | + require.NoError(t, reader.Collect(t.Context(), &rm)) |
| 162 | + |
| 163 | + preemptionsMetric := findMetric(t, rm, "hypeman_snapshot_compression_preemptions_total") |
| 164 | + preemptions, ok := preemptionsMetric.Data.(metricdata.Sum[int64]) |
| 165 | + require.True(t, ok) |
| 166 | + require.Len(t, preemptions.DataPoints, 1) |
| 167 | + assert.Equal(t, "fork_instance", metricLabel(t, preemptions.DataPoints[0].Attributes, "operation")) |
| 168 | +} |
| 169 | + |
116 | 170 | func assertMetricNames(t *testing.T, rm metricdata.ResourceMetrics, expected []string) { |
117 | 171 | t.Helper() |
118 | 172 |
|
|
0 commit comments