diff --git a/.travis.yml b/.travis.yml index 7cf3d0d..d47fc59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.12.x + - 1.13.x - tip go_import_path: github.com/v3io/http_blaster diff --git a/examples/faker_2_kv_example.toml b/examples/faker_2_kv_example.toml index ba5caa8..d553b66 100644 --- a/examples/faker_2_kv_example.toml +++ b/examples/faker_2_kv_example.toml @@ -1,24 +1,27 @@ title = "Workload example" [global] - Duration = "160s" - server="webapi.default-tenant.app.hostname.lab.iguazeng.com" - port="8081" - TLSMode=false + Duration="3600s" + servers=["Servers"] + port="8444" + TLSMode=true [global.StatusCodesAcceptance] 200 = 100.0 # upto 100% return status of 200 204 = 100.0 205 = 100.0 [workloads] - [workloads.load_faker_to_kv] - name="faker_to_kv" - count=1 + [workloads.fakertokv] + name="load_faker_to_kv" Generator="faker2kv" - container="bigdata" - lazy=10 - Target="faker2kv/" - workers=100 + container="parquez" + count=10000000000000000 + duration="72h" + lazy = 100 + type="PUT" + workers=1 + Target="faker/" Partition="day" - [workloads.load_faker_to_kv.Header] - "Authorization"="Basic abcdefg" + [workloads.fakertokv.Header] + "Authorization"="Authorization" + diff --git a/httpblaster/data_generator/memoryGenerator.go b/httpblaster/data_generator/memoryGenerator.go index 1af5d9e..2e24fe5 100644 --- a/httpblaster/data_generator/memoryGenerator.go +++ b/httpblaster/data_generator/memoryGenerator.go @@ -3,8 +3,8 @@ package data_generator import ( "encoding/json" "fmt" + log "github.com/sirupsen/logrus" "strings" - //"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/mem" "github.com/v3io/http_blaster/httpblaster/igz_data" @@ -14,55 +14,55 @@ import ( "time" ) -type MemoryGenerator struct{ - Total uint64 - Availible uint64 - Active uint64 +type MemoryGenerator struct { + Total uint64 + Availible uint64 + Active uint64 } -func (self *MemoryGenerator) GenerateRandomData(cpuNumber string) []string{ +func (self *MemoryGenerator) GenerateRandomData(cpuNumber string) []string { //stats, _ := cpu.Info() //fmt.Println(stats) v, _ := mem.VirtualMemory() - payloads :=self.GenerateJsonArray(v ,cpuNumber) - fmt.Println(strings.Join(payloads, ", ")) + payloads := self.GenerateJsonArray(v, cpuNumber) + log.Debugln("[" + strings.Join(payloads, ", ") + "]") + //fmt.Println(strings.Join(payloads, ", ")) return payloads } -func (self *MemoryGenerator) GenerateJsonByVal(timestamp string,colName string,val float64 , cpuNumber string) string{ +func (self *MemoryGenerator) GenerateJsonByVal(timestamp string, colName string, val float64, cpuNumber string) string { //item :=igz_data.IgzTSDBItem{} - item :=igz_data.IgzTSDBItem{} + item := igz_data.IgzTSDBItem{} item.InsertMetric("memory") - item.InsertLable("type",colName) - item.InsertLable("hostname",GetHostname()) - item.InsertLable("cpu",string(cpuNumber)) + item.InsertLable("type", colName) + item.InsertLable("hostname", GetHostname()) + item.InsertLable("cpu", string(cpuNumber)) - item.InsertSample(timestamp,val) + item.InsertSample(timestamp, val) return item.ToJsonString() } - -func (self *MemoryGenerator) GenerateJsonArray(v *mem.VirtualMemoryStat,cpuNumber string) []string{ - timestamp := NowAsUnixMilli() - arr := []string{} - val := make(map[string]interface{}) - if err := json.Unmarshal([]byte(v.String()), &val) ; err!=nil { +func (self *MemoryGenerator) GenerateJsonArray(v *mem.VirtualMemoryStat, cpuNumber string) []string { + timestamp := NowAsUnixMilli() + arr := []string{} + val := make(map[string]interface{}) + if err := json.Unmarshal([]byte(v.String()), &val); err != nil { panic(err) } - for s,vl := range val{ - f ,_ := getFloat(vl) - arr = append(arr, self.GenerateJsonByVal(timestamp,s,f,cpuNumber)) - } + for s, vl := range val { + f, _ := getFloat(vl) + arr = append(arr, self.GenerateJsonByVal(timestamp, s, f, cpuNumber)) + } return arr } - func GetHostname() string { name, err := os.Hostname() if err != nil { panic(err) } else { - return name } + return name + } } var floatType = reflect.TypeOf(float64(0)) diff --git a/tests/fakerGenerator_test.go b/testing/fakerGenerator_test.go similarity index 76% rename from tests/fakerGenerator_test.go rename to testing/fakerGenerator_test.go index 65b80d0..fed39fe 100644 --- a/tests/fakerGenerator_test.go +++ b/testing/fakerGenerator_test.go @@ -1,19 +1,20 @@ -package tests +package testing import ( "fmt" "github.com/v3io/http_blaster/httpblaster/data_generator" "testing" + "time" ) func Test_facker_generator(t *testing.T) { gen := data_generator.Fake{} - gen.GenerateRandomData() + gen.GenerateRandomData(time.Now()) } func Test_facker_generator_to_igzemditem(t *testing.T) { gen := data_generator.Fake{} - gen.GenerateRandomData() + gen.GenerateRandomData(time.Now()) str := gen.ConvertToIgzEmdItemJson() fmt.Println(str) } diff --git a/tests/memoryGenerator_test.go b/testing/memoryGenerator_test.go similarity index 68% rename from tests/memoryGenerator_test.go rename to testing/memoryGenerator_test.go index 9695327..f7f8ccb 100644 --- a/tests/memoryGenerator_test.go +++ b/testing/memoryGenerator_test.go @@ -1,11 +1,14 @@ -package tests +package testing import ( + //"fmt" "github.com/v3io/http_blaster/httpblaster/data_generator" + //"strings" "testing" ) func Test_memeory_generator(t *testing.T) { gen := data_generator.MemoryGenerator{} gen.GenerateRandomData("1") + //fmt.Println("["+strings.Join(payloads, ", ")+"]") } diff --git a/tests/utils_test.go b/testing/utils_test.go similarity index 59% rename from tests/utils_test.go rename to testing/utils_test.go index ae03c23..769efde 100644 --- a/tests/utils_test.go +++ b/testing/utils_test.go @@ -1,28 +1,25 @@ -package tests +package testing import ( "github.com/v3io/http_blaster/httpblaster/utils" "testing" + "time" ) -func Test_utils_print(t *testing.T) { - utils.PrintTime() -} - func Test_utils_generate_year_partitioned_request(t *testing.T) { - str := utils.GeneratePartitionedRequest("year") + str := utils.GeneratePartitionedRequest("year", time.Now()) print(str) } func Test_utils_generate_month_partitioned_request(t *testing.T) { - str := utils.GeneratePartitionedRequest("month") + str := utils.GeneratePartitionedRequest("month", time.Now()) print(str) } func Test_utils_generate_day_partitioned_request(t *testing.T) { - str := utils.GeneratePartitionedRequest("day") + str := utils.GeneratePartitionedRequest("day", time.Now()) print(str) } func Test_utils_generate_hour_partitioned_request(t *testing.T) { - str := utils.GeneratePartitionedRequest("hour") + str := utils.GeneratePartitionedRequest("hour", time.Now()) print(str) } diff --git a/tests/igz_tsdb_item_test.go b/tests/igz_tsdb_item_test.go deleted file mode 100644 index faed6df..0000000 --- a/tests/igz_tsdb_item_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package tests - -import ( - "github.com/v3io/http_blaster/httpblaster/igz_data" - "testing" -) - -var item2 = igz_data.IgzEmdItem{} - -//var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") -//var metric = randSeq(10) -//var lables = map[string]string{"dc": "7", "hostname": "myhosts"} -//var timestamp = NowAsUnixMilli() -//var float_val = randFloat(0,rand.Float64()) -//var lable_key = "lable" -//var lable_val = "lable_value" - -//func init() { -// item2.InsertMetric(metric) -// item2.InsertLable(lable_key,lable_val) -// item2.InsertSample(timestamp, float_val) -// -// fmt.Println(item2.Samples) -// /* load test data */ -//} -// -//func Test_igz_tsdb_item_v2_init(t *testing.T) { -// assert.Equal(t, metric, item2.Metric, "they should be equal") -//} -// -//func Test_igz_tsdb_item_v2_lables(t *testing.T) { -// assert.Equal(t, lable_val, item2.Labels[lable_key], "they should be equal") -//} -// -//func Test_igz_tsdb_item_v2_sample(t *testing.T) { -// assert.Equal(t, timestamp, item2.Samples[0].T, "they should be equal") -// assert.Equal(t, float_val, item2.Samples[0].V["n"], "they should be equal") -//} - -func Test__igz_tsdb_item_v2_convert(t *testing.T) { - print(item2.ToJsonString()) -} - -//func NowAsUnixMilli() string { -// ts := time.Now().UnixNano() / 1e6 -// ts_str := strconv.FormatInt(ts, 10) -// return ts_str -//} -// -//func randSeq(n int) string { -// b := make([]rune, n) -// for i := range b { -// b[i] = letters[rand.Intn(len(letters))] -// } -// return string(b) -//} -// -//func randFloat(min, max float64) float64 { -// res := min + rand.Float64() * (max - min) -// return res -//}