コード例 #1
0
ファイル: main.go プロジェクト: Wikia/influxdb
func main() {
	numberOfSeries := 50000
	if len(os.Args) > 1 {
		numberOfSeries, _ = strconv.Atoi(os.Args[1])
	}
	fmt.Printf("Benchmarking writing %d series\n", numberOfSeries)

	c, err := client.NewClient(&client.ClientConfig{})
	if err != nil {
		panic(err)
	}

	before := time.Now()
	c.DeleteDatabase("performance")
	fmt.Printf("Deleting took %s\n", time.Now().Sub(before))
	os.Exit(0)
	if err := c.CreateDatabase("performance"); err != nil {
		panic(err)
	}

	c, err = client.NewClient(&client.ClientConfig{
		Database: "performance",
	})
	if err != nil {
		panic(err)
	}

	before = time.Now()

	for i := 0; i < 10; i++ {
		series := []*client.Series{}
		for i := 0; i < numberOfSeries; i++ {
			name := fmt.Sprintf("series_%d", i+1)
			series = append(series, &client.Series{
				Name:    name,
				Columns: []string{"value"},
				Points: [][]interface{}{
					{rand.Float64()},
				},
			})
		}
		if err := c.WriteSeries(series); err != nil {
			panic(err)
		}
	}

	fmt.Printf("Writing took %s\n", time.Now().Sub(before))
}
コード例 #2
0
ファイル: data_test_client.go プロジェクト: Wikia/influxdb
func (self *DataTestClient) RunInvalidQuery(query string, c *C, timePrecision ...influxdb.TimePrecision) []*influxdb.Series {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{Database: self.db})
	c.Assert(err, IsNil)
	_, err = client.Query(query, timePrecision...)
	c.Assert(err, NotNil)
	return nil
}
コード例 #3
0
ファイル: data_test_client.go プロジェクト: Wikia/influxdb
func (self *DataTestClient) RunQueryWithNumbers(query string, c *C, timePrecision ...influxdb.TimePrecision) []*influxdb.Series {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{Database: self.db})
	c.Assert(err, IsNil)
	series, err := client.QueryWithNumbers(query, timePrecision...)
	c.Assert(err, IsNil)
	return series
}
コード例 #4
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) TestSslOnly(c *C) {
	self.server.Stop()
	// TODO: don't hard code the path here
	c.Assert(os.RemoveAll("/tmp/influxdb/development"), IsNil)
	server := NewSslServer("integration/test_ssl_only.toml", c)
	server.WaitForServerToStart()

	defer func() {
		server.Stop()
		self.server = NewServer("integration/test_config_single.toml", c)
	}()

	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		IsSecure: true,
		HttpClient: &http.Client{
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{
					InsecureSkipVerify: true,
				},
			},
		},
	})

	c.Assert(err, IsNil)
	c.Assert(client.Ping(), IsNil)

}
コード例 #5
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) createUser(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.CreateDatabase("db1"), IsNil)
	c.Assert(client.CreateDatabaseUser("db1", "user", "pass"), IsNil)
	c.Assert(client.AlterDatabasePrivilege("db1", "user", true), IsNil)
}
コード例 #6
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) TestShortPasswords(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)

	c.Assert(client.CreateDatabase("shahid"), IsNil)
	c.Assert(client.CreateDatabaseUser("shahid", "shahid", "1"), Not(ErrorMatches), ".*blowfish.*")

	// should be able to recreate the user
	c.Assert(client.CreateDatabaseUser("shahid", "shahid", "shahid"), IsNil)

	c.Assert(client.AuthenticateDatabaseUser("shahid", "shahid", "shahid"), IsNil)
}
コード例 #7
0
ファイル: server.go プロジェクト: Wikia/influxdb
func (self *Server) GetClientWithUser(db, username, password string, c *C) *influxdb.Client {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Host:     fmt.Sprintf("localhost:%d", self.ApiPort()),
		Username: username,
		Password: password,
		Database: db,
		HttpClient: &http.Client{
			Timeout: time.Second * 60,
		},
	})
	c.Assert(err, IsNil)
	return client
}
コード例 #8
0
ファイル: data_test_client.go プロジェクト: Wikia/influxdb
func (self *DataTestClient) WriteData(series []*influxdb.Series, c *C, timePrecision ...influxdb.TimePrecision) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Database: self.db,
		HttpClient: &http.Client{
			Timeout: 60 * time.Second,
		},
	})
	c.Assert(err, IsNil)
	if len(timePrecision) == 0 {
		c.Assert(client.WriteSeries(series), IsNil)
	} else {
		c.Assert(client.WriteSeriesWithTimePrecision(series, timePrecision[0]), IsNil)
	}
}
コード例 #9
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
// issue #378
func (self *SingleServerSuite) TestDeletingNewDatabase(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.CreateDatabase("delete0"), IsNil)

	s := CreatePoints("data_resurrection", 1, 10)
	self.server.WriteData(s, c)
	self.server.WaitForServerToSync()

	for i := 0; i < 2; i++ {
		c.Assert(client.CreateDatabase("delete1"), IsNil)
		c.Assert(client.DeleteDatabase("delete1"), IsNil)
		c.Assert(client.Ping(), IsNil)
	}
}
コード例 #10
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) TestSingleServerHostnameChange(c *C) {
	self.server.Stop()
	// TODO: don't hard code the path here
	c.Assert(os.RemoveAll("/tmp/influxdb/development"), IsNil)
	server := NewServerWithArgs("integration/test_config_single.toml", c, "-hostname", "foo")
	server.WaitForServerToStart()
	server.Stop()
	server = NewServerWithArgs("integration/test_config_single.toml", c, "-hostname", "bar")
	server.WaitForServerToStart()

	defer func() {
		server.Stop()
		self.server = NewServer("integration/test_config_single.toml", c)
	}()

	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.Ping(), IsNil)
}
コード例 #11
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
// test for issue #41
func (self *SingleServerSuite) TestDbDelete(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	self.server.WriteData(`
[
  {
    "name": "test_deletetions",
    "columns": ["val1", "val2"],
    "points":[["v1", 2]]
  }
]`, c, "s")

	data := self.server.RunQuery("select val1 from test_deletetions", "m", c)
	c.Assert(data, HasLen, 1)

	c.Assert(client.DeleteDatabase("db1"), IsNil)

	self.createUser(c)
	// this shouldn't return any data
	error, _ := self.server.GetErrorBody("db1", "select val1 from test_deletetions", "root", "root", true, c)
	c.Assert(error, Matches, ".*Couldn't find series.*")
}
コード例 #12
0
ファイル: server.go プロジェクト: Wikia/influxdb
func (self *Server) reportStats() {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Database: "reporting",
		Host:     "m.influxdb.com:8086",
		Username: "******",
		Password: "******",
	})

	if err != nil {
		log.Error("Couldn't create client for reporting: %s", err)
	} else {
		series := &influxdb.Series{
			Name:    "reports",
			Columns: []string{"os", "arch", "id", "version"},
			Points: [][]interface{}{
				{runtime.GOOS, runtime.GOARCH, self.RaftServer.GetRaftName(), self.Config.InfluxDBVersion},
			},
		}

		log.Info("Reporting stats: %#v", series)
		client.WriteSeries([]*influxdb.Series{series})
	}
}
コード例 #13
0
ファイル: data_test_client.go プロジェクト: Wikia/influxdb
func (self *DataTestClient) DeleteDatabase(db string, c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.DeleteDatabase(db), IsNil)
}
コード例 #14
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) TestInvalidDbUserCreation(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)

	c.Assert(client.CreateDatabaseUser("db999", "user", "pass"), NotNil)
}
コード例 #15
0
ファイル: single_server_test.go プロジェクト: Wikia/influxdb
func (self *SingleServerSuite) TestUserWritePermissions(c *C) {
	rootUser := self.server.GetClient("", c)

	verifyPermissions := func(db string, name string, readFrom string, writeTo string) {
		users, _ := rootUser.GetDatabaseUserList(db)
		matched := false
		for _, user := range users {
			if user["name"] == name {
				c.Assert(user["readFrom"], DeepEquals, readFrom)
				c.Assert(user["writeTo"], DeepEquals, writeTo)
				matched = true
			}
		}
		c.Assert(matched, Equals, true)
	}

	// create two users one that can only read and one that can only write. both can access test_should_read
	// series only
	rootUser.CreateDatabase("db1")
	c.Assert(rootUser.CreateDatabaseUser("db1", "limited_user", "pass", "^$", "^$"), IsNil)
	verifyPermissions("db1", "limited_user", "^$", "^$")

	config := &influxdb.ClientConfig{
		Username: "******",
		Password: "******",
		Database: "db1",
	}
	user, err := influxdb.NewClient(config)
	c.Assert(err, IsNil)

	data := `
[
  {
    "points": [
        [1]
    ],
    "name": "test_should_write",
    "columns": ["value"]
  }
]`
	invalidData := `
[
  {
    "points": [
        [2]
    ],
    "name": "test_should_not_write",
    "columns": ["value"]
  }
]`
	series := []*influxdb.Series{}
	c.Assert(json.Unmarshal([]byte(data), &series), IsNil)
	// readUser shouldn't be able to write
	c.Assert(user.WriteSeries(series), NotNil)
	actualSeries, err := rootUser.Query("select * from test_should_write", "s")
	// if this test ran by itself there will be no shards to query,
	// therefore no error will be returned
	if err != nil {
		c.Assert(err, ErrorMatches, ".*Couldn't find series.*")
	} else {
		c.Assert(actualSeries, HasLen, 0)
	}
	rootUser.ChangeDatabaseUser("db1", "limited_user", "pass", false, "^$", "test_should_write")
	verifyPermissions("db1", "limited_user", "^$", "test_should_write")
	// write the data to test the write permissions
	c.Assert(user.WriteSeries(series), IsNil)
	content := self.server.RunQueryAsRoot("select * from test_should_write", "m", c)
	c.Assert(content, HasLen, 1)
	invalidSeries := []*influxdb.Series{}
	c.Assert(json.Unmarshal([]byte(invalidData), &invalidSeries), IsNil)
	c.Assert(user.WriteSeries(invalidSeries), NotNil)
	self.server.WaitForServerToSync()
	content, err = rootUser.Query("select * from test_should_not_write", "m")
	c.Assert(content, HasLen, 0)
	rootUser.ChangeDatabaseUser("db1", "limited_user", "pass", false, "^$", "test_.*")
	verifyPermissions("db1", "limited_user", "^$", "test_.*")
	c.Assert(user.WriteSeries(invalidSeries), IsNil)
	self.server.WaitForServerToSync()
	content = self.server.RunQueryAsRoot("select * from test_should_not_write", "m", c)
	c.Assert(content, HasLen, 1)
}
コード例 #16
0
ファイル: example.go プロジェクト: Wikia/influxdb
func internalTest(compression bool) {
	c, err := client.NewClient(&client.ClientConfig{})
	if err != nil {
		panic(err)
	}

	admins, err := c.GetClusterAdminList()
	if err != nil {
		panic(err)
	}

	if len(admins) == 1 {
		if err := c.CreateClusterAdmin("admin", "password"); err != nil {
			panic(err)
		}
	}

	admins, err = c.GetClusterAdminList()
	if err != nil {
		panic(err)
	}

	if len(admins) != 2 {
		panic("more than two admins returned")
	}

	dbs, err := c.GetDatabaseList()
	if err != nil {
		panic(err)
	}

	if len(dbs) == 0 {
		if err := c.CreateDatabase("foobar"); err != nil {
			panic(err)
		}
	}

	dbs, err = c.GetDatabaseList()
	if err != nil {
		panic(err)
	}

	if len(dbs) != 1 && dbs[0]["foobar"] == nil {
		panic("List of databases don't match")
	}

	users, err := c.GetDatabaseUserList("foobar")
	if err != nil {
		panic(err)
	}

	if len(users) == 0 {
		if err := c.CreateDatabaseUser("foobar", "dbuser", "pass"); err != nil {
			panic(err)
		}

		if err := c.AlterDatabasePrivilege("foobar", "dbuser", true); err != nil {
			panic(err)
		}
	}

	users, err = c.GetDatabaseUserList("foobar")
	if err != nil {
		panic(err)
	}

	if len(users) != 1 {
		panic("more than one user returned")
	}

	c, err = client.NewClient(&client.ClientConfig{
		Username: "******",
		Password: "******",
		Database: "foobar",
	})

	if !compression {
		c.DisableCompression()
	}

	if err != nil {
		panic(err)
	}

	name := "ts9"
	if !compression {
		name = "ts9_uncompressed"
	}

	series := &client.Series{
		Name:    name,
		Columns: []string{"value"},
		Points: [][]interface{}{
			{1.0},
		},
	}
	if err := c.WriteSeries([]*client.Series{series}); err != nil {
		panic(err)
	}

	result, err := c.Query("select * from " + name)
	if err != nil {
		panic(err)
	}

	if len(result) != 1 {
		panic(fmt.Errorf("expected one time series returned: %d", len(result)))
	}

	if len(result[0].Points) != 1 {
		panic(fmt.Errorf("Expected one point: %d", len(result[0].Points)))
	}

	if result[0].Points[0][2].(float64) != 1 {
		panic("Value not equal to 1")
	}

	c, err = client.NewClient(&client.ClientConfig{
		Username: "******",
		Password: "******",
	})

	if err != nil {
		panic(err)
	}

	spaces, err := c.GetShardSpaces()
	if err != nil || len(spaces) == 0 {
		panic(fmt.Errorf("Got empty spaces back: %s", err))
	}
	if spaces[0].Name != "default" {
		panic("Space name isn't default")
	}
	space := &client.ShardSpace{Name: "foo", Regex: "/^paul_is_rad/"}
	err = c.CreateShardSpace("foobar", space)
	if err != nil {
		panic(err)
	}
	spaces, _ = c.GetShardSpaces()
	if spaces[1].Name != "foo" {
		panic("Space name isn't foo")
	}
	shards, err := c.GetShards()
	if err != nil {
		panic(fmt.Errorf("Couldn't get shards back: %s", err))
	}

	c, err = client.NewClient(&client.ClientConfig{
		Username: "******",
		Password: "******",
		Database: "",
	})
	series = &client.Series{
		Name:    "paul_is_rad",
		Columns: []string{"value"},
		Points: [][]interface{}{
			{1.0},
		},
	}
	if err := c.WriteSeries([]*client.Series{series}); err != nil {
		panic(err)
	}

	spaces, _ = c.GetShardSpaces()
	count := 0
	for _, s := range shards.All {
		if s.SpaceName == "foo" {
			count++
		}
	}

	if err := c.DropShardSpace("foobar", "foo"); err != nil {
		panic(fmt.Errorf("Error: %s", err))
	}

	spaces, err = c.GetShardSpaces()
	if err != nil || len(spaces) != 1 || spaces[0].Name != "default" {
		panic(fmt.Errorf("Error: %s, %d, %s", err, len(spaces), spaces[0].Name))
	}
}