Skip to content

Commit

Permalink
feat: send display_name label with host's name/fqdn
Browse files Browse the repository at this point in the history
Which is read from "subscription-manager identity" command, attribute
"name".

So that it is easier to identify the metered host by humans.

Signed-off-by: Petr Vobornik <[email protected]>
  • Loading branch information
pvoborni committed Dec 12, 2023
1 parent b28045b commit 4f70bb3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hostinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type HostInfo struct {
CpuCount uint
HostId string
HostName string
ExternalOrganization string
SocketCount string
Product []string
Expand Down Expand Up @@ -58,6 +59,7 @@ func (hi *HostInfo) String() string {
[]string{
"HostInfo:",
fmt.Sprintf("| CpuCount: %d", hi.CpuCount),
fmt.Sprintf("| HostName: %s", hi.HostName),
fmt.Sprintf("| HostId: %s", hi.HostId),
fmt.Sprintf("| ExternalOrganization: %s", hi.ExternalOrganization),
fmt.Sprintf("| SocketCount: %s", hi.SocketCount),
Expand Down
1 change: 1 addition & 0 deletions hostinfo/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestHostInfo(t *testing.T) {
// Define the expected defaults.
expectedString := "HostInfo:\n" +
"| CpuCount: 64\n" +
"| HostName: host.mock.test\n" +
"| HostId: 01234567-89ab-cdef-0123-456789abcdef\n" +
"| ExternalOrganization: 12345678\n" +
"| SocketCount: 3\n" +
Expand Down
5 changes: 5 additions & 0 deletions hostinfo/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func LoadSubManInformation(hi *HostInfo) {
identity := GetSubManIdentity()
hi.HostId, _ = GetHostId(identity)
hi.HostName, _ = GetHostName(identity)
hi.ExternalOrganization, _ = GetExternalOrganization(identity)

hi.Usage, _ = GetUsage()
Expand All @@ -34,6 +35,10 @@ func GetHostId(identity SubManValues) (string, error) {
return identity.get("system identity")
}

func GetHostName(identity SubManValues) (string, error) {
return identity.get("name")
}

func GetExternalOrganization(identity SubManValues) (string, error) {
return identity.get("org ID")
}
Expand Down
1 change: 1 addition & 0 deletions hostinfo/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func TestLoadSubManInformation(t *testing.T) {
// Define the expected general host info.
expected := &HostInfo{
HostId: "01234567-89ab-cdef-0123-456789abcdef",
HostName: "host.mock.test",
ExternalOrganization: "12345678",
SocketCount: "3",
Product: []string{"394", "69"},
Expand Down
2 changes: 1 addition & 1 deletion mocks/subscription-manager
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

IDENTITY=\
"system identity: 01234567-89ab-cdef-0123-456789abcdef
name: hostname
name: host.mock.test
org name: 12345678
org ID: 12345678"

Expand Down
4 changes: 4 additions & 0 deletions notify/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func hostInfo2WriteRequest(hostinfo *hostinfo.HostInfo, samples []prompb.Sample)
Name: "conversions_success",
Value: hostinfo.ConversionsSuccess,
},
{
Name: "display_name",
Value: hostinfo.HostName,
},
{
Name: "external_organization",
Value: hostinfo.ExternalOrganization,
Expand Down
2 changes: 2 additions & 0 deletions notify/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func TestLabels(t *testing.T) {
"billing_marketplace_instance_id",
"billing_model",
"conversions_success",
"display_name",
"external_organization",
"product",
"socket_count",
Expand Down Expand Up @@ -490,6 +491,7 @@ func createHostInfo() *hostinfo.HostInfo {
return &hostinfo.HostInfo{
CpuCount: 1,
HostId: "test",
HostName: testHostname,
SocketCount: "1",
Product: []string{"123", "456"},
Support: "test support",
Expand Down

0 comments on commit 4f70bb3

Please sign in to comment.