Skip to content
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 support for Elasticsearch datasource #99 #100

Merged
merged 7 commits into from
Feb 19, 2018
Merged

Add support for Elasticsearch datasource #99 #100

merged 7 commits into from
Feb 19, 2018

Conversation

fho
Copy link
Contributor

@fho fho commented Dec 21, 2017

The PR adds partial support for creating graphs against an elasticsearch datasource.
It only adds support for basic query and aggregators.
Grafana supports more aggregators and query options that are not implemented yet.

@fho
Copy link
Contributor Author

fho commented Jan 4, 2018

@jml any chance to get the PR merged?
It would be great to have the elasticsearch support in the upstream version

@jml
Copy link
Contributor

jml commented Jan 4, 2018 via email

Copy link
Contributor

@jml jml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've got a couple of bigger changes I'd like you to make and a few smaller things. Let me know if you've got questions.


@attr.s
class DateTimeAgg(object):
field = attr.ib(default="time_iso8601", validator=instance_of(str))

This comment was marked as abuse.

class DateTimeAgg(object):
field = attr.ib(default="time_iso8601", validator=instance_of(str))
id = attr.ib(default=0, validator=instance_of(int))
settings = attr.ib(default=DateTimeAggSettings())

This comment was marked as abuse.

'id': str(self.id),
'settings': self.settings,
'type': self.type
}

This comment was marked as abuse.


@attr.s
class CountMetric(object):
field = attr.ib(default="select field", validator=instance_of(str))

This comment was marked as abuse.

This comment was marked as abuse.

@attr.s
class CountMetric(object):
field = attr.ib(default="select field", validator=instance_of(str))
type = attr.ib(default="count", validator=instance_of(str))

This comment was marked as abuse.

"""

alias = attr.ib(default=None)
bucket_aggs = attr.ib(default=[DateTimeAgg()])

This comment was marked as abuse.

if agg.id:
return agg

agg.id = next(auto_ids)

This comment was marked as abuse.

def to_json_data(self):
return {
'alias': self.alias,
'bucketAggs': self.auto_bucket_aggs_id(),

This comment was marked as abuse.

This comment was marked as abuse.

refId = attr.ib(default="", validator=instance_of(str))

def auto_bucket_aggs_id(self):
ids = set([agg.id for agg in self.bucket_aggs if agg.id])

This comment was marked as abuse.

This comment was marked as abuse.

@@ -0,0 +1,65 @@
from grafanalib.core import *

This comment was marked as abuse.

@fho
Copy link
Contributor Author

fho commented Jan 5, 2018

@jml thanks a lot for you feedback. I'll address your remarks soon.

fho added 2 commits February 14, 2018 18:40
Add an ElasticsearchTarget and query related helper classes to create
graphs with queries from an elasticsearch datasource.

This commit only adds partial support for elasticsearch queries.
Grafana supports a lot more Metric and Aggregators for elasticsearch.
@fho
Copy link
Contributor Author

fho commented Feb 14, 2018

@jml
I'm indecisive regarding the naming:

  • Elasticsearch's bucket aggregators are called "Group by" in the Grafana Webinterface
  • Elasticsearch's metric aggregators are called "Metric" in the Grafana Webinterface

In the current PR version metric aggregators have the postfix MetricAgg (like MaxMetricAgg), bucket aggregators have the postfix GroupBy (like DateHistogramGroupBy).
That is inconsistent but calling them GroupBy might be more clear if you are accustomed to the webinterface.

What naming would you prefer?

- add documentation
- improve naming
- remove Settings objects, move the fields to the aggregator objects
- make fields that don't change constants in to_json_data()
@fho
Copy link
Contributor Author

fho commented Feb 14, 2018

@jml I addressed all your comments and did some additional refactoring.
Please review it again

@jml
Copy link
Contributor

jml commented Feb 15, 2018 via email

Copy link
Contributor

@jml jml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thank you so much for sticking with this.

All my comments are very minor, so I'll fix them up myself and then merge this.

@@ -0,0 +1,75 @@
"""
This is an exemplary Grafana board that uses an elastichsearch datasource.
The graph shows the followinging metrics for HTTP requests to the URL path "/login":

This comment was marked as abuse.

"""
This is an exemplary Grafana board that uses an elastichsearch datasource.
The graph shows the followinging metrics for HTTP requests to the URL path "/login":
- number of succesful requests resulted in a HTTP response code between 200-300

This comment was marked as abuse.

)

dashboard = Dashboard(title="HTTP dashboard",
rows=[Row(panels=[g])])

This comment was marked as abuse.

@@ -0,0 +1,207 @@
"""Helpers to create Elasticsearch specific Grafana Queries."""

This comment was marked as abuse.

@jml jml merged commit f295d76 into weaveworks:master Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants