refactor: update cm proto parser#4293
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the cmmetrics protobuf parsing to handle an envelope-style “metrics file record” format (version/schema/batch/summary) instead of returning only ObjectCollection, and updates tests/fixtures accordingly.
Changes:
- Added
MetricsFileRecordparsing, includingMetricsFileVersion,CollectionStatus, andStatusCodedecoding. - Updated
Messagesto yield*MetricsFileRecordrecords from the metrics file stream. - Adjusted
CounterSchemaparsing forbase_counter_indexfield number and refreshedTestMessagesto validate the new fixture (testdata/wqd.pb).
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| cmd/collectors/cmperf/cmmetrics/metrics.go | Introduces envelope record types and parsing handlers; updates Messages/readProto; tweaks counter schema field mapping. |
| cmd/collectors/cmperf/cmmetrics/metrics_test.go | Updates message parsing test to the new record structure and fixture; adds mustList64; removes prior malformed-nested-message regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| batch *ObjectCollection | ||
| summary *CollectionStatus | ||
| } | ||
|
|
| code StatusCodeEnum | ||
| nodes []string | ||
| } | ||
|
|
| return statusCode, errors.New("failed to read statusCode code value") | ||
| } | ||
| if value > math.MaxUint8 { | ||
| return statusCode, fmt.Errorf("status code exceeds uint8 %d ", value) |
| var err error | ||
| data, err = fc.NextField(data) | ||
| if err != nil { | ||
| return collectionStatus, errors.New("failed to read CollectionStatus data") |
| var err error | ||
| data, err = fc.NextField(data) | ||
| if err != nil { | ||
| return fileVersion, errors.New("failed to read metricsFileVersion data") |
Comment on lines
78
to
+89
| func TestMessages(t *testing.T) { | ||
|
|
||
| path := "testdata/test1.pb" | ||
| obs := make([]*ObjectCollection, 0, 2) | ||
| path := "testdata/wqd.pb" | ||
| obs := make([]*MetricsFileRecord, 0, 5) | ||
|
|
||
| for aMsg, err := range Messages(path) { | ||
| assert.Nil(t, err) | ||
| assert.NotNil(t, aMsg) | ||
| obs = append(obs, aMsg) | ||
| } | ||
|
|
||
| assert.Equal(t, len(obs), 2) | ||
|
|
||
| assert.Equal(t, obs[0].Timestamp, uint64(1776429464001)) | ||
| assert.Equal(t, obs[0].Period, uint32(60)) | ||
| assert.Equal(t, obs[0].Node, "cm-test") | ||
| assert.Equal(t, obs[0].Schema.Name, "cm-test") | ||
| assert.Equal(t, len(obs[0].Schema.CounterSchema), 2) | ||
| assert.Equal(t, obs[0].Schema.CounterSchema[0].Name, "counter-1") | ||
| assert.Equal(t, obs[0].Schema.CounterSchema[0].Index, uint32(1)) | ||
| assert.Equal(t, obs[0].Schema.CounterSchema[0].Type, CookString) | ||
| assert.Equal(t, obs[0].Schema.CounterSchema[0].DimX, uint32(0)) | ||
| assert.Equal(t, obs[0].Schema.CounterSchema[0].DimY, uint32(0)) | ||
| assert.Equal(t, len(obs[0].Schema.CounterSchema[0].LabelsX), 0) | ||
| assert.Equal(t, len(obs[0].Schema.CounterSchema[0].LabelsY), 0) | ||
|
|
||
| assert.Equal(t, obs[0].Data.Name, "od-1") | ||
| assert.Equal(t, len(obs[0].Data.Instances), 2) | ||
| assert.Equal(t, obs[0].Data.Instances[0].Name, "vol1") | ||
| assert.Equal(t, obs[0].Data.Instances[0].UUID, "06b3c803-ff78-11eb-ba17-00a098e24321") | ||
| assert.Equal(t, len(obs[0].Data.Instances[0].Counters), 4) | ||
| assert.Equal(t, obs[0].Data.Instances[0].Counters[0].Index, uint32(1)) | ||
| assert.Equal(t, mustUint64Value(t, obs[0].Data.Instances[0].Counters[0]), 42) | ||
| assert.False(t, obs[0].Data.Instances[0].Counters[0].IsUint32()) | ||
| assert.True(t, obs[0].Data.Instances[0].Counters[0].IsUint64()) | ||
| assert.False(t, obs[0].Data.Instances[0].Counters[0].IsList32()) | ||
| assert.False(t, obs[0].Data.Instances[0].Counters[0].IsList64()) | ||
| assert.False(t, obs[0].Data.Instances[0].Counters[0].IsListString()) | ||
|
|
||
| assert.Equal(t, obs[0].Data.Instances[1].Counters[3].Index, 4) | ||
| assert.Equal(t, obs[0].Data.Instances[1].Counters[2].scalar, 144) | ||
|
|
||
| listString, b := obs[1].Data.Instances[0].Counters[3].ListString() | ||
| assert.True(t, b) | ||
| assert.Equal(t, listString, []string{"abc", "def", "ghi"}) | ||
| assert.Equal(t, mustList32(t, obs[1].Data.Instances[0].Counters[4]), []uint32{100, 200, 300}) | ||
|
|
||
| assert.Equal(t, obs[1].Schema.CounterSchema[0].LabelsX, []string{"opcode 1", "opcode 2"}) | ||
| assert.Equal(t, obs[1].Schema.CounterSchema[1].Name, "ops") | ||
| assert.Equal(t, obs[1].Schema.CounterSchema[2].Name, "latency") | ||
| assert.Equal(t, obs[1].Schema.CounterSchema[2].BaseIndex, 1) | ||
| assert.Equal(t, obs[1].Schema.CounterSchema[2].Type, CookAverage) | ||
| assert.Equal(t, len(obs), 5) |
rahulguptajss
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.