Skip to content

Commit

Permalink
Migrate: Redis prospector to the input interface (#6119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph authored and ruflin committed Jan 25, 2018
1 parent 2ebb47c commit deec4ea
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Renaming of the prospector type to the input type and all prospectors are now moved to the input
folder, to maintain backward compatibility type aliasing was used to map the old type to the new
one. This change also affect YAML configuration. {pull}6078[6078]
- Refactor the Redis prospector to use the input interface {pull}6116[6116]

*Heartbeat*

Expand Down
2 changes: 1 addition & 1 deletion filebeat/input/redis/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package redis package contains prospector and harvester to read the redis slow log
// Package redis package contains input and harvester to read the redis slow log
//
// The redis slow log is stored in memory. The slow log can be activate on the redis command line as following:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ import (

"github.com/elastic/beats/filebeat/channel"
"github.com/elastic/beats/filebeat/harvester"
"github.com/elastic/beats/filebeat/input"
"github.com/elastic/beats/filebeat/input/file"
"github.com/elastic/beats/filebeat/prospector"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/libbeat/logp"
)

func init() {
err := prospector.Register("redis", NewProspector)
err := input.Register("redis", NewInput)
if err != nil {
panic(err)
}
}

// Prospector is a prospector for redis
type Prospector struct {
// Input is a input for redis
type Input struct {
started bool
outlet channel.Outleter
config config
cfg *common.Config
registry *harvester.Registry
}

// NewProspector creates a new redis prospector
func NewProspector(cfg *common.Config, outletFactory channel.Factory, context prospector.Context) (prospector.Prospectorer, error) {
cfgwarn.Experimental("Redis slowlog prospector is enabled.")
// NewInput creates a new redis input
func NewInput(cfg *common.Config, outletFactory channel.Factory, context input.Context) (input.Input, error) {
cfgwarn.Experimental("Redis slowlog input is enabled.")

config := defaultConfig

Expand All @@ -46,7 +46,7 @@ func NewProspector(cfg *common.Config, outletFactory channel.Factory, context pr
return nil, err
}

p := &Prospector{
p := &Input{
started: false,
outlet: outlet,
config: config,
Expand All @@ -58,13 +58,13 @@ func NewProspector(cfg *common.Config, outletFactory channel.Factory, context pr
}

// LoadStates loads the states
func (p *Prospector) LoadStates(states []file.State) error {
func (p *Input) LoadStates(states []file.State) error {
return nil
}

// Run runs the prospector
func (p *Prospector) Run() {
logp.Debug("redis", "Run redis prospector with hosts: %+v", p.config.Hosts)
// Run runs the input
func (p *Input) Run() {
logp.Debug("redis", "Run redis input with hosts: %+v", p.config.Hosts)

if len(p.config.Hosts) == 0 {
logp.Err("No redis hosts configured")
Expand All @@ -85,14 +85,14 @@ func (p *Prospector) Run() {
}
}

// Stop stopps the prospector and all its harvesters
func (p *Prospector) Stop() {
// Stop stops the input and all its harvesters
func (p *Input) Stop() {
p.registry.Stop()
p.outlet.Close()
}

// Wait waits for the propsector to be completed. Not implemented.
func (p *Prospector) Wait() {}
// Wait waits for the input to be completed. Not implemented.
func (p *Input) Wait() {}

// CreatePool creates a redis connection pool
// NOTE: This code is copied from the redis pool handling in metricbeat
Expand Down
2 changes: 1 addition & 1 deletion filebeat/module/redis/log/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ var:
- "c:/program files/Redis/logs/redis.log*"

ingest_pipeline: ingest/pipeline.json
prospector: config/log.yml
input: config/log.yml
12 changes: 12 additions & 0 deletions filebeat/module/redis/log/test/test.log-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"prospector" : {
"type" : "log"
},
"event" : {
"type" : "log"
},
"read_timestamp" : "2017-06-01T22:43:37.024Z",
"source" : "/Users/tsg/src/github.com/elastic/beats/filebeat/module/redis/log/test/test.log",
"fileset" : {
Expand Down Expand Up @@ -45,6 +48,9 @@
"prospector" : {
"type" : "log"
},
"event" : {
"type" : "log"
},
"read_timestamp" : "2017-06-01T22:43:37.024Z",
"source" : "/Users/tsg/src/github.com/elastic/beats/filebeat/module/redis/log/test/test.log",
"fileset" : {
Expand Down Expand Up @@ -77,6 +83,9 @@
"prospector" : {
"type" : "log"
},
"event" : {
"type" : "log"
},
"read_timestamp" : "2017-06-01T22:43:37.024Z",
"source" : "/Users/tsg/src/github.com/elastic/beats/filebeat/module/redis/log/test/test.log",
"fileset" : {
Expand Down Expand Up @@ -107,6 +116,9 @@
"prospector" : {
"type" : "log"
},
"event" : {
"type" : "log"
},
"read_timestamp" : "2017-06-01T22:43:37.024Z",
"source" : "/Users/tsg/src/github.com/elastic/beats/filebeat/module/redis/log/test/test.log",
"fileset" : {
Expand Down
2 changes: 1 addition & 1 deletion filebeat/module/redis/slowlog/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ var:
default: ""

ingest_pipeline: ingest/pipeline.json
prospector: config/slowlog.yml
input: config/slowlog.yml

0 comments on commit deec4ea

Please sign in to comment.