Skip to content

Commit

Permalink
fix: fix incorrect tsv initialization (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkspx authored Mar 2, 2022
1 parent aae7931 commit 733c80e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/dpluger/dpluger.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func createPluginNonCollect(cfg CreatePluginConfig) error {

if cfg.SIDListFile != "" {
var ref tsvRef
ref.initWithConfig(cfg.Plugin.Name, cfg.SIDListFile)
ref.initWithConfig(cfg.SIDListFile)

pt.Ref = ref
pt.SIDListGroup = ref.GroupByCustomData()
Expand Down Expand Up @@ -313,7 +313,7 @@ func createPluginCollect(cfg CreatePluginConfig) error {
pt.Ref = ref
} else {
var ref tsvRef
ref.initWithConfig(cfg.Plugin.Name, cfg.SIDListFile)
ref.initWithConfig(cfg.SIDListFile)

pt.Ref = ref
pt.SIDListGroup = ref.GroupByCustomData()
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/dpluger/es5client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (es *es5Client) Init(esURL string) (err error) {

func (es *es5Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, titleSource, categorySource string, shouldCollectCategory bool) (c tsvRef, err error) {
size := 1000
c.initWithConfig(plugin.Name, confFile)
c.init(plugin.Name, confFile)
var finalAgg, subSubTerm *elastic5.TermsAggregation
rootTerm := elastic5.NewTermsAggregation().Field(titleSource).Size(size)
subTerm := elastic5.NewTermsAggregation().Field(sidSource)
Expand Down Expand Up @@ -121,7 +121,7 @@ func (es *es5Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t
func (es *es5Client) Collect(plugin Plugin, confFile, sidSource, esFilter, categorySource string, shouldCollectCategory bool) (c tsvRef, err error) {

size := 1000
c.initWithConfig(plugin.Name, confFile)
c.init(plugin.Name, confFile)
var subTerm *elastic5.TermsAggregation
terms := elastic5.NewTermsAggregation().Field(sidSource).Size(size)
if shouldCollectCategory {
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/dpluger/es6client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (es *es6Client) Init(esURL string) (err error) {

func (es *es6Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, titleSource, categorySource string, shouldCollectCategory bool) (c tsvRef, err error) {
size := 1000
c.initWithConfig(plugin.Name, confFile)
c.init(plugin.Name, confFile)
var finalAgg, subSubTerm *elastic6.TermsAggregation
rootTerm := elastic6.NewTermsAggregation().Field(titleSource).Size(size)
subTerm := elastic6.NewTermsAggregation().Field(sidSource)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (es *es6Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t
func (es *es6Client) Collect(plugin Plugin, confFile, sidSource, esFilter, categorySource string, shouldCollectCategory bool) (c tsvRef, err error) {

size := 1000
c.initWithConfig(plugin.Name, confFile)
c.init(plugin.Name, confFile)
var subTerm *elastic6.TermsAggregation
terms := elastic6.NewTermsAggregation().Field(sidSource).Size(size)
if shouldCollectCategory {
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/dpluger/es7client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (es *es7Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t
)

var ref tsvRef
ref.initWithConfig(plugin.Name, confFile)
ref.init(plugin.Name, confFile)

if shouldCollectCategory {
categoryAgg := elastic7.NewTermsAggregation().Field(categorySource)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (es *es7Client) Collect(plugin Plugin, confFile, sidSource, esFilter, categ
ref tsvRef
)

ref.initWithConfig(plugin.Name, confFile)
ref.init(plugin.Name, confFile)

var subTerm *elastic7.TermsAggregation
terms := elastic7.NewTermsAggregation().Field(sidSource).Size(size)
Expand Down
17 changes: 15 additions & 2 deletions internal/pkg/dpluger/tsvref.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -189,11 +190,23 @@ func (c *tsvRef) initWithReader(pluginName, base string, r io.Reader) {
c.initSIDList(r)
}

func (c *tsvRef) initWithConfig(pluginName string, configFile string) {
func (c *tsvRef) initWithConfig(configFile string) {
c.SIDs = make(map[int]PluginSID)
c.filename = filepath.Base(configFile)
f, err := os.OpenFile(configFile, os.O_RDONLY, 0600)
if err != nil {
return
}

defer f.Close()
c.initSIDList(f)
}

func (c *tsvRef) init(pluginName string, configFile string) {
c.SIDs = make(map[int]PluginSID)
c.setFilename(pluginName, path.Dir(configFile))
// f, err := os.OpenFile(c.filename, os.O_RDONLY, 0600)
f, err := os.OpenFile(configFile, os.O_RDONLY, 0600)
f, err := os.OpenFile(c.filename, os.O_RDONLY, 0600)
if err != nil {
return
}
Expand Down

0 comments on commit 733c80e

Please sign in to comment.