Skip to content

Commit 5825841

Browse files
committed
Revert Allow setting the time of a point manually
This reverts commit c25ec08, which this commit is part of PR influxdata#304.
1 parent e898317 commit 5825841

File tree

3 files changed

+14
-69
lines changed

3 files changed

+14
-69
lines changed

influxdb/helper.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Helper class for InfluxDB
44
"""
55
from collections import namedtuple, defaultdict
6-
from datetime import datetime
76
from warnings import warn
87

98
import six
@@ -17,16 +16,6 @@ class SeriesHelper(object):
1716
Each subclass can write to its own database.
1817
The time series names can also be based on one or more defined fields.
1918
20-
A field "time" can be used to write data points at a specific time,
21-
rather than the default current time. The time field can take any of
22-
the following forms:
23-
* An integer unix timestamp in nanoseconds, assumed to be in UTC.
24-
* A string in the ISO time format, including a timezone.
25-
* A naive python datetime, which will be treated as UTC.
26-
* A localized python datetime, which will use the chosen timezone.
27-
If no time field is provided, the current UTC system time in microseconds
28-
at the time of assembling the point data will be used.
29-
3019
Annotated example::
3120
3221
class MySeriesHelper(SeriesHelper):
@@ -153,23 +142,8 @@ def _json_body_(cls):
153142
"tags": {},
154143
}
155144

156-
ts = getattr(point, 'time', None)
157-
if not ts:
158-
# No time provided. Use current UTC time.
159-
ts = datetime.utcnow().isoformat() + "+00:00"
160-
elif isinstance(ts, datetime):
161-
if ts.tzinfo is None or ts.tzinfo.utcoffset(ts) is None:
162-
# Assuming naive datetime provided. Format with UTC tz.
163-
ts = ts.isoformat() + "+00:00"
164-
else:
165-
# Assuming localized datetime provided.
166-
ts = ts.isoformat()
167-
# Neither of the above match. Assuming correct string or int.
168-
json_point['time'] = ts
169-
170145
for field in cls._fields:
171-
if field != 'time':
172-
json_point['fields'][field] = getattr(point, field)
146+
json_point['fields'][field] = getattr(point, field)
173147

174148
for tag in cls._tags:
175149
json_point['tags'][tag] = getattr(point, tag)

influxdb/tests/helper_test.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import datetime
4-
import pytz
53
import sys
64
if sys.version_info < (2, 7):
75
import unittest2 as unittest
@@ -40,18 +38,6 @@ class Meta:
4038

4139
TestSeriesHelper.MySeriesHelper = MySeriesHelper
4240

43-
class MySeriesTimeHelper(SeriesHelper):
44-
45-
class Meta:
46-
client = TestSeriesHelper.client
47-
series_name = 'events.stats.{server_name}'
48-
fields = ['time', 'some_stat']
49-
tags = ['server_name', 'other_tag']
50-
bulk_size = 5
51-
autocommit = True
52-
53-
TestSeriesHelper.MySeriesTimeHelper = MySeriesTimeHelper
54-
5541
def test_auto_commit(self):
5642
"""
5743
Tests that write_points is called after the right number of events
@@ -80,20 +66,14 @@ def testSingleSeriesName(self):
8066
"""
8167
Tests JSON conversion when there is only one series name.
8268
"""
83-
dt = datetime.datetime(2016, 1, 2, 3, 4, 5, 678912)
84-
ts1 = dt
85-
ts2 = "2016-10-11T01:02:03.123456789-04:00"
86-
ts3 = 1234567890123456789
87-
ts4 = pytz.timezone("Europe/Berlin").localize(dt)
88-
89-
TestSeriesHelper.MySeriesTimeHelper(
90-
time=ts1, server_name='us.east-1', other_tag='ello', some_stat=159)
91-
TestSeriesHelper.MySeriesTimeHelper(
92-
time=ts2, server_name='us.east-1', other_tag='ello', some_stat=158)
93-
TestSeriesHelper.MySeriesTimeHelper(
94-
time=ts3, server_name='us.east-1', other_tag='ello', some_stat=157)
95-
TestSeriesHelper.MySeriesTimeHelper(
96-
time=ts4, server_name='us.east-1', other_tag='ello', some_stat=156)
69+
TestSeriesHelper.MySeriesHelper(
70+
server_name='us.east-1', other_tag='ello', some_stat=159)
71+
TestSeriesHelper.MySeriesHelper(
72+
server_name='us.east-1', other_tag='ello', some_stat=158)
73+
TestSeriesHelper.MySeriesHelper(
74+
server_name='us.east-1', other_tag='ello', some_stat=157)
75+
TestSeriesHelper.MySeriesHelper(
76+
server_name='us.east-1', other_tag='ello', some_stat=156)
9777
expectation = [
9878
{
9979
"measurement": "events.stats.us.east-1",
@@ -104,7 +84,6 @@ def testSingleSeriesName(self):
10484
"fields": {
10585
"some_stat": 159
10686
},
107-
"time": "2016-01-02T03:04:05.678912+00:00",
10887
},
10988
{
11089
"measurement": "events.stats.us.east-1",
@@ -115,7 +94,6 @@ def testSingleSeriesName(self):
11594
"fields": {
11695
"some_stat": 158
11796
},
118-
"time": "2016-10-11T01:02:03.123456789-04:00",
11997
},
12098
{
12199
"measurement": "events.stats.us.east-1",
@@ -126,7 +104,6 @@ def testSingleSeriesName(self):
126104
"fields": {
127105
"some_stat": 157
128106
},
129-
"time": 1234567890123456789,
130107
},
131108
{
132109
"measurement": "events.stats.us.east-1",
@@ -137,24 +114,23 @@ def testSingleSeriesName(self):
137114
"fields": {
138115
"some_stat": 156
139116
},
140-
"time": "2016-01-02T03:04:05.678912+01:00",
141117
}
142118
]
143119

144-
rcvd = TestSeriesHelper.MySeriesTimeHelper._json_body_()
120+
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
145121
self.assertTrue(all([el in expectation for el in rcvd]) and
146122
all([el in rcvd for el in expectation]),
147123
'Invalid JSON body of time series returned from '
148124
'_json_body_ for one series name: {0}.'.format(rcvd))
149-
TestSeriesHelper.MySeriesTimeHelper._reset_()
125+
TestSeriesHelper.MySeriesHelper._reset_()
150126
self.assertEqual(
151-
TestSeriesHelper.MySeriesTimeHelper._json_body_(),
127+
TestSeriesHelper.MySeriesHelper._json_body_(),
152128
[],
153129
'Resetting helper did not empty datapoints.')
154130

155131
def testSeveralSeriesNames(self):
156132
'''
157-
Tests JSON conversion when there are multiple series names.
133+
Tests JSON conversion when there is only one series name.
158134
'''
159135
TestSeriesHelper.MySeriesHelper(
160136
server_name='us.east-1', some_stat=159, other_tag='ello')
@@ -208,10 +184,6 @@ def testSeveralSeriesNames(self):
208184
]
209185

210186
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
211-
for r in rcvd:
212-
self.assertTrue(r.get('time'),
213-
"No time field in received JSON body.")
214-
del(r["time"])
215187
self.assertTrue(all([el in expectation for el in rcvd]) and
216188
all([el in rcvd for el in expectation]),
217189
'Invalid JSON body of time series returned from '

test-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
nose
22
nose-cov
33
mock
4-
requests-mock
5-
pytz
4+
requests-mock

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy