Skip to content

Commit

Permalink
Add resource name field to outgoing sg-core metrics
Browse files Browse the repository at this point in the history
Few Ceilometer meters like `cpu` & `network` have 2 name fields
in their metrics, `name` and `display_name`. Use delimiter ":"
to merge the values of both fields such as "cirros:instance-000001".

Need for this change was due to such meters being related to
the same instance so `display_name` would be same both meters.

The `name` field will provide extra information about the actual resource
related to the instance like `cirros:tap3a84e3fc-d9` in `network` meter.

(cherry picked from commit 1235744)
  • Loading branch information
yadneshk committed Aug 29, 2023
1 parent a4ddd8d commit 8bc11a9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 28 deletions.
23 changes: 21 additions & 2 deletions plugins/handler/ceilometer-metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func genName(cNameShards []string) string {
}

func genLabels(m ceilometer.Metric, publisher string, cNameShards []string) ([]string, []string) {
labelKeys := make([]string, 11) // TODO: set to persistent var
labelVals := make([]string, 11)
labelKeys := make([]string, 12) // TODO: set to persistent var
labelVals := make([]string, 12)
plugin := cNameShards[0]
pluginVal := m.ResourceID
if len(cNameShards) > 2 {
Expand Down Expand Up @@ -237,6 +237,25 @@ func genLabels(m ceilometer.Metric, publisher string, cNameShards []string) ([]s
index++
}

if m.ResourceMetadata.DisplayName != "" {
labelKeys[index] = "resource_name"
labelVals[index] = m.ResourceMetadata.DisplayName
// index++
}

if m.ResourceMetadata.Name != "" {
labelKeys[index] = "resource_name"
if labelVals[index] != "" {
// Use the ":" delimiter when DisplayName is not None
labelVals[index] = labelVals[index] + ":" + m.ResourceMetadata.Name
} else {
labelVals[index] = m.ResourceMetadata.Name
}
}
if labelVals[index] != "" {
index++
}

return labelKeys[:index], labelVals[:index]
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/handler/ceilometer-metrics/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var expectedMsgpackMetric = data.Metric{
Type: data.UNTYPED,
Interval: 100 * time.Second,
Value: 0,
LabelKeys: []string{"test_name_0_0_82", "publisher", "type", "counter", "project", "project_name", "user", "user_name", "unit", "resource"},
LabelVals: []string{"test_resource_id", "localhost.localdomain", "test_name_0_0_82", "test_name_0_0_82", "test_project_id_0", "test_project_name_0", "test_user_id", "test_user_name", "test_unit", "test_resource_id"},
LabelKeys: []string{"test_name_0_0_82", "publisher", "type", "counter", "project", "project_name", "user", "user_name", "unit", "resource", "resource_name"},
LabelVals: []string{"test_resource_id", "localhost.localdomain", "test_name_0_0_82", "test_name_0_0_82", "test_project_id_0", "test_project_name_0", "test_user_id", "test_user_name", "test_unit", "test_resource_id", "test_display_name:test_name"},
}

// CeilometerMetricTemplate holds correct parsings for comparing against parsed results
Expand Down
32 changes: 21 additions & 11 deletions plugins/handler/ceilometer-metrics/messages/metric-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"testInput": {
"request": {
"oslo.version": "2.0",
"oslo.message": "{\"message_id\": \"37f64423-db31-4cfb-8c9d-06f9c0fad04a\", \"publisher_id\": \"telemetry.publisher.controller-0.redhat.local\", \"event_type\": \"metering\", \"priority\": \"SAMPLE\", \"payload\": [{\"source\": \"openstack\", \"counter_name\": \"disk.ephemeral.size\", \"counter_type\": \"gauge\", \"counter_unit\": \"GB\", \"counter_volume\": 0, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a54880-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"be55d63bd5d876a62ab52824104128eedfa0619386e8569e326ccef4dcf0d9db\"}, {\"source\": \"openstack\", \"counter_name\": \"disk.root.size\", \"counter_type\": \"gauge\", \"counter_unit\": \"GB\", \"counter_volume\": 1, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a55c80-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"bc0b987d71fe9f0d5d902347f22a0a20b2d975344b4c948572cae4dae553e960\"}, {\"source\": \"openstack\", \"counter_name\": \"compute.instance.booting.time\", \"counter_type\": \"gauge\", \"counter_unit\": \"sec\", \"counter_volume\": 10.839122, \"user_id\": null, \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": null, \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a574d6-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"fd7f1e2fdb34b7beb836d0ead178289f7c36f39bcd68acfd0719848667c58a13\"}, {\"source\": \"openstack\", \"counter_name\": \"vcpus\", \"counter_type\": \"gauge\", \"counter_unit\": \"vcpu\", \"counter_volume\": 2, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a5821e-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"d3f107c2ef6bb1b06e1a9975d1f1ff0bdc51432adff39403db2a1f6a9773b99d\"}, {\"source\": \"openstack\", \"counter_name\": \"memory\", \"counter_type\": \"gauge\", \"counter_unit\": \"MB\", \"counter_volume\": 512, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a591dc-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"9dcf78e3cd43e7fcd66cda5cf33511150e79a086a634bd9d087bb567e4985980\"}], \"timestamp\": \"2020-09-14 16:12:49.954128\"}"
"oslo.message": "{\"message_id\": \"37f64423-db31-4cfb-8c9d-06f9c0fad04a\", \"publisher_id\": \"telemetry.publisher.controller-0.redhat.local\", \"event_type\": \"metering\", \"priority\": \"SAMPLE\", \"payload\": [{\"source\": \"openstack\", \"counter_name\": \"disk.ephemeral.size\", \"counter_type\": \"gauge\", \"counter_unit\": \"GB\", \"counter_volume\": 0, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"name\": \"instance-0000001\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a54880-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"be55d63bd5d876a62ab52824104128eedfa0619386e8569e326ccef4dcf0d9db\"}, {\"source\": \"openstack\", \"counter_name\": \"disk.root.size\", \"counter_type\": \"gauge\", \"counter_unit\": \"GB\", \"counter_volume\": 1, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"name\": \"instance-0000001\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a55c80-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"bc0b987d71fe9f0d5d902347f22a0a20b2d975344b4c948572cae4dae553e960\"}, {\"source\": \"openstack\", \"counter_name\": \"compute.instance.booting.time\", \"counter_type\": \"gauge\", \"counter_unit\": \"sec\", \"counter_volume\": 10.839122, \"user_id\": null, \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": null, \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"name\": \"instance-0000001\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a574d6-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"fd7f1e2fdb34b7beb836d0ead178289f7c36f39bcd68acfd0719848667c58a13\"}, {\"source\": \"openstack\", \"counter_name\": \"vcpus\", \"counter_type\": \"gauge\", \"counter_unit\": \"vcpu\", \"counter_volume\": 2, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"display_name\": \"new-instance\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a5821e-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"d3f107c2ef6bb1b06e1a9975d1f1ff0bdc51432adff39403db2a1f6a9773b99d\"}, {\"source\": \"openstack\", \"counter_name\": \"memory\", \"counter_type\": \"gauge\", \"counter_unit\": \"MB\", \"counter_volume\": 512, \"user_id\": \"3ee72fcd74aa4439bb07fa69f1bc7169\", \"project_id\": \"e56191ef77744c599dbcecae6af176bb\", \"user_name\": \"test_user\", \"project_name\": \"test_project\", \"resource_id\": \"d8bd99b6-6fd8-4c02-a2e3-efbf596df636\", \"timestamp\": \"2020-09-14T16:12:49.939250+00:00\", \"resource_metadata\": {\"host\": \"compute-0.redhat.local\", \"flavor_id\": \"71cd0af1-afd3-4ee4-b918-cec05bf89578\", \"flavor_name\": \"m1.tiny\", \"name\": \"instance-0000001\", \"image_ref\": \"45333e02-643d-4f4f-a817-065060753983\", \"launched_at\": \"2020-09-14T16:12:49.839122\", \"created_at\": \"2020-09-14 16:12:39+00:00\"}, \"message_id\": \"22a591dc-f6a5-11ea-b0f2-525400971e97\", \"monotonic_time\": null, \"message_signature\": \"9dcf78e3cd43e7fcd66cda5cf33511150e79a086a634bd9d087bb567e4985980\"}], \"timestamp\": \"2020-09-14 16:12:49.954128\"}"
},
"context": {}
},
Expand All @@ -22,7 +22,8 @@
"user_name",
"unit",
"resource",
"vm_instance"
"vm_instance",
"resource_name"
],
"LabelVals": [
"size",
Expand All @@ -35,7 +36,8 @@
"test_user",
"GB",
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
"compute-0.redhat.local"
"compute-0.redhat.local",
"new-instance:instance-0000001"
],
"Time": 1600099969,
"Type": 2,
Expand All @@ -55,7 +57,8 @@
"user_name",
"unit",
"resource",
"vm_instance"
"vm_instance",
"resource_name"
],
"LabelVals": [
"size",
Expand All @@ -68,7 +71,8 @@
"test_user",
"GB",
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
"compute-0.redhat.local"
"compute-0.redhat.local",
"new-instance:instance-0000001"
],
"Time": 1600099969,
"Type": 2,
Expand All @@ -86,7 +90,8 @@
"project_name",
"unit",
"resource",
"vm_instance"
"vm_instance",
"resource_name"
],
"LabelVals": [
"booting",
Expand All @@ -97,7 +102,8 @@
"test_project",
"sec",
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
"compute-0.redhat.local"
"compute-0.redhat.local",
"new-instance:instance-0000001"
],
"Time": 1600099969,
"Type": 2,
Expand All @@ -117,7 +123,8 @@
"user_name",
"unit",
"resource",
"vm_instance"
"vm_instance",
"resource_name"
],
"LabelVals": [
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
Expand All @@ -130,7 +137,8 @@
"test_user",
"vcpu",
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
"compute-0.redhat.local"
"compute-0.redhat.local",
"new-instance"
],
"Time": 1600099969,
"Type": 2,
Expand All @@ -150,7 +158,8 @@
"user_name",
"unit",
"resource",
"vm_instance"
"vm_instance",
"resource_name"
],
"LabelVals": [
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
Expand All @@ -163,7 +172,8 @@
"test_user",
"MB",
"d8bd99b6-6fd8-4c02-a2e3-efbf596df636",
"compute-0.redhat.local"
"compute-0.redhat.local",
"instance-0000001"
],
"Time": 1600099969,
"Type": 2,
Expand Down
Binary file modified plugins/handler/ceilometer-metrics/messages/msgpack-test.msgpack
Binary file not shown.
29 changes: 16 additions & 13 deletions plugins/handler/ceilometer-metrics/pkg/ceilometer/ceilometer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ var (

// Metedata represents metadataof a metric from ceilometer
type Metadata struct {
Host string
Host string `json:"host" msgpack:"host"`
Name string `json:"name" msgpack:"name"`
DisplayName string `json:"display_name" msgpack:"display_name"`
InstanceHost string `json:"instance_host" msgpack:"instance_host"`
}

// Metric represents a single metric from ceilometer for unmarshalling
type Metric struct {
Source string
CounterName string `json:"counter_name" msgpack:"counter_name"`
CounterType string `json:"counter_type" msgpack:"counter_type"`
CounterUnit string `json:"counter_unit" msgpack:"counter_unit"`
CounterVolume float64 `json:"counter_volume" msgpack:"counter_volume"`
UserID string `json:"user_id" msgpack:"user_id"`
UserName string `json:"user_name" msgpack:"user_name"`
ProjectID string `json:"project_id" msgpack:"project_id"`
ProjectName string `json:"project_name" msgpack:"project_name"`
ResourceID string `json:"resource_id" msgpack:"resource_id"`
Timestamp string
ResourceMetadata Metadata `json:"resource_metadata"`
Source string `json:"source" msgpack:"source"`
CounterName string `json:"counter_name" msgpack:"counter_name"`
CounterType string `json:"counter_type" msgpack:"counter_type"`
CounterUnit string `json:"counter_unit" msgpack:"counter_unit"`
CounterVolume float64 `json:"counter_volume" msgpack:"counter_volume"`
UserID string `json:"user_id" msgpack:"user_id"`
UserName string `json:"user_name" msgpack:"user_name"`
ProjectID string `json:"project_id" msgpack:"project_id"`
ProjectName string `json:"project_name" msgpack:"project_name"`
ResourceID string `json:"resource_id" msgpack:"resource_id"`
Timestamp string `json:"timestamp" msgpack:"timestamp"`
ResourceMetadata Metadata `json:"resource_metadata" msgpack:"resource_metadata"`
}

// Message struct represents an incoming ceilometer metrics message
Expand Down

0 comments on commit 8bc11a9

Please sign in to comment.