-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
138 lines (115 loc) · 2.89 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package fcgw
/**
The server wraps the influxdb httpd server, and instead of
passing input data on to a database, passes it through to
SeriesTable.
*/
import (
"github.com/influxdb/influxdb/services/httpd"
"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/meta"
"time"
)
type InfluxServer struct {
service *httpd.Service
series_table *SeriesTable
}
func NewInfluxServer(st *SeriesTable) *InfluxServer {
is := &InfluxServer{
series_table: st,
}
c := httpd.Config{
Enabled: true,
BindAddress: "0.0.0.0:8086",
AuthEnabled: false,
LogEnabled: true,
WriteTracing: false,
PprofEnabled: false,
HTTPSEnabled: false,
HTTPSCertificate: "",
}
is.service = httpd.NewService(c)
is.service.Handler.PointsWriter = NewPointsConverter(st)
is.service.Handler.Version = "embedded"
is.service.Handler.MetaStore = MetaStore{}
//is.service.Handle.QueryExecutor =
return is
}
type MetaStore struct {}
func (ms MetaStore) WaitForLeader(timeout time.Duration) error {
return nil
}
func (ms MetaStore) Database(name string) (*meta.DatabaseInfo, error) {
di := &meta.DatabaseInfo{
Name: "dummy",
}
return di, nil
}
func (ms MetaStore) Authenticate(username, password string) (ui *meta.UserInfo, err error) {
return nil, nil
}
func (ms MetaStore) Users() ([]meta.UserInfo, error) {
return nil, nil
}
// Define a PointsWriter class that takes a WritePointsRequest from
// the influxdb server code, and sends it in our simplfied form
// up to SeriesTable
type PointsConverter struct {
st *SeriesTable
}
func NewPointsConverter(st *SeriesTable) *PointsConverter {
pc := &PointsConverter{
st: st,
}
return pc
}
func (pc *PointsConverter) WritePoints(p *cluster.WritePointsRequest) error {
pc.st.Logger.Println("WritePoints")
for _, point := range(p.Points) {
for field_name, field := range(point.Fields()) {
// Whereas influx has time series
// with multiple fields, we define
// a time series as a single value series.
// Append field to name to make the conversion
name := point.Name()
name += "." + field_name
// if field.(type) == float64 {
//
// }
var v float64
switch field.(type) {
case float64:
v, _ = field.(float64)
case uint32:
vtmp, _ := field.(uint32)
v = float64(vtmp)
case uint64:
vtmp, _ := field.(uint64)
v = float64(vtmp)
case float32:
vtmp, _ := field.(float32)
v = float64(vtmp)
default:
continue
}
// Work out a series key
sk := NewSeries(SeriesName(name), SeriesTags(point.Tags()) )
key := sk.Key()
// Look up the series object in seriestable
series := pc.st.Series(key)
if series == nil {
pc.st.Insert(sk)
series = sk
}
// append the data
series.Append(TimeVal(point.Time().Unix()), v)
}
}
return nil
}
func (is *InfluxServer) Open() error {
return is.service.Open()
}
func (is *InfluxServer) Close() error {
return is.service.Close()
}