Skip to content

refactor: update cm proto parser#4293

Merged
rahulguptajss merged 2 commits into
mainfrom
cbg-cm-proto
May 20, 2026
Merged

refactor: update cm proto parser#4293
rahulguptajss merged 2 commits into
mainfrom
cbg-cm-proto

Conversation

@cgrinds
Copy link
Copy Markdown
Collaborator

@cgrinds cgrinds commented May 19, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 19, 2026 22:51
@cla-bot cla-bot Bot added the cla-signed label May 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MetricsFileRecord parsing, including MetricsFileVersion, CollectionStatus, and StatusCode decoding.
  • Updated Messages to yield *MetricsFileRecord records from the metrics file stream.
  • Adjusted CounterSchema parsing for base_counter_index field number and refreshed TestMessages to 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 rahulguptajss merged commit 92ed9da into main May 20, 2026
13 checks passed
@rahulguptajss rahulguptajss deleted the cbg-cm-proto branch May 20, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants