Skip to content

Commit 9862d2f

Browse files
xuthus5hezhangjian
andauthored
feat: add Timestamp to Point and deprecated Time field (#213)
Add a `Timestamp` field instead of `Time`. This change is a compatibility change and will remain in `Time` for some time. Signed-off-by: Young Xu <[email protected]> Signed-off-by: Zhangjian He <[email protected]> Co-authored-by: Zhangjian He <[email protected]>
1 parent ecd1f2d commit 9862d2f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

opengemini/point.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,24 @@ func (p Precision) Epoch() string {
6868
return ""
6969
}
7070

71+
// Point represents a single point in the line protocol format.
72+
// A Point is composed of a measurement name, zero or more tags, one or more fields, and a timestamp.
7173
type Point struct {
74+
// Measurement is the line protocol measurement name definition.
7275
Measurement string
73-
// Precision Timestamp precision ,default value is PrecisionNanosecond
76+
// Precision Timestamp precision, default value is PrecisionNanosecond
7477
Precision Precision
75-
Time time.Time
76-
Tags map[string]string
77-
Fields map[string]interface{}
78+
// Time is the line protocol time field definition.
79+
// Deprecated: Use Timestamp instead. Will be removed in 0.10.0.
80+
Time time.Time
81+
// Timestamp Point creation timestamp, default value is Now() in nanoseconds.
82+
// If p.Time is not zero, Timestamp will be set to p.Time.UnixNano() / int64(p.Precision).
83+
// If Timestamp is zero, Timestamp will be set to current time.
84+
Timestamp int64
85+
// Tags is the line protocol tag field definition.
86+
Tags map[string]string
87+
// Fields is the line protocol value field definition.
88+
Fields map[string]interface{}
7889
}
7990

8091
func (p *Point) AddTag(key string, value string) {
@@ -236,12 +247,18 @@ func (enc *LineProtocolEncoder) Encode(p *Point) error {
236247
}
237248
}
238249

239-
if !p.Time.IsZero() {
250+
if p.Timestamp != 0 || !p.Time.IsZero() {
240251
if err := enc.writeByte(' '); err != nil {
241252
return err
242253
}
243-
if _, err := io.WriteString(enc.w, formatTimestamp(p.Time, p.Precision)); err != nil {
244-
return err
254+
if p.Timestamp != 0 {
255+
if _, err := io.WriteString(enc.w, strconv.FormatInt(p.Timestamp, 10)); err != nil {
256+
return err
257+
}
258+
} else if !p.Time.IsZero() {
259+
if _, err := io.WriteString(enc.w, formatTimestamp(p.Time, p.Precision)); err != nil {
260+
return err
261+
}
245262
}
246263
}
247264

0 commit comments

Comments
 (0)