Skip to content

Commit

Permalink
compact stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Jan 3, 2025
1 parent 154a8b4 commit 21eb83c
Show file tree
Hide file tree
Showing 11 changed files with 9,715 additions and 54,319 deletions.
30 changes: 19 additions & 11 deletions pkg/ingester/otlp/ingest_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ func TestSymbolizedFunctionNames(t *testing.T) {
h := NewOTLPIngestHandler(svc, logger, false)
_, err := h.Export(context.Background(), req)
assert.NoError(t, err)
require.Equal(t, 1, len(profiles))
assert.Equal(t, 1, len(profiles))

gp := profiles[0].Series[0].Samples[0].Profile.Profile

jsonStr, err := strprofile.Stringify(gp, strprofile.Options{})
require.NoError(t, err)
assert.NoError(t, err)
expectedJSON := readJSONFile(t, "testdata/TestSymbolizedFunctionNames.json")
require.JSONEq(t, expectedJSON, jsonStr)
assert.JSONEq(t, expectedJSON, jsonStr)

os.WriteFile("testdata/TestSymbolizedFunctionNames.json", []byte(jsonStr), 0666)

}

func TestSampleAttributes(t *testing.T) {
Expand Down Expand Up @@ -306,9 +309,10 @@ func TestSampleAttributes(t *testing.T) {
gp := profiles[0].Series[0].Samples[0].Profile.Profile

jsonStr, err := strprofile.Stringify(gp, strprofile.Options{})
require.NoError(t, err)
assert.NoError(t, err)
expectedJSON := readJSONFile(t, "testdata/TestSampleAttributes.json")
require.JSONEq(t, expectedJSON, jsonStr)
assert.Equal(t, expectedJSON, jsonStr)

}

func TestDifferentServiceNames(t *testing.T) {
Expand Down Expand Up @@ -455,16 +459,17 @@ func TestDifferentServiceNames(t *testing.T) {
require.Equal(t, 3, len(profiles))

expectedProfiles := map[string]string{
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"service-a\"}": readJSONFile(t, "testdata/TestDifferentServiceNames_service_a_profile.json"),
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"service-b\"}": readJSONFile(t, "testdata/TestDifferentServiceNames_service_b_profile.json"),
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"unknown\"}": readJSONFile(t, "testdata/TestDifferentServiceNames_unknown_profile.json"),
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"service-a\"}": "testdata/TestDifferentServiceNames_service_a_profile.json",
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"service-b\"}": "testdata/TestDifferentServiceNames_service_b_profile.json",
"{__name__=\"process_cpu\", __delta__=\"false\", __otel__=\"true\", pyroscope_spy=\"unknown\", service_name=\"unknown\"}": "testdata/TestDifferentServiceNames_unknown_profile.json",
}

for _, p := range profiles {
require.Equal(t, 1, len(p.Series))
series := phlaremodel.Labels(p.Series[0].Labels).ToPrometheusLabels().String()
assert.Contains(t, expectedProfiles, series)
expectedJson := expectedProfiles[series]
expectedJsonPath := expectedProfiles[series]
expectedJson := readJSONFile(t, expectedJsonPath)

gp := p.Series[0].Samples[0].Profile.Profile

Expand All @@ -478,9 +483,12 @@ func TestDifferentServiceNames(t *testing.T) {
assert.Equal(t, int64(10000000), gp.Period)

jsonStr, err := strprofile.Stringify(gp, strprofile.Options{})
require.NoError(t, err)
require.JSONEq(t, expectedJson, jsonStr)
assert.NoError(t, err)
assert.JSONEq(t, expectedJson, jsonStr)
assert.NotContains(t, jsonStr, "service.name")

os.WriteFile(expectedJsonPath, []byte(jsonStr), 0666)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,19 @@
{
"address": "0x1100",
"lines": [
{
"function": {
"name": "serviceA_func1",
"system_name": "serviceA_func1",
"filename": "service_a.go"
},
"line": 10
}
"serviceA_func1[serviceA_func1]@service_a.go:10"
],
"mapping": {
"start": "0x1000",
"limit": "0x2000",
"offset": "0x0",
"filename": "service-a.so"
}
"mapping": "0x1000-0x2000@0x0 service-a.so()"
},
{
"address": "0x1200",
"lines": [
{
"function": {
"name": "serviceA_func2",
"system_name": "serviceA_func2",
"filename": "service_a.go"
},
"line": 20
}
"serviceA_func2[serviceA_func2]@service_a.go:20"
],
"mapping": {
"start": "0x1000",
"limit": "0x2000",
"offset": "0x0",
"filename": "service-a.so"
}
"mapping": "0x1000-0x2000@0x0 service-a.so()"
}
],
"values": [
1000000000
]
"values": "1000000000"
}
],
"time_nanos": "239",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,19 @@
{
"address": "0x2100",
"lines": [
{
"function": {
"name": "serviceB_func1",
"system_name": "serviceB_func1",
"filename": "service_b.go"
},
"line": 30
}
"serviceB_func1[serviceB_func1]@service_b.go:30"
],
"mapping": {
"start": "0x2000",
"limit": "0x3000",
"offset": "0x0",
"filename": "service-b.so"
}
"mapping": "0x2000-0x3000@0x0 service-b.so()"
},
{
"address": "0x2200",
"lines": [
{
"function": {
"name": "serviceB_func2",
"system_name": "serviceB_func2",
"filename": "service_b.go"
},
"line": 40
}
"serviceB_func2[serviceB_func2]@service_b.go:40"
],
"mapping": {
"start": "0x2000",
"limit": "0x3000",
"offset": "0x0",
"filename": "service-b.so"
}
"mapping": "0x2000-0x3000@0x0 service-b.so()"
}
],
"values": [
2000000000
]
"values": "2000000000"
}
],
"time_nanos": "239",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,19 @@
{
"address": "0xef0",
"lines": [
{
"function": {
"name": "serviceC_func3",
"system_name": "serviceC_func3",
"filename": "service_c.go"
},
"line": 50
}
"serviceC_func3[serviceC_func3]@service_c.go:50"
],
"mapping": {
"start": "0x4000",
"limit": "0x5000",
"offset": "0x0",
"filename": "service-c.so"
}
"mapping": "0x4000-0x5000@0x0 service-c.so()"
},
{
"address": "0xef0",
"lines": [
{
"function": {
"name": "serviceC_func3",
"system_name": "serviceC_func3",
"filename": "service_c.go"
},
"line": 50
}
"serviceC_func3[serviceC_func3]@service_c.go:50"
],
"mapping": {
"start": "0x4000",
"limit": "0x5000",
"offset": "0x0",
"filename": "service-c.so"
}
"mapping": "0x4000-0x5000@0x0 service-c.so()"
}
],
"values": [
7000000000
]
"values": "7000000000"
}
],
"time_nanos": "239",
Expand Down
74 changes: 12 additions & 62 deletions pkg/ingester/otlp/testdata/TestSampleAttributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,90 +11,40 @@
{
"address": "0x1e",
"lines": [
{
"function": {
"name": "firefox.so 0x1e"
}
}
"firefox.so 0x1e[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "firefox.so"
}
"mapping": "0x1000-0x1000@0x0 firefox.so()"
},
{
"address": "0x2e",
"lines": [
{
"function": {
"name": "firefox.so 0x2e"
}
}
"firefox.so 0x2e[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "firefox.so"
}
"mapping": "0x1000-0x1000@0x0 firefox.so()"
}
],
"values": [
239
],
"labels": [
{
"key": "process",
"value": "firefox"
}
]
"values": "239",
"labels": "process=firefox"
},
{
"locations": [
{
"address": "0x3e",
"lines": [
{
"function": {
"name": "chrome.so 0x3e"
}
}
"chrome.so 0x3e[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "chrome.so"
}
"mapping": "0x1000-0x1000@0x0 chrome.so()"
},
{
"address": "0x4e",
"lines": [
{
"function": {
"name": "chrome.so 0x4e"
}
}
"chrome.so 0x4e[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "chrome.so"
}
"mapping": "0x1000-0x1000@0x0 chrome.so()"
}
],
"values": [
61423
],
"labels": [
{
"key": "process",
"value": "chrome"
}
]
"values": "61423",
"labels": "process=chrome"
}
],
"time_nanos": "239",
Expand Down
34 changes: 7 additions & 27 deletions pkg/ingester/otlp/testdata/TestSymbolizedFunctionNames.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,22 @@
{
"address": "0x1e0",
"lines": [
{
"function": {
"name": "file1.so 0x1e0"
}
}
"file1.so 0x1e0[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "file1.so"
}
"mapping": "0x1000-0x1000@0x0 file1.so()"
},
{
"address": "0x2f0",
"lines": [
{
"function": {
"name": "file1.so 0x2f0"
}
}
"file1.so 0x2f0[]@:0"
],
"mapping": {
"start": "0x1000",
"limit": "0x1000",
"offset": "0x0",
"filename": "file1.so"
}
"mapping": "0x1000-0x1000@0x0 file1.so()"
}
],
"values": [
239
]
"values": "239"
}
],
"time_nanos": "239",
"period": "0",
"duration_nanos": "10000000000"
"duration_nanos": "10000000000",
"period": "0"
}
Loading

0 comments on commit 21eb83c

Please sign in to comment.