This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 523
Line protocol #211
Merged
Merged
Line protocol #211
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
078350e
initial implementation of line protocol
trehn 9b753de
update client tests for line protocol
trehn 99cc8ca
Fixes for line-protocol feature
ynezz ca10f5e
line protocol: fix timestamp UTC conversion
trehn f029677
the timestamp field is called 'time'
trehn dae6a8a
fix some expected timestamps
trehn 7fae65f
set precision and retention policy in GET params
trehn 1350d05
update some more test cases
trehn 7553d73
Merge branch 'master' of github.com:influxdb/influxdb-python into lin…
6627efa
Formatting improvements
2ea2437
New epoch parameter + pep8 + enable udp tests
a17e743
Fixed tests for new line protocol
439f46c
isinstance: Use tuple
58dac7b
Fix write_points_batch test for python3.
geodimm 126b39d
Update queries and tests for InfluxDB v0.9.1.
geodimm ab590e3
Travis.yml: Updated to InfluxDB 0.9.1
3699c15
Merge branch 'master' of github.com:influxdb/influxdb-python into HEAD
32f5bed
'time.sleep(0.1)' before returning free port
1775b24
line_protocol: Don't replace when decoding utf-8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from calendar import timegm | ||
| from copy import copy | ||
| from datetime import datetime | ||
|
|
||
| from dateutil.parser import parse | ||
| from pytz import utc | ||
| from six import binary_type, text_type | ||
|
|
||
|
|
||
| def _convert_timestamp(timestamp): | ||
| if isinstance(timestamp, int): | ||
| return timestamp | ||
| if isinstance(_force_text(timestamp), text_type): | ||
| timestamp = parse(timestamp) | ||
| if isinstance(timestamp, datetime): | ||
| if timestamp.tzinfo: | ||
| timestamp = timestamp.astimezone(utc) | ||
| timestamp.replace(tzinfo=None) | ||
| return ( | ||
| timegm(timestamp.timetuple()) * 1e9 + | ||
| timestamp.microsecond * 1e3 | ||
| ) | ||
| raise ValueError(timestamp) | ||
|
|
||
|
|
||
| def _escape_tag(tag): | ||
| return tag.replace( | ||
| "\\", "\\\\" | ||
| ).replace( | ||
| " ", "\\ " | ||
| ).replace( | ||
| ",", "\\," | ||
| ).replace( | ||
| "=", "\\=" | ||
| ) | ||
|
|
||
|
|
||
| def _escape_value(value): | ||
| value = _force_text(value) | ||
| if isinstance(value, text_type): | ||
| return "\"{}\"".format(value.replace( | ||
| "\"", "\\\"" | ||
| )) | ||
| else: | ||
| return str(value) | ||
|
|
||
|
|
||
| def _force_text(data): | ||
| """ | ||
| Try to return a text aka unicode object from the given data. | ||
| """ | ||
| if isinstance(data, binary_type): | ||
| return data.decode('utf-8') | ||
| else: | ||
| return data | ||
|
|
||
|
|
||
| def make_lines(data): | ||
| """ | ||
| Extracts the points from the given dict and returns a Unicode string | ||
| matching the line protocol introduced in InfluxDB 0.9.0. | ||
| """ | ||
| lines = "" | ||
| static_tags = data.get('tags', None) | ||
| for point in data['points']: | ||
| # add measurement name | ||
| lines += _escape_tag(_force_text( | ||
| point.get('measurement', data.get('measurement')) | ||
| )) + "," | ||
|
|
||
| # add tags | ||
| if static_tags is None: | ||
| tags = point.get('tags', {}) | ||
| else: | ||
| tags = copy(static_tags) | ||
| tags.update(point.get('tags', {})) | ||
| # tags should be sorted client-side to take load off server | ||
| for tag_key in sorted(tags.keys()): | ||
| lines += "{key}={value},".format( | ||
| key=_escape_tag(tag_key), | ||
| value=_escape_tag(tags[tag_key]), | ||
| ) | ||
| lines = lines[:-1] + " " # strip the trailing comma | ||
|
|
||
| # add fields | ||
| for field_key in sorted(point['fields'].keys()): | ||
| lines += "{key}={value},".format( | ||
| key=_escape_tag(field_key), | ||
| value=_escape_value(point['fields'][field_key]), | ||
| ) | ||
| lines = lines[:-1] # strip the trailing comma | ||
|
|
||
| # add timestamp | ||
| if 'time' in point: | ||
| lines += " " + _force_text(str(int( | ||
| _convert_timestamp(point['time']) | ||
| ))) | ||
|
|
||
| lines += "\n" | ||
| return lines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| python-dateutil>=2.0.0 | ||
| pytz | ||
| requests>=1.0.3 | ||
| six==1.9.0 | ||
| six==1.9.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any specific reason for this new line?
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.
Not really, this was included in a
Formating improvementscommit.