Skip to content

Commit

Permalink
test(inputs.solr): Rework testing (influxdata#13692)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Jul 28, 2023
1 parent a438fa7 commit babd887
Show file tree
Hide file tree
Showing 31 changed files with 1,450 additions and 415 deletions.
7 changes: 5 additions & 2 deletions plugins/inputs/solr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[[inputs.solr]]
## specify a list of one or more Solr servers
servers = ["http://localhost:8983"]
##

## specify a list of one or more Solr cores (default - all)
# cores = ["main"]
##

## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"

## Timeout for HTTP requests
# timeout = "5s"
```

## Metrics
Expand Down
7 changes: 5 additions & 2 deletions plugins/inputs/solr/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
[[inputs.solr]]
## specify a list of one or more Solr servers
servers = ["http://localhost:8983"]
##

## specify a list of one or more Solr cores (default - all)
# cores = ["main"]
##

## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"

## Timeout for HTTP requests
# timeout = "5s"
110 changes: 14 additions & 96 deletions plugins/inputs/solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,111 +26,27 @@ const adminCoresPath = "/solr/admin/cores?action=STATUS&wt=json"

// Solr is a plugin to read stats from one or many Solr servers
type Solr struct {
Local bool
Servers []string
Username string
Password string
HTTPTimeout config.Duration
Cores []string
client *http.Client
}

// AdminCoresStatus is an exported type that
// contains a response with information about Solr cores.
type AdminCoresStatus struct {
Status map[string]struct {
Index struct {
SizeInBytes int64 `json:"sizeInBytes"`
NumDocs int64 `json:"numDocs"`
MaxDoc int64 `json:"maxDoc"`
DeletedDocs int64 `json:"deletedDocs"`
} `json:"index"`
} `json:"status"`
}

// MBeansData is an exported type that
// contains a response from Solr with metrics
type MBeansData struct {
Headers ResponseHeader `json:"responseHeader"`
SolrMbeans []json.RawMessage `json:"solr-mbeans"`
}

// ResponseHeader is an exported type that
// contains a response metrics: QTime and Status
type ResponseHeader struct {
QTime int64 `json:"QTime"`
Status int64 `json:"status"`
}

// Core is an exported type that
// contains Core metrics
type Core struct {
Stats struct {
DeletedDocs int64 `json:"deletedDocs"`
MaxDoc int64 `json:"maxDoc"`
NumDocs int64 `json:"numDocs"`
} `json:"stats"`
}
Servers []string `toml:"servers"`
Username string `toml:"username"`
Password string `toml:"password"`
HTTPTimeout config.Duration `toml:"timeout"`
Cores []string `toml:"cores"`

// QueryHandler is an exported type that
// contains query handler metrics
type QueryHandler struct {
Stats interface{} `json:"stats"`
}

// UpdateHandler is an exported type that
// contains update handler metrics
type UpdateHandler struct {
Stats struct {
Adds int64 `json:"adds"`
AutocommitMaxDocs int64 `json:"autocommit maxDocs"`
AutocommitMaxTime string `json:"autocommit maxTime"`
Autocommits int64 `json:"autocommits"`
Commits int64 `json:"commits"`
CumulativeAdds int64 `json:"cumulative_adds"`
CumulativeDeletesByID int64 `json:"cumulative_deletesById"`
CumulativeDeletesByQuery int64 `json:"cumulative_deletesByQuery"`
CumulativeErrors int64 `json:"cumulative_errors"`
DeletesByID int64 `json:"deletesById"`
DeletesByQuery int64 `json:"deletesByQuery"`
DocsPending int64 `json:"docsPending"`
Errors int64 `json:"errors"`
ExpungeDeletes int64 `json:"expungeDeletes"`
Optimizes int64 `json:"optimizes"`
Rollbacks int64 `json:"rollbacks"`
SoftAutocommits int64 `json:"soft autocommits"`
} `json:"stats"`
}

// Hitratio is an helper interface
// so we can later on convert it to float64
type Hitratio interface{}

// Cache is an exported type that
// contains cache metrics
type Cache struct {
Stats map[string]interface{} `json:"stats"`
}

// NewSolr return a new instance of Solr
func NewSolr() *Solr {
return &Solr{
HTTPTimeout: config.Duration(time.Second * 5),
}
client *http.Client
}

func (*Solr) SampleConfig() string {
return sampleConfig
}

func (s *Solr) Init() error {
s.client = s.createHTTPClient()
return nil
}

// Gather reads the stats from Solr and writes it to the
// Accumulator.
func (s *Solr) Gather(acc telegraf.Accumulator) error {
if s.client == nil {
client := s.createHTTPClient()
s.client = client
}

var wg sync.WaitGroup
wg.Add(len(s.Servers))

Expand Down Expand Up @@ -486,6 +402,8 @@ func (s *Solr) gatherData(url string, v interface{}) error {

func init() {
inputs.Add("solr", func() telegraf.Input {
return NewSolr()
return &Solr{
HTTPTimeout: config.Duration(time.Second * 5),
}
})
}
Loading

0 comments on commit babd887

Please sign in to comment.