Skip to content

Commit

Permalink
fix http metric make panic when url invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Aug 27, 2024
1 parent 37afd3a commit 86b8561
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
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

0 comments on commit 86b8561

Please sign in to comment.