Skip to content

Commit 0b5cf39

Browse files
committed
tests
1 parent 1560db4 commit 0b5cf39

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

receiver/postgresqlreceiver/scraper_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
_ "embed"
1010
"errors"
1111
"fmt"
12+
"os"
1213
"path/filepath"
1314
"testing"
1415
"time"
@@ -866,3 +867,31 @@ func (m *mockClient) initMocks(database, schema string, databases []string, inde
866867
m.On("getFunctionStats", mock.Anything, database).Return(functionStats, nil)
867868
}
868869
}
870+
871+
func TestGetInstanceId(t *testing.T) {
872+
localhostName, _ := os.Hostname()
873+
874+
instanceString := "example.com:5432"
875+
instanceID := getInstanceID(instanceString, zap.NewNop())
876+
assert.Equal(t, "example.com:5432", instanceID)
877+
878+
localHostStringUppercase := "Localhost:5432"
879+
localInstanceID := getInstanceID(localHostStringUppercase, zap.NewNop())
880+
assert.NotNil(t, localInstanceID)
881+
assert.Equal(t, localhostName+":5432", localInstanceID)
882+
883+
localHostString := "127.0.0.1:5432"
884+
localInstanceID = getInstanceID(localHostString, zap.NewNop())
885+
assert.NotNil(t, localInstanceID)
886+
assert.Equal(t, localhostName+":5432", localInstanceID)
887+
888+
localHostStringIPV6 := "[::1]:5432"
889+
localInstanceID = getInstanceID(localHostStringIPV6, zap.NewNop())
890+
assert.NotNil(t, localInstanceID)
891+
assert.Equal(t, localhostName+":5432", localInstanceID)
892+
893+
hostNameErrorSample := ""
894+
localInstanceID = getInstanceID(hostNameErrorSample, zap.NewNop())
895+
assert.NotNil(t, localInstanceID)
896+
assert.Equal(t, "unknown:5432", localInstanceID)
897+
}

receiver/postgresqlreceiver/testdata/scraper/multiple/expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ resourceMetrics:
474474
attributes:
475475
- key: service.instance.id
476476
value:
477-
stringValue: INSTANCE-NAME:5432
477+
stringValue: SAMBALAM-M-P4X5:5432
478478
scopeMetrics:
479479
- metrics:
480480
- description: Number of buffers allocated.

receiver/postgresqlreceiver/testdata/scraper/multiple/expected_imprecise_lag.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ resourceMetrics:
474474
attributes:
475475
- key: service.instance.id
476476
value:
477-
stringValue: INSTANCE-NAME:5432
477+
stringValue: SAMBALAM-M-P4X5:5432
478478
scopeMetrics:
479479
- metrics:
480480
- description: Number of buffers allocated.

receiver/postgresqlreceiver/testdata/scraper/multiple/expected_imprecise_lag_schemaattr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ resourceMetrics:
474474
attributes:
475475
- key: service.instance.id
476476
value:
477-
stringValue: INSTANCE-NAME:5432
477+
stringValue: SAMBALAM-M-P4X5:5432
478478
scopeMetrics:
479479
- metrics:
480480
- description: Number of buffers allocated.

receiver/postgresqlreceiver/testdata/scraper/multiple/expected_schemaattr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ resourceMetrics:
474474
attributes:
475475
- key: service.instance.id
476476
value:
477-
stringValue: INSTANCE-NAME:5432
477+
stringValue: SAMBALAM-M-P4X5:5432
478478
scopeMetrics:
479479
- metrics:
480480
- description: Number of buffers allocated.

0 commit comments

Comments
 (0)