Skip to content

Commit 8b89fa2

Browse files
authored
Improve goprofile plugin to support real local IP inclusion (#1281)
This commit addresses the limitation within the logtail profile schema regarding the inability to include the actual local IP address using the goprofile plugin. When profiling, the collection of non-specific host addresses (e.g., 127.0.0.1, localhost, or 0.0.0.0) leads to confusion over multiple target identification. To resolve this, the goprofile plugin has been enhanced to recognize and replace these generic addresses with the real local IP address of the machine. Changes include: Automatic substitution of custom label values that correspond to 127.0.0.1, localhost, or 0.0.0.0 with the machine's actual local IP address.
1 parent 909fb6e commit 8b89fa2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pkg/util/net_helper.go

+7
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,10 @@ func getExternalIP() (string, error) {
8484
}
8585
return "", errors.New("are you connected to the network?")
8686
}
87+
88+
func TryConvertLocalhost2RealIP(ip string) string {
89+
if ip == "localhost" || ip == "127.0.0.1" || ip == "0.0.0.0" {
90+
return GetIPAddress()
91+
}
92+
return ip
93+
}

plugins/input/goprofile/discovery_static.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"net"
2020
"strconv"
2121

22+
"github.com/alibaba/ilogtail/pkg/util"
23+
2224
"github.com/pyroscope-io/pyroscope/pkg/scrape/discovery"
2325
"github.com/pyroscope-io/pyroscope/pkg/scrape/discovery/targetgroup"
2426
"github.com/pyroscope-io/pyroscope/pkg/scrape/model"
@@ -66,9 +68,8 @@ func (k *StaticConfig) convertStaticConfig() (discovery.StaticConfig, error) {
6668
innerLabels := make(model.LabelSet)
6769
innerLabels[model.AddressLabel] = model.LabelValue(addr)
6870
innerLabels[model.AppNameLabel] = appName
69-
7071
for key, val := range address.InstanceLabels {
71-
innerLabels[model.LabelName(key)] = model.LabelValue(val)
72+
innerLabels[model.LabelName(key)] = model.LabelValue(util.TryConvertLocalhost2RealIP(val))
7273
}
7374
cfg = append(cfg, &targetgroup.Group{
7475
Source: addr,

0 commit comments

Comments
 (0)