-
Notifications
You must be signed in to change notification settings - Fork 793
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
add index metrics #85
add index metrics #85
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hello, Please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either remote all indices metric from collector/nodes.go
and move them into collector/indices.go
or the other way around. But like this it gets confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the metrics your are using from _all/_stats
are all included in _nodes/_local/stats
/_nodes/stats
which we already get from ES in `collector/nodes.go. Some of the json fields are not (yet) used, but if you are not planning to use the detailed index stats, we don't need to make another http call.
The additional call can be still useful, if we evaluate the per index metrics. I would then make the _all/_stats
call optional.
So my suggestion is:
- retrieve the metrics from this PR from the
_nodes/stats
endpoint, i.e. extendcollector/nodes.go
. - pick a (for now arbitrary) metrics from the index endpoint and expose it as prometheus metric as a starting point for future word. We can then later extend
indices.go
to expose detailed indices metrics.
After merging this PR I would implement the opt-in/opt-out for sub collectors.
Hello, Thank you for the comments.
Certainly we can get the metrics of docs from |
So I fixed below:
What do you think? |
not sure if moving the index metrics to a another call to the ES api is what we want. We need to call What do you think, @dominikschulz ? |
Sounds reasonable. We should make indices metrics optional. |
@zwopir @dominikschulz |
@matsumana IMHO you're changing/moving a lot of unrelated code that shouldn't be touched by your PR. |
collector/cluster_health.go
Outdated
@@ -220,49 +217,14 @@ func (c *ClusterHealth) Describe(ch chan<- *prometheus.Desc) { | |||
ch <- c.jsonParseFailures.Desc() | |||
} | |||
|
|||
func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should remain in this file
collector/cluster_health_test.go
Outdated
"github.com/go-kit/kit/log" | ||
) | ||
|
||
func TestClusterHealth(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should remain in this file
collector/metrics_collector.go
Outdated
indexStatsResponse *indexStatsResponse | ||
} | ||
|
||
func NewMetricsCollector(logger log.Logger, client *http.Client, url *url.URL, all bool, exportIndices bool) *MetricsCollector { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should init all metrics collector in main, not in another wrapper method.
collector/metrics_collector.go
Outdated
c.indices.Collect(ch, clusterHealthResponse, nodeStatsResponse, indexStatsResponse) | ||
} | ||
|
||
func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should stay in it's own file.
collector/metrics_collector.go
Outdated
return chr, nil | ||
} | ||
|
||
func (c *Nodes) fetchAndDecodeNodeStats() (nodeStatsResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should stay in it's own file.
collector/metrics_collector_test.go
Outdated
return | ||
} | ||
|
||
func TestClusterHealth(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should stay in it's own file.
collector/metrics_collector_test.go
Outdated
} | ||
} | ||
|
||
func TestNodesStats(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should stay in it's own file.
collector/nodes.go
Outdated
@@ -984,51 +525,14 @@ func (c *Nodes) Describe(ch chan<- *prometheus.Desc) { | |||
ch <- c.jsonParseFailures.Desc() | |||
} | |||
|
|||
func (c *Nodes) fetchAndDecodeNodeStats() (nodeStatsResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should remain in this file
collector/nodes_test.go
Outdated
"github.com/go-kit/kit/log" | ||
) | ||
|
||
func TestNodesStats(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should remain in this file
collector/cluster_health.go
Outdated
} | ||
|
||
func (c *ClusterHealth) Collect(ch chan<- prometheus.Metric) { | ||
func (c *ClusterHealth) Collect(ch chan<- prometheus.Metric, clusterHealthResponse clusterHealthResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't work. Collect must fulfill the prometheus. Collector interface and thus the signature must be
Collect(ch chan<- prometheus.Metric)
collector/metrics_collector.go
Outdated
|
||
c.clusterHealth.Collect(ch, clusterHealthResponse) | ||
c.nodes.Collect(ch, nodeStatsResponse) | ||
c.indices.Collect(ch, clusterHealthResponse, nodeStatsResponse, indexStatsResponse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapping collectors (or your custom non-interface-fulfilling Collect() ) isn't a good idea. Doing so makes the collectors run sequentially, not in parallel. Also the json retrieval works parallel, if you exclude it from the collectors.
In additionMaking collectors optional is then just a matter of if
ing the prometheus.Mustregister()
.
Could you please refer to you initial intent of this PR: get the docs metrics of the primary shards. To archieve this I would strongly suggest to
- go back to the start (sorry)
- implement the indices collector (fulfilling the collector interface) with just the very few metrics included you are interested in. We would really like to keep the overall index metrics we can get via
_nodes/stats
in the nodes collector. Please only export the structs marshaled from the_all/_stats
that are not in_nodes/stats
. - add this collector optionally with
prometheus.MustRegister
@zwopir @dominikschulz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Matsumana,
thanks for the update. It almost looks good. Two things I would ask you to change:
- exclude the flag, if indices metrics should be scraped to main.go
- a copy'n'paste error in the indices Collect() func
collector/indices.go
Outdated
"err", err, | ||
) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this clusterHealth block in the indices collector is probably a copy'n' paste error, isn't it?!
collector/indices.go
Outdated
client *http.Client | ||
url *url.URL | ||
all bool | ||
exportIndices bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move the bool controlling if indices metrics should be scraped out of the collector. There is no reason registering the metrics via Describe()
and then don't collect them. See my other comment in main.go
collector/indices.go
Outdated
func (c *Indices) fetchAndDecodeIndexStats() (indexStatsResponse, error) { | ||
var isr indexStatsResponse | ||
|
||
if c.exportIndices { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move if statement to main.go
main.go
Outdated
@@ -55,6 +56,7 @@ func main() { | |||
|
|||
prometheus.MustRegister(collector.NewClusterHealth(logger, httpClient, esURL)) | |||
prometheus.MustRegister(collector.NewNodes(logger, httpClient, esURL, *esAllNodes)) | |||
prometheus.MustRegister(collector.NewIndices(logger, httpClient, esURL, *esAllNodes, *esExportIndices)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please replace by
if *exExportIndices {
prometheus.MustRegister(collector.NewIndices(logger, httpClient, esURL, *esAllNodes))
}
(so remove the flag from the NewIndices constructor as well)
collector/indices.go
Outdated
metric.Desc, | ||
metric.Type, | ||
metric.Value(indexStats), | ||
metric.Labels(clusterHealthResponse.ClusterName, indexName)..., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy'n'paste error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review the labels you want to attach to the indices metrics. It seems there is not cluster name available
@zwopir Thank you for the comments. |
looks good to me, thanks for your contribution! |
I would like to monitor index metrics, just like Kinaba X-pack monitoring.
so I added 3 metrics below: