Skip to content
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

fix: http metric make panic when url invalid #11

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions pkg/plugins/protocols/http/ebpf/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ func (e *provider) FanInMetric(m *ebpf.Map) {
)
for {
for m.Iterate().Next(&key, &val) {
metric, err := DecodeMetrics(&key, &val)
if err != nil {
klog.Errorf("decode metrics error: %v", err)
}
e.ch <- *metric
// clean map
if err := m.Delete(key); err != nil {
klog.Errorf("delete map error: %v", err)
continue
}
metric, err := DecodeMetrics(&key, &val)
if err != nil {
klog.Errorf("decode metrics error: %v", err)
continue
}
e.ch <- *metric
}
time.Sleep(1 * time.Second)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/protocols/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *provider) Gather(c chan *metric.Metric) {
//p.Log.Infof("recive metric: %+v", m.String())
export := p.meta.Convert(&m)
if export != nil {
p.Log.Infof("recive metric: %+v", export.String())
p.Log.Debugf("recive metric: %+v", export.String())
c <- export
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/plugins/protocols/http/meta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"strconv"
"time"

"github.com/erda-project/erda-infra/base/logs"
corev1 "k8s.io/api/core/v1"

"github.com/erda-project/ebpf-agent/metric"
"github.com/erda-project/ebpf-agent/pkg/plugins/kprobe"
"github.com/erda-project/ebpf-agent/pkg/plugins/netfilter"
"github.com/erda-project/ebpf-agent/pkg/plugins/protocols/http/ebpf"
"github.com/erda-project/erda-infra/base/logs"
)

const (
Expand Down Expand Up @@ -39,7 +39,7 @@ func New(l logs.Logger, k kprobe.Interface, n netfilter.Interface) Interface {
}

func (p *provider) Convert(m *ebpf.Metric) *metric.Metric {
p.l.Infof("gonna to convert metrics: %+v", m)
p.l.Debugf("gonna to convert metrics: %+v", m)
measurement := measurementGroup
output := &metric.Metric{
Timestamp: time.Now().UnixNano(),
Expand All @@ -65,7 +65,7 @@ func (p *provider) Convert(m *ebpf.Metric) *metric.Metric {
"elapsed_mean": m.Duration,
},
}
p.l.Infof("ebpf metrics: %s", m.String())
p.l.Debugf("ebpf metrics: %s", m.String())

if m.StatusCode >= 400 {
measurement = measurementGroupError
Expand Down Expand Up @@ -119,14 +119,14 @@ func (p *provider) Convert(m *ebpf.Metric) *metric.Metric {

// external target
if target == nil {
p.l.Infof("source: %s/%d, target(external): %s", m.SourceIP, m.SourcePort, m.DestIP)
p.l.Debugf("source: %s/%d, target(external): %s", m.SourceIP, m.SourcePort, m.DestIP)
return nil
}

// in cluster
switch t := target.(type) {
case *corev1.Pod:
p.l.Infof("source(pod): %s/%d, target(pod): %s/%s", m.SourceIP, m.SourcePort, t.Namespace, t.Name)
p.l.Debugf("source(pod): %s/%d, target(pod): %s/%s", m.SourceIP, m.SourcePort, t.Namespace, t.Name)
output.Tags["cluster_name"] = t.Labels["DICE_CLUSTER_NAME"]
output.Tags["db_host"] = fmt.Sprintf("%s:%d", m.DestIP, m.DestPort)
output.Tags["org_name"] = t.Labels["DICE_ORG_NAME"]
Expand Down Expand Up @@ -155,7 +155,7 @@ func (p *provider) Convert(m *ebpf.Metric) *metric.Metric {
output.Tags["target_workspace"] = t.Annotations["msp.erda.cloud/workspace"]
case *corev1.Service:
// TODO: service resource
p.l.Infof("source(pod): %s/%d, target(service): %s/%s", m.SourceIP, m.SourcePort, t.Namespace, t.Name)
p.l.Debugf("source(pod): %s/%d, target(service): %s/%s", m.SourceIP, m.SourcePort, t.Namespace, t.Name)
default:
p.l.Errorf("unknown target type: %T", target)
}
Expand Down
Loading