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

change timestamp to time #2405

Merged
merged 1 commit into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ curl -H "Content-Type: application/json" http://localhost:8086/write -d '
"retentionPolicy": "default",
"points": [
{
"timestamp": "2014-11-10T23:00:00Z",
"time": "2014-11-10T23:00:00Z",
"name": "cpu",
"tags": {
"region":"uswest",
Expand Down
8 changes: 4 additions & 4 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ The mechanism is to create one or more points and then create a batch aka *batch
and write these to a given database and series. A series is a combination of a
measurement (time/values) and a set of tags.

In this sample we will create a batch of a 1,000 points. Each point has a timestamp and
In this sample we will create a batch of a 1,000 points. Each point has a time and
a single value as well as 2 tags indicating a shape and color. We write these points
to a database called _square_holes_ using a measurement named _shapes_.

NOTE: In this example, we are specifically assigning timestamp, tags and precision
to each point. Alternately, you can specify a timestamp, tags and precision at
NOTE: In this example, we are specifically assigning time, tags and precision
to each point. Alternately, you can specify a time, tags and precision at
the batch point level that could be used as defaults if an associated point
does not provide these metrics.

Expand Down Expand Up @@ -117,7 +117,7 @@ func writePoints(con *client.Client) {
Fields: map[string]interface{}{
"value": rand.Intn(sampleSize),
},
Timestamp: time.Now(),
Time: time.Now(),
Precision: "s",
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ExampleClient_Write() {
Fields: map[string]interface{}{
"value": rand.Intn(sampleSize),
},
Timestamp: time.Now(),
Time: time.Now(),
Precision: "s",
}
}
Expand Down
48 changes: 24 additions & 24 deletions client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ func (r Response) Error() error {
}

// Point defines the fields that will be written to the database
// Name, Timestamp, and Fields are required
// Precision can be specified if the timestamp is in epoch format (integer).
// Name, Time, and Fields are required
// Precision can be specified if the time is in epoch format (integer).
// Valid values for Precision are n, u, ms, s, m, and h
type Point struct {
Name string
Tags map[string]string
Timestamp time.Time
Time time.Time
Fields map[string]interface{}
Precision string
}
Expand All @@ -320,7 +320,7 @@ func (p *Point) MarshalJSON() ([]byte, error) {
point := struct {
Name string `json:"name,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Time string `json:"time,omitempty"`
Fields map[string]interface{} `json:"fields,omitempty"`
Precision string `json:"precision,omitempty"`
}{
Expand All @@ -330,8 +330,8 @@ func (p *Point) MarshalJSON() ([]byte, error) {
Precision: p.Precision,
}
// Let it omit empty if it's really zero
if !p.Timestamp.IsZero() {
point.Timestamp = p.Timestamp.UTC().Format(time.RFC3339Nano)
if !p.Time.IsZero() {
point.Time = p.Time.UTC().Format(time.RFC3339Nano)
}
return json.Marshal(&point)
}
Expand All @@ -341,14 +341,14 @@ func (p *Point) UnmarshalJSON(b []byte) error {
var normal struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
Time time.Time `json:"time"`
Precision string `json:"precision"`
Fields map[string]interface{} `json:"fields"`
}
var epoch struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Timestamp *int64 `json:"timestamp"`
Time *int64 `json:"time"`
Precision string `json:"precision"`
Fields map[string]interface{} `json:"fields"`
}
Expand All @@ -360,18 +360,18 @@ func (p *Point) UnmarshalJSON(b []byte) error {
if err = dec.Decode(&epoch); err != nil {
return err
}
// Convert from epoch to time.Time, but only if Timestamp
// Convert from epoch to time.Time, but only if Time
// was actually set.
var ts time.Time
if epoch.Timestamp != nil {
ts, err = EpochToTime(*epoch.Timestamp, epoch.Precision)
if epoch.Time != nil {
ts, err = EpochToTime(*epoch.Time, epoch.Precision)
if err != nil {
return err
}
}
p.Name = epoch.Name
p.Tags = epoch.Tags
p.Timestamp = ts
p.Time = ts
p.Precision = epoch.Precision
p.Fields = normalizeFields(epoch.Fields)
return nil
Expand All @@ -384,10 +384,10 @@ func (p *Point) UnmarshalJSON(b []byte) error {
if err := dec.Decode(&normal); err != nil {
return err
}
normal.Timestamp = SetPrecision(normal.Timestamp, normal.Precision)
normal.Time = SetPrecision(normal.Time, normal.Precision)
p.Name = normal.Name
p.Tags = normal.Tags
p.Timestamp = normal.Timestamp
p.Time = normal.Time
p.Precision = normal.Precision
p.Fields = normalizeFields(normal.Fields)

Expand Down Expand Up @@ -417,15 +417,15 @@ func normalizeFields(fields map[string]interface{}) map[string]interface{} {
// Database and Points are required
// If no retention policy is specified, it will use the databases default retention policy.
// If tags are specified, they will be "merged" with all points. If a point already has that tag, it is ignored.
// If timestamp is specified, it will be applied to any point with an empty timestamp.
// Precision can be specified if the timestamp is in epoch format (integer).
// If time is specified, it will be applied to any point with an empty time.
// Precision can be specified if the time is in epoch format (integer).
// Valid values for Precision are n, u, ms, s, m, and h
type BatchPoints struct {
Points []Point `json:"points,omitempty"`
Database string `json:"database,omitempty"`
RetentionPolicy string `json:"retentionPolicy,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
Time time.Time `json:"time,omitempty"`
Precision string `json:"precision,omitempty"`
}

Expand All @@ -436,15 +436,15 @@ func (bp *BatchPoints) UnmarshalJSON(b []byte) error {
Database string `json:"database"`
RetentionPolicy string `json:"retentionPolicy"`
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
Time time.Time `json:"time"`
Precision string `json:"precision"`
}
var epoch struct {
Points []Point `json:"points"`
Database string `json:"database"`
RetentionPolicy string `json:"retentionPolicy"`
Tags map[string]string `json:"tags"`
Timestamp *int64 `json:"timestamp"`
Time *int64 `json:"time"`
Precision string `json:"precision"`
}

Expand All @@ -455,8 +455,8 @@ func (bp *BatchPoints) UnmarshalJSON(b []byte) error {
}
// Convert from epoch to time.Time
var ts time.Time
if epoch.Timestamp != nil {
ts, err = EpochToTime(*epoch.Timestamp, epoch.Precision)
if epoch.Time != nil {
ts, err = EpochToTime(*epoch.Time, epoch.Precision)
if err != nil {
return err
}
Expand All @@ -465,7 +465,7 @@ func (bp *BatchPoints) UnmarshalJSON(b []byte) error {
bp.Database = epoch.Database
bp.RetentionPolicy = epoch.RetentionPolicy
bp.Tags = epoch.Tags
bp.Timestamp = ts
bp.Time = ts
bp.Precision = epoch.Precision
return nil
}(); err == nil {
Expand All @@ -475,12 +475,12 @@ func (bp *BatchPoints) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &normal); err != nil {
return err
}
normal.Timestamp = SetPrecision(normal.Timestamp, normal.Precision)
normal.Time = SetPrecision(normal.Time, normal.Precision)
bp.Points = normal.Points
bp.Database = normal.Database
bp.RetentionPolicy = normal.RetentionPolicy
bp.Tags = normal.Tags
bp.Timestamp = normal.Timestamp
bp.Time = normal.Time
bp.Precision = normal.Precision

return nil
Expand Down
22 changes: 11 additions & 11 deletions client/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ func TestPoint_UnmarshalEpoch(t *testing.T) {

for _, test := range tests {
t.Logf("testing %q\n", test.name)
data := []byte(fmt.Sprintf(`{"timestamp": %d, "precision":"%s"}`, test.epoch, test.precision))
data := []byte(fmt.Sprintf(`{"time": %d, "precision":"%s"}`, test.epoch, test.precision))
t.Logf("json: %s", string(data))
var p client.Point
err := json.Unmarshal(data, &p)
if err != nil {
t.Fatalf("unexpected error. exptected: %v, actual: %v", nil, err)
}
if !p.Timestamp.Equal(test.expected) {
t.Fatalf("Unexpected time. expected: %v, actual: %v", test.expected, p.Timestamp)
if !p.Time.Equal(test.expected) {
t.Fatalf("Unexpected time. expected: %v, actual: %v", test.expected, p.Time)
}
}
}
Expand Down Expand Up @@ -289,15 +289,15 @@ func TestPoint_UnmarshalRFC(t *testing.T) {
for _, test := range tests {
t.Logf("testing %q\n", test.name)
ts := test.now.Format(test.rfc)
data := []byte(fmt.Sprintf(`{"timestamp": %q}`, ts))
data := []byte(fmt.Sprintf(`{"time": %q}`, ts))
t.Logf("json: %s", string(data))
var p client.Point
err := json.Unmarshal(data, &p)
if err != nil {
t.Fatalf("unexpected error. exptected: %v, actual: %v", nil, err)
}
if !p.Timestamp.Equal(test.expected) {
t.Fatalf("Unexpected time. expected: %v, actual: %v", test.expected, p.Timestamp)
if !p.Time.Equal(test.expected) {
t.Fatalf("Unexpected time. expected: %v, actual: %v", test.expected, p.Time)
}
}
}
Expand All @@ -318,9 +318,9 @@ func TestPoint_MarshalOmitempty(t *testing.T) {
},
{
name: "with time",
point: client.Point{Name: "cpu", Fields: map[string]interface{}{"value": 1.1}, Timestamp: now},
point: client.Point{Name: "cpu", Fields: map[string]interface{}{"value": 1.1}, Time: now},
now: now,
expected: fmt.Sprintf(`{"name":"cpu","timestamp":"%s","fields":{"value":1.1}}`, now.Format(time.RFC3339Nano)),
expected: fmt.Sprintf(`{"name":"cpu","time":"%s","fields":{"value":1.1}}`, now.Format(time.RFC3339Nano)),
},
{
name: "with tags",
Expand Down Expand Up @@ -386,7 +386,7 @@ func emptyTestServer() *httptest.Server {
}))
}

// Ensure that data with epoch timestamps can be decoded.
// Ensure that data with epoch times can be decoded.
func TestBatchPoints_Normal(t *testing.T) {
var bp client.BatchPoints
data := []byte(`
Expand All @@ -399,7 +399,7 @@ func TestBatchPoints_Normal(t *testing.T) {
"tags": {
"host": "server01"
},
"timestamp": 14244733039069373,
"time": 14244733039069373,
"precision": "n",
"values": {
"value": 4541770385657154000
Expand All @@ -410,7 +410,7 @@ func TestBatchPoints_Normal(t *testing.T) {
"tags": {
"host": "server01"
},
"timestamp": 14244733039069380,
"time": 14244733039069380,
"precision": "n",
"values": {
"value": 7199311900554737000
Expand Down
4 changes: 2 additions & 2 deletions cmd/influxd/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRestoreCommand(t *testing.T) {
if err := s.CreateDatabase("db"); err != nil {
t.Fatalf("cannot create database: %s", err)
}
if index, err := s.WriteSeries("db", "default", []influxdb.Point{{Name: "cpu", Timestamp: now, Fields: map[string]interface{}{"value": float64(100)}}}); err != nil {
if index, err := s.WriteSeries("db", "default", []influxdb.Point{{Name: "cpu", Time: now, Fields: map[string]interface{}{"value": float64(100)}}}); err != nil {
t.Fatalf("cannot write series: %s", err)
} else if err = s.Sync(1, index); err != nil {
t.Fatalf("shard sync: %s", err)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestRestoreCommand(t *testing.T) {
if err := s.CreateDatabase("newdb"); err != nil {
t.Fatalf("cannot create new database: %s", err)
}
if index, err := s.WriteSeries("newdb", "default", []influxdb.Point{{Name: "mem", Timestamp: now, Fields: map[string]interface{}{"value": float64(1000)}}}); err != nil {
if index, err := s.WriteSeries("newdb", "default", []influxdb.Point{{Name: "mem", Time: now, Fields: map[string]interface{}{"value": float64(1000)}}}); err != nil {
t.Fatalf("cannot write new series: %s", err)
} else if err = s.Sync(2, index); err != nil {
t.Fatalf("shard sync: %s", err)
Expand Down
Loading