Skip to content

Commit

Permalink
add dropper provider for application metric
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Jun 14, 2024
1 parent 5b4b59c commit aecc01f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/monitor/collector/bootstrap-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ erda.oap.collector.core:
- "erda.oap.collector.exporter.collector@metrics"
batch_size: ${METRIC_PROMETHEUS_BATCH_SIZE:1024}

- receivers: [ "erda.oap.collector.receiver.collector" ]
processors:
- "erda.oap.collector.processor.dropper@application-agent"
exporters: [ "erda.oap.collector.exporter.collector@metrics" ]

external_metrics:
- receivers:
- "erda.oap.collector.receiver.prometheus-remote-write@external_metrics"
Expand All @@ -46,6 +51,13 @@ erda.oap.collector.core:

erda.oap.collector.receiver.prometheus-remote-write@default:

erda.oap.collector.receiver.collector:
auth:
username: "${COLLECTOR_AUTH_USERNAME:collector}"
password: "${COLLECTOR_AUTH_PASSWORD:G$9767bP32drYFPWrK4XMLRMTatiM6cU}"
force: ${COLLECTOR_AUTH_FORCE:false}
skip: ${COLLECTOR_AUTH_SKIP:false}

erda.oap.collector.receiver.prometheus-remote-write@external_metrics:
remote_write_url: "${EXTERNAL_METRIC_REMOTE_WRITE_URL:/api/v1/external-prometheus-remote-write}"
# ************* receivers *************
Expand Down Expand Up @@ -373,6 +385,9 @@ erda.oap.collector.exporter.collector@external_metrics:
content-encoding: "gzip"
x-erda-cluster-key: ${DICE_CLUSTER_NAME}

erda.oap.collector.processor.dropper@application-agent:
metric_prefix: ${APPLICATION_AGENT_DROP_PREFIX}

# ************* exporters *************

kubernetes:
Expand Down
1 change: 1 addition & 0 deletions internal/tools/monitor/oap/collector/plugins/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

// processors
_ "github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins/processors/aggregator"
_ "github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins/processors/dropper"
_ "github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins/processors/k8s-tagger"
_ "github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins/processors/modifier"
_ "github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins/processors/profile"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dropper

import (
"strings"

"github.com/erda-project/erda-infra/base/logs"
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda/internal/apps/msp/apm/trace"
"github.com/erda-project/erda/internal/tools/monitor/core/log"
"github.com/erda-project/erda/internal/tools/monitor/core/metric"
"github.com/erda-project/erda/internal/tools/monitor/core/profile"
"github.com/erda-project/erda/internal/tools/monitor/oap/collector/core/model"
"github.com/erda-project/erda/internal/tools/monitor/oap/collector/core/model/odata"
"github.com/erda-project/erda/internal/tools/monitor/oap/collector/plugins"
)

var providerName = plugins.WithPrefixProcessor("dropper")

type config struct {
MetricPrefix string `file:"metric_prefix"`
}

type provider struct {
Cfg *config
Log logs.Logger
}

var _ model.Processor = (*provider)(nil)

func (p *provider) ComponentClose() error {
return nil
}

func (p *provider) ComponentConfig() interface{} {
return p.Cfg
}

func (p *provider) ProcessMetric(item *metric.Metric) (*metric.Metric, error) {
if len(p.Cfg.MetricPrefix) > 0 && strings.HasPrefix(item.Name, p.Cfg.MetricPrefix) {
return nil, nil
}
return item, nil
}

func (p *provider) ProcessLog(item *log.Log) (*log.Log, error) { return item, nil }

func (p *provider) ProcessSpan(item *trace.Span) (*trace.Span, error) { return item, nil }

func (p *provider) ProcessRaw(item *odata.Raw) (*odata.Raw, error) { return item, nil }

func (p *provider) ProcessProfile(*profile.ProfileIngest) (*profile.Output, error) {
return &profile.Output{}, nil
}

func (p *provider) Init(ctx servicehub.Context) error {
return nil
}

func init() {
servicehub.Register(providerName, &servicehub.Spec{
Services: []string{
providerName,
},
Description: "help to drop item by prefix name",
ConfigFunc: func() interface{} {
return &config{}
},
Creator: func() servicehub.Provider {
return &provider{}
},
})
}

0 comments on commit aecc01f

Please sign in to comment.