processors

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProcessor

func RegisterProcessor(typ string, creator func(metric string, cfg []byte) (Processor, error))

RegisterProcessor .

Types

type Processor

type Processor interface {
	Process(content string) (string, map[string]interface{}, error)
	Keys() []*pb.FieldDefine
}

Processor .

func NewProcessor

func NewProcessor(name, typ string, cfg []byte) (Processor, error)

NewProcessor .

type Processors

type Processors struct {
	// contains filtered or unexported fields
}

Processors .

Example
package main

import (
	"encoding/json"
	"fmt"

	"github.com/erda-project/erda-proto-go/core/monitor/metric/pb"
	"github.com/erda-project/erda/modules/extensions/loghub/metrics/analysis/processors"

	_ "github.com/erda-project/erda/modules/extensions/loghub/metrics/analysis/processors/regex"
)

func main() {
	var (
		scopeID string = "terminus"
		tags           = map[string]string{
			"dice_org_id":         "1",
			"dice_application_id": "2",
			"dice_service_name":   "abc",
		}
		metricName = "test_metric"
	)
	cfg, _ := json.Marshal(map[string]interface{}{
		"pattern": "(d+)",
		"keys": []*pb.FieldDefine{
			{
				Key:  "ip",
				Type: "string",
			},
		},
	})
	ps := processors.New()
	err := ps.Add(scopeID, tags, metricName, "regexp", cfg)
	if err != nil {
		fmt.Println(err)
		return
	}
	list := ps.Find("", scopeID, map[string]string{
		"dice_org_id":         "1",
		"dice_application_id": "2",
	})
	if len(list) != 0 {
		fmt.Println("Find error")
		return
	}
	list = ps.Find("", scopeID, map[string]string{
		"dice_org_id":         "1",
		"dice_application_id": "3",
		"dice_service_name":   "abc",
	})
	if len(list) != 0 {
		fmt.Println("Find error")
		return
	}
	list = ps.Find("", scopeID, map[string]string{
		"dice_org_id":         "1",
		"dice_application_id": "2",
		"dice_service_name":   "abc",
	})
	if len(list) <= 0 {
		fmt.Println("Find error")
		return
	}
	fmt.Printf("Find %d\n", len(list))

}
Output:

Find 1

func New

func New() *Processors

New .

func (*Processors) Add

func (ps *Processors) Add(key string, tags map[string]string, name, typ string, config []byte) error

Add .

func (*Processors) Find

func (ps *Processors) Find(name, key string, tags map[string]string) []Processor

Find .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL