Skip to content

Improve goprofile plugin to support real local IP inclusion #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 7 additions & 0 deletions pkg/util/net_helper.go
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否说明为什么要做这些转换?用途是什么

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sidecar 模式设置采集本地地址,倒是采集上来的profile 数据都是127.0.0.1 追加一个本地真实ip 标签

Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ func getExternalIP() (string, error) {
}
return "", errors.New("are you connected to the network?")
}

func TryConvertLocalhost2RealIP(ip string) string {
if ip == "localhost" || ip == "127.0.0.1" || ip == "0.0.0.0" {
return GetIPAddress()
}
return ip
}
4 changes: 3 additions & 1 deletion plugins/input/goprofile/discovery_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"net"
"strconv"

"github.com/alibaba/ilogtail/pkg/util"

"github.com/pyroscope-io/pyroscope/pkg/scrape/discovery"
"github.com/pyroscope-io/pyroscope/pkg/scrape/discovery/targetgroup"
"github.com/pyroscope-io/pyroscope/pkg/scrape/model"
Expand Down Expand Up @@ -62,7 +64,7 @@ func (k *StaticConfig) convertStaticConfig() (discovery.StaticConfig, error) {
} else {
return nil, errors.New("not found required service labels")
}
addr := net.JoinHostPort(address.Host, strconv.Itoa(int(address.Port)))
addr := net.JoinHostPort(util.TryConvertLocalhost2RealIP(address.Host), strconv.Itoa(int(address.Port)))
innerLabels := make(model.LabelSet)
innerLabels[model.AddressLabel] = model.LabelValue(addr)
innerLabels[model.AppNameLabel] = appName
Expand Down
3 changes: 2 additions & 1 deletion plugins/input/jmxfetch/jmxfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/alibaba/ilogtail/pkg/helper"
"github.com/alibaba/ilogtail/pkg/logger"
"github.com/alibaba/ilogtail/pkg/pipeline"
"github.com/alibaba/ilogtail/pkg/util"
)

type Instance struct {
Expand Down Expand Up @@ -158,7 +159,7 @@ func (m *Jmx) Start(collector pipeline.Collector) error {
for k, v := range m.Tags {
m.StaticInstances[i].Tags[k] = v
}
inner := NewInstanceInner(m.StaticInstances[i].Port, m.StaticInstances[i].Host, m.StaticInstances[i].User,
inner := NewInstanceInner(m.StaticInstances[i].Port, util.TryConvertLocalhost2RealIP(m.StaticInstances[i].Host), m.StaticInstances[i].User,
m.StaticInstances[i].Password, m.StaticInstances[i].Tags, m.DefaultJvmMetrics)
m.instances[inner.Hash()] = inner
}
Expand Down