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

Make config object public for graphite and http server #4820

Merged
merged 1 commit into from
Aug 3, 2017
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
3 changes: 2 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
- Add support to exclude labels from kubernetes pod metadata. {pull}4757[4757]
- Add graphite protocol metricbeat module. {pull}4734[4734]
- Add http server metricset to support push metrics via http. {pull}4770[4770]

- Make config object public for graphite and http server {pull}4820[4820]

*Packetbeat*

*Winlogbeat*
Expand Down
18 changes: 9 additions & 9 deletions metricbeat/module/graphite/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ const (
defaultDelimiter = "."
)

type graphiteCollectorConfig struct {
type GraphiteServerConfig struct {
Protocol string `config:"protocol"`
Templates []templateConfig `config:"templates"`
DefaultTemplate templateConfig `config:"default_template"`
Templates []TemplateConfig `config:"templates"`
DefaultTemplate TemplateConfig `config:"default_template"`
}

type templateConfig struct {
type TemplateConfig struct {
Filter string `config:"filter"`
Template string `config:"template"`
Namespace string `config:"namespace"`
Delimiter string `config:"delimiter"`
Tags map[string]string `config:"tags"`
}

func defaultGraphiteCollectorConfig() graphiteCollectorConfig {
return graphiteCollectorConfig{
func DefaultGraphiteCollectorConfig() GraphiteServerConfig {
return GraphiteServerConfig{
Protocol: "udp",
DefaultTemplate: templateConfig{
DefaultTemplate: TemplateConfig{
Filter: "*",
Template: "metric*",
Namespace: "graphite",
Expand All @@ -34,14 +34,14 @@ func defaultGraphiteCollectorConfig() graphiteCollectorConfig {
}
}

func (c graphiteCollectorConfig) Validate() error {
func (c GraphiteServerConfig) Validate() error {
if c.Protocol != "tcp" && c.Protocol != "udp" {
return errors.New("`protocol` can only be tcp or udp")
}
return nil
}

func (t *templateConfig) Validate() error {
func (t *TemplateConfig) Validate() error {
if t.Namespace == "" {
return errors.New("`namespace` can not be empty in template configuration")
}
Expand Down
8 changes: 4 additions & 4 deletions metricbeat/module/graphite/server/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type metricProcessor struct {
sync.RWMutex
}

func NewMetricProcessor(templates []templateConfig, defaultTemplate templateConfig) *metricProcessor {
func NewMetricProcessor(templates []TemplateConfig, defaultTemplate TemplateConfig) *metricProcessor {
templateTree := NewTree(getTemplateFromConfig(defaultTemplate))
for _, t := range templates {
templateTree.Insert(t.Filter, getTemplateFromConfig(t))
Expand All @@ -37,7 +37,7 @@ func NewMetricProcessor(templates []templateConfig, defaultTemplate templateConf
}
}

func getTemplateFromConfig(config templateConfig) template {
func getTemplateFromConfig(config TemplateConfig) template {
return template{
Namespace: config.Namespace,
Tags: config.Tags,
Expand All @@ -46,14 +46,14 @@ func getTemplateFromConfig(config templateConfig) template {
}
}

func (m *metricProcessor) AddTemplate(t templateConfig) {
func (m *metricProcessor) AddTemplate(t TemplateConfig) {
m.Lock()
template := getTemplateFromConfig(t)
m.templates.Insert(t.Filter, template)
m.Unlock()
}

func (m *metricProcessor) RemoveTemplate(template templateConfig) {
func (m *metricProcessor) RemoveTemplate(template TemplateConfig) {
m.Lock()
m.templates.Delete(template.Filter)
m.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions metricbeat/module/graphite/server/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func GetMetricProcessor() *metricProcessor {
templates := []templateConfig{
templates := []TemplateConfig{
{
Namespace: "foo",
Filter: "test.localhost.*",
Expand All @@ -31,13 +31,13 @@ func GetMetricProcessor() *metricProcessor {
},
}

defaultTemplate := defaultGraphiteCollectorConfig().DefaultTemplate
defaultTemplate := DefaultGraphiteCollectorConfig().DefaultTemplate
return NewMetricProcessor(templates, defaultTemplate)
}

func TestMetricProcessorAddTemplate(t *testing.T) {
processor := GetMetricProcessor()
temp := templateConfig{
temp := TemplateConfig{
Namespace: "xyz",
Filter: "a.b.*",
Template: ".host.shell.metric",
Expand All @@ -51,7 +51,7 @@ func TestMetricProcessorAddTemplate(t *testing.T) {

func TestMetricProcessorDeleteTemplate(t *testing.T) {
processor := GetMetricProcessor()
temp := templateConfig{
temp := TemplateConfig{
Namespace: "xyz",
Filter: "a.b.*",
Template: ".host.shell.metric",
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/graphite/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type MetricSet struct {
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
cfgwarn.Experimental("The graphite server metricset is experimental")

config := defaultGraphiteCollectorConfig()
config := DefaultGraphiteCollectorConfig()
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions metricbeat/module/http/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import (
"github.com/elastic/beats/libbeat/common"
)

type httpServerConfig struct {
Paths []pathConfig `config:"paths"`
DefaultPath pathConfig `config:"default_path"`
type HttpServerConfig struct {
Paths []PathConfig `config:"paths"`
DefaultPath PathConfig `config:"default_path"`
}

type pathConfig struct {
type PathConfig struct {
Path string `config:"path"`
Fields common.MapStr `config:"fields"`
Namespace string `config:"namespace"`
}

func defaultHttpServerConfig() httpServerConfig {
return httpServerConfig{
DefaultPath: pathConfig{
func defaultHttpServerConfig() HttpServerConfig {
return HttpServerConfig{
DefaultPath: PathConfig{
Path: "/",
Namespace: "http",
},
}
}

func (p pathConfig) Validate() error {
func (p PathConfig) Validate() error {
if p.Namespace == "" {
return errors.New("`namespace` can not be empty in path configuration")
}
Expand Down
14 changes: 7 additions & 7 deletions metricbeat/module/http/server/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

type metricProcessor struct {
paths map[string]pathConfig
defaultPath pathConfig
paths map[string]PathConfig
defaultPath PathConfig
sync.RWMutex
}

func NewMetricProcessor(paths []pathConfig, defaultPath pathConfig) *metricProcessor {
pathMap := map[string]pathConfig{}
func NewMetricProcessor(paths []PathConfig, defaultPath PathConfig) *metricProcessor {
pathMap := map[string]PathConfig{}
for _, path := range paths {
pathMap[path.Path] = path
}
Expand All @@ -30,13 +30,13 @@ func NewMetricProcessor(paths []pathConfig, defaultPath pathConfig) *metricProce
}
}

func (m *metricProcessor) AddPath(path pathConfig) {
func (m *metricProcessor) AddPath(path PathConfig) {
m.Lock()
m.paths[path.Path] = path
m.Unlock()
}

func (m *metricProcessor) RemovePath(path pathConfig) {
func (m *metricProcessor) RemovePath(path PathConfig) {
m.Lock()
delete(m.paths, path.Path)
m.Unlock()
Expand Down Expand Up @@ -85,7 +85,7 @@ func (p *metricProcessor) Process(event server.Event) (common.MapStr, error) {
return out, nil
}

func (p *metricProcessor) findPath(url string) *pathConfig {
func (p *metricProcessor) findPath(url string) *PathConfig {
for path, conf := range p.paths {
if strings.Index(url, path) == 0 {
return &conf
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/http/server/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func GetMetricProcessor() *metricProcessor {
paths := []pathConfig{
paths := []PathConfig{
{
Namespace: "foo",
Path: "/foo",
Expand All @@ -30,7 +30,7 @@ func GetMetricProcessor() *metricProcessor {

func TestMetricProcessorAddPath(t *testing.T) {
processor := GetMetricProcessor()
temp := pathConfig{
temp := PathConfig{
Namespace: "xyz",
Path: "/abc",
}
Expand All @@ -51,7 +51,7 @@ func TestFindPath(t *testing.T) {
processor := GetMetricProcessor()
tests := []struct {
a string
expected pathConfig
expected PathConfig
}{
{
a: "/foo/bar",
Expand Down