Skip to content

Conversation

@awake416
Copy link

HI I have added my changes for review to specify a custom transport and ua class. We have a usecase where in instead of ES auth we are using something custom and ES is sitting behind a authentication proxy so queries should have some token added to them.

Users who are having similar requirements now can write their custom plugins and override.

@awake416
Copy link
Author

awake416 commented Apr 4, 2017

@rfarley3 would you help here to move forward.

Copy link
Owner

@rfarley3 rfarley3 left a comment

Choose a reason for hiding this comment

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

This is a great idea! However, I feel that there is a bit of mixture of the needs for a requests.session and needs for the custom useragent object. It is also not applied to all http requests (there is a post that isn't modified later in the code).

If we move the pkg manip/loading to the init and reduce duck typing, then I feel that things would clear up.

--index INDEX Kibana index to work on
--transport-class TRANSPORT_CLASS
Elastic search transport class parameter
--map-ua MAP_UA Over-ride default http user-agent with a custom,
Copy link
Owner

Choose a reason for hiding this comment

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

Why map-ua? How about user-agent?

self.index,
self._index_pattern,
self._host,
self.map_ua,
Copy link
Owner

Choose a reason for hiding this comment

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

Why do the mappings need UAs, but the non-mappings calls don't?

Copy link
Owner

Choose a reason for hiding this comment

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

Would it help if I made both the Mappings and Manager class use the Elasticsearch API instead of Mappings using requests and Manager using ES?

transport_class_obj = getattr(mod, my_class)
self.es = Elasticsearch(
[{'host': self._host_ip, 'port': self._host_port}], transport_class=transport_class_obj)
else:
Copy link
Owner

Choose a reason for hiding this comment

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

If transport_class is false, then self.es is never set. Is this indent wrong?

self.index = index
self._index_pattern = index_pattern
self._host = host
self.map_ua = map_ua,
Copy link
Owner

Choose a reason for hiding this comment

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

Let's call the setting/conversion function here once, to avoid relying on isinstance of str and leverage a single session instead of one session per request. Also, then instead of self.get_map_ua() we can call the attribute directly.

def pr_err(self, msg):
print('[ERR] Mapping %s' % msg)

def get_map_ua(self):
Copy link
Owner

Choose a reason for hiding this comment

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

There are too many types for this single variable, it's a string, a custom ua obj, or a requests.session. I feel like the user agent concept is being blended with the sessions usage. Could we separate out or clarify those needs?

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