github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/common/influxdb/dummy_influxdb.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package influxdb 16 17 import ( 18 "strings" 19 "time" 20 21 influxdb "github.com/influxdata/influxdb/client" 22 ) 23 24 type PointSavedToInfluxdb struct { 25 Ponit influxdb.Point 26 } 27 28 type FakeInfluxDBClient struct { 29 Pnts []PointSavedToInfluxdb 30 } 31 32 func NewFakeInfluxDBClient() *FakeInfluxDBClient { 33 return &FakeInfluxDBClient{[]PointSavedToInfluxdb{}} 34 } 35 36 func (client *FakeInfluxDBClient) Write(bps influxdb.BatchPoints) (*influxdb.Response, error) { 37 for _, pnt := range bps.Points { 38 client.Pnts = append(client.Pnts, PointSavedToInfluxdb{pnt}) 39 } 40 return nil, nil 41 } 42 43 func (client *FakeInfluxDBClient) Query(q influxdb.Query) (*influxdb.Response, error) { 44 numQueries := strings.Count(q.Command, ";") 45 46 // return an empty result for each separate query 47 return &influxdb.Response{ 48 Results: make([]influxdb.Result, numQueries), 49 }, nil 50 } 51 52 func (client *FakeInfluxDBClient) Ping() (time.Duration, string, error) { 53 return 0, "", nil 54 } 55 56 var Client = NewFakeInfluxDBClient() 57 58 var Config = InfluxdbConfig{ 59 User: "root", 60 Password: "root", 61 Host: "localhost:8086", 62 DbName: "k8s", 63 Secure: false, 64 Concurrency: 1, 65 }