Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Addressed PR comments
  • Loading branch information
agoallikmaa committed Nov 19, 2021
commit ded8f53c45d106b841ac9411bcc2ad18769d93f2
4 changes: 3 additions & 1 deletion receiver/cloudfoundryreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func TestLoadConfig(t *testing.T) {
require.Len(t, cfg.Receivers, 2)

r0 := cfg.Receivers[config.NewComponentID(typeStr)]
assert.Equal(t, factory.CreateDefaultConfig(), r0)
defaultConfig := factory.CreateDefaultConfig().(*Config)
defaultConfig.UAA.Password = "test"
assert.Equal(t, defaultConfig, r0)

r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "one")].(*Config)
assert.Equal(t,
Expand Down
6 changes: 3 additions & 3 deletions receiver/cloudfoundryreceiver/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func convertEnvelopeToMetrics(envelope *loggregator_v2.Envelope, metricSlice pda

func copyEnvelopeAttributes(attributes pdata.AttributeMap, envelope *loggregator_v2.Envelope) {
for key, value := range envelope.Tags {
attributes.InsertString(attributeNamePrefix + key, value)
attributes.InsertString(attributeNamePrefix+key, value)
}

if envelope.SourceId != "" {
attributes.InsertString(attributeNamePrefix + "source_id", envelope.SourceId)
attributes.InsertString(attributeNamePrefix+"source_id", envelope.SourceId)
}

if envelope.InstanceId != "" {
attributes.InsertString(attributeNamePrefix + "instance_id", envelope.InstanceId)
attributes.InsertString(attributeNamePrefix+"instance_id", envelope.InstanceId)
}
}
44 changes: 22 additions & 22 deletions receiver/cloudfoundryreceiver/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func TestConvertCountEnvelope(t *testing.T) {
assert.Equal(t, 10.0, dataPoint.DoubleVal())

assertAttributes(t, dataPoint.Attributes(), map[string]string{
"source_id": "uaa",
"origin": "gorouter",
"deployment": "cf",
"job": "router",
"index": "bc276108-8282-48a5-bae7-c009c4392246",
"ip": "10.244.0.34",
"org.cloudfoundry.source_id": "uaa",
"org.cloudfoundry.origin": "gorouter",
"org.cloudfoundry.deployment": "cf",
"org.cloudfoundry.job": "router",
"org.cloudfoundry.index": "bc276108-8282-48a5-bae7-c009c4392246",
"org.cloudfoundry.ip": "10.244.0.34",
})
}

Expand Down Expand Up @@ -107,17 +107,17 @@ func TestConvertGaugeEnvelope(t *testing.T) {
},
}

expectedLabels := map[string]string{
"source_id": "5db33854-09a4-4519-ba71-af33a878df6f",
"instance_id": "0",
"origin": "rep",
"deployment": "cf",
"process_type": "web",
"process_id": "5db33854-09a4-4519-ba71-af33a878df6f",
"process_instance_id": "78d4e6d9-ef14-4116-6dc8-9bd7",
"job": "compute",
"index": "7505d2c9-beab-4aaa-afe3-41322ebcd13d",
"ip": "10.0.4.8",
expectedAttributes := map[string]string{
"org.cloudfoundry.source_id": "5db33854-09a4-4519-ba71-af33a878df6f",
"org.cloudfoundry.instance_id": "0",
"org.cloudfoundry.origin": "rep",
"org.cloudfoundry.deployment": "cf",
"org.cloudfoundry.process_type": "web",
"org.cloudfoundry.process_id": "5db33854-09a4-4519-ba71-af33a878df6f",
"org.cloudfoundry.process_instance_id": "78d4e6d9-ef14-4116-6dc8-9bd7",
"org.cloudfoundry.job": "compute",
"org.cloudfoundry.index": "7505d2c9-beab-4aaa-afe3-41322ebcd13d",
"org.cloudfoundry.ip": "10.0.4.8",
}

metricSlice := pdata.NewMetricSlice()
Expand All @@ -139,7 +139,7 @@ func TestConvertGaugeEnvelope(t *testing.T) {
assert.Equal(t, pdata.NewTimestampFromTime(now), dataPoint.Timestamp())
assert.Equal(t, pdata.NewTimestampFromTime(before), dataPoint.StartTimestamp())
assert.Equal(t, 17046641.0, dataPoint.DoubleVal())
assertAttributes(t, dataPoint.Attributes(), expectedLabels)
assertAttributes(t, dataPoint.Attributes(), expectedAttributes)

metric = metricSlice.At(1 - memoryMetricPosition)
assert.Equal(t, "rep.disk", metric.Name())
Expand All @@ -149,14 +149,14 @@ func TestConvertGaugeEnvelope(t *testing.T) {
assert.Equal(t, pdata.NewTimestampFromTime(now), dataPoint.Timestamp())
assert.Equal(t, pdata.NewTimestampFromTime(before), dataPoint.StartTimestamp())
assert.Equal(t, 10231808.0, dataPoint.DoubleVal())
assertAttributes(t, dataPoint.Attributes(), expectedLabels)
assertAttributes(t, dataPoint.Attributes(), expectedAttributes)
}

func assertAttributes(t *testing.T, labels pdata.AttributeMap, expected map[string]string) {
assert.Equal(t, len(expected), labels.Len())
func assertAttributes(t *testing.T, attributes pdata.AttributeMap, expected map[string]string) {
assert.Equal(t, len(expected), attributes.Len())

for key, expectedValue := range expected {
value, present := labels.Get(key)
value, present := attributes.Get(key)
assert.True(t, present, "Attribute %s presence", key)
assert.Equal(t, expectedValue, value.StringVal(), "Attribute %s value", key)
}
Expand Down
2 changes: 2 additions & 0 deletions receiver/cloudfoundryreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
receivers:
cloudfoundry:
uaa:
password: "test"
cloudfoundry/one:
rlp_gateway:
endpoint: "https://log-stream.sys.example.internal"
Expand Down