Ejemplo n.º 1
0
	. "github.com/onsi/gomega"

	"bonitosrv/testdata"
)

var _ = Describe("GenGen Timerange", func() {
	Context("Simple fixed string generation", func() {
		var gen *testdata.GenGen
		BeforeEach(func() {
			var err error
			gen, err = testdata.NewGenGen(testdata.GenGenOptions{
				Samples: 10,
				Specs: []map[string]testdata.GenGenSpec{
					map[string]testdata.GenGenSpec{
						"service": testdata.GenGenSpec{
							Fixed: &testdata.FixedOptions{
								Value: "Service 0",
							},
						},
					},
				},
			})

			Expect(err).NotTo(HaveOccurred())
		})

		It("should generate 10 point", func() {
			lst := gen.GenerateList()
			Expect(lst).To(HaveLen(10))
		})

		It("should generate the same value for all", func() {
Ejemplo n.º 2
0
	"bonitosrv/testdata"
)

var _ = Describe("GenGen Choice", func() {
	Context("Simple choice loop generation", func() {
		var gen *testdata.GenGen
		BeforeEach(func() {
			var err error
			gen, err = testdata.NewGenGen(testdata.GenGenOptions{
				Samples: 10,
				Specs: []map[string]testdata.GenGenSpec{
					map[string]testdata.GenGenSpec{
						"host": testdata.GenGenSpec{
							Choice: &testdata.ChoiceOptions{
								Values: []interface{}{"Host1", "Host2", "Host3"},
								Type:   "loop",
							},
						},
					},
				},
			})

			Expect(err).NotTo(HaveOccurred())
		})

		It("should generate 10 points", func() {
			lst := gen.GenerateList()
			Expect(lst).To(HaveLen(10))
		})
Ejemplo n.º 3
0
)

var _ = Describe("GenGen Timerange", func() {
	Context("Simple timestamps generation", func() {
		var gen *testdata.GenGen
		to := time.Now()
		from := to.Add(-1 * time.Minute)
		BeforeEach(func() {
			var err error
			gen, err = testdata.NewGenGen(testdata.GenGenOptions{
				Samples: 100,
				Specs: []map[string]testdata.GenGenSpec{
					map[string]testdata.GenGenSpec{
						"ts": testdata.GenGenSpec{
							Timerange: &testdata.TimerangeOptions{
								From: from,
								To:   to,
							},
						},
					},
				},
			})

			Expect(err).NotTo(HaveOccurred())
		})

		It("should generate 100 point", func() {
			lst := gen.GenerateList()
			Expect(lst).To(HaveLen(100))
		})
Ejemplo n.º 4
0
			gen, err = testdata.NewGenGen(testdata.GenGenOptions{
				Samples: 100,
				Specs: []map[string]testdata.GenGenSpec{
					map[string]testdata.GenGenSpec{
						"ts": testdata.GenGenSpec{
							Timerange: &testdata.TimerangeOptions{
								From: from,
								To:   to,
							},
						},
						"service": testdata.GenGenSpec{
							Fixed: &testdata.FixedOptions{
								Value: "Service 0",
							},
						},
					},
					map[string]testdata.GenGenSpec{
						"ts": testdata.GenGenSpec{
							Timerange: &testdata.TimerangeOptions{
								From: from,
								To:   to,
							},
						},
						"service": testdata.GenGenSpec{
							Fixed: &testdata.FixedOptions{
								Value: "Service 1",
							},
						},
					},
				},
			})
Ejemplo n.º 5
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"bonitosrv/testdata"
)

var _ = Describe("GenGen Eventful", func() {
	Context("Integer non-randomized generation", func() {
		It("Should generate the correct values for peak", func() {
			gen, err := testdata.NewGenGen(testdata.GenGenOptions{
				Samples: 10,
				Specs: []map[string]testdata.GenGenSpec{
					map[string]testdata.GenGenSpec{
						"count": testdata.GenGenSpec{
							Eventful: &testdata.EventfulOptions{
								Type:       "peak",
								Value:      20,
								Integerify: true,
							},
						},
					},
				},
			})
			Expect(err).NotTo(HaveOccurred())

			lst := gen.GenerateList()
			counts := []int32{}
			for _, el := range lst {
				counts = append(counts, el["count"].(int32))
			}

			Expect(counts).To(Equal([]int32{20, 20, 20, 40, 20, 20, 20, 20, 20, 20}))
Ejemplo n.º 6
0
Archivo: gen.go Proyecto: sk163/bonito
func main() {
	to := time.Now()
	from := to.Add(-1 * time.Hour)

	samples := 100
	options := gengenOptionsForServices(samples, to, from)
	gen, err := testdata.NewGenGen(*options)
	if err != nil {
		fmt.Println(err)
		return
	}

	transChan := make(chan testdata.TestTransaction, 100)

	index_name := "packetbeat-test"
	es := elasticsearch.NewElasticsearch()

	// make sure we start fresh
	_, err = es.DeleteIndex(index_name)
	if err != nil {
		fmt.Println("Error: ", err)
		return
	}

	// create index with custom settings
	resp, err := es.Request("PUT", index_name, "", bytes.NewBufferString(
		`{"settings": {"index": {"refresh_interval": "-1"}}}`,
	))
	if err != nil {
		fmt.Println(elasticsearch.ResponseBody(resp))
		fmt.Println("Error: ", err)
		return
	}

	// generate in channel
	go func() {
		for i := 0; i < samples; i++ {
			for _, trans := range gen.Generate(i) {
				transChan <- testdata.TestTransaction{
					Timestamp:    elasticsearch.Time(trans["timestamp"].(time.Time)),
					Service:      trans["service"].(string),
					Host:         trans["host"].(string),
					Count:        int(trans["count"].(float64)),
					Responsetime: trans["responsetime"].(int),
					Status:       trans["status"].(string),
				}
			}
		}
		close(transChan)
	}()

	inserted, err := testdata.InsertInEsFromChan(es, index_name, transChan)
	if err != nil {
		fmt.Println("Error: ", err)
	}

	fmt.Printf("%d transactions inserted into %s\n", inserted, index_name)

	// set back the refreshing interval
	_, err = es.Request("PUT", index_name, "_settings", bytes.NewBufferString(
		`{"index": {"refresh_interval": "1s"}}`,
	))
	if err != nil {
		fmt.Println("Error: ", err)
	}
}