Add Indexer.Size() and index_size metric

This commit is contained in:
James Mills
2021-02-07 21:12:49 +10:00
parent c31fc9569f
commit ce4b180576
3 changed files with 390 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import (
type Indexer interface {
Index(entry *Entry) error
Size() int64
Search(q string, p int) (*bleve.SearchResult, error)
}
@@ -40,6 +41,15 @@ func NewIndexer(conf *Config) (Indexer, error) {
return &indexer{conf: conf, idx: idx}, nil
}
func (i *indexer) Size() int64 {
count, err := i.idx.DocCount()
if err != nil {
log.WithError(err).Warn("error getting index size")
return 0
}
return int64(count)
}
func (i *indexer) Index(entry *Entry) error {
return i.idx.Index(entry.Hash(), entry)
}