Ejemplo n.º 1
0
// SetVars sets up the environment for InsertStatement to call it's Run function
func (i *InsertStatement) SetVars(s *ponyExpress.StoreFront) chan<- string {
	// Set the #series at 1 to start
	i.series = 1

	// Num series is the product of the cardinality of the tags
	for _, tmpl := range i.Templates[0:i.TagCount] {
		i.series *= tmpl.numSeries()
	}

	// make stringers from the templates
	i.stringers = i.Templates.Init(i.series)

	// Set the time function, keeps track of 'time' of the points being created
	i.time = i.Timestamp.Time(s.StartDate, i.series, s.Precision)

	// Set a commune on the StoreFront
	s.Lock()
	comCh := s.SetCommune(i.Name)
	s.Unlock()

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	return comCh
}
Ejemplo n.º 2
0
func newTestInfluxQl() *InfluxqlStatement {
	return &InfluxqlStatement{
		Query:       "CREATE DATABASE foo",
		Tracer:      ponyExpress.NewTracer(make(map[string]string)),
		StatementID: "fooID",
	}
}
Ejemplo n.º 3
0
// Run statisfies the Statement Interface
func (i *QueryStatement) Run(s *ponyExpress.StoreFront) {

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	vals := make(map[string]interface{})

	var point models.Point

	runtime := time.Now()

	for j := 0; j < i.Count; j++ {

		// If the query is a simple query, send it.
		if len(i.Args) == 0 {
			b := []byte(i.TemplateString)

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		} else {
			// Otherwise cherry pick field values from the commune?

			// TODO: Currently the program lock up here if s.GetPoint
			//       cannot return a value, which can happen.
			// Seee insert.go
			s.Lock()
			point = s.GetPoint(i.Name, s.Precision)
			s.Unlock()

			setMapValues(vals, point)

			// Set the template string with args from the commune
			b := []byte(fmt.Sprintf(i.TemplateString, setArgs(vals, i.Args)...))

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		}
	}

	// Wait for all operations to finish
	i.Tracer.Wait()

	// Stop time timer
	i.runtime = time.Since(runtime)
}
Ejemplo n.º 4
0
func newTestSet(toSet, value string) *SetStatement {
	return &SetStatement{
		Var:         toSet,
		Value:       value,
		Tracer:      ponyExpress.NewTracer(make(map[string]string)),
		StatementID: "fooID",
	}
}
Ejemplo n.º 5
0
// Run statisfies the Statement Interface
func (i *SetStatement) Run(s *ponyExpress.StoreFront) {

	// Set the Tracer
	i.Tracer = ponyExpress.NewTracer(make(map[string]string))

	// Create a new Directive
	d := ponyExpress.NewDirective(strings.ToLower(i.Var), strings.ToLower(i.Value), i.Tracer)

	switch d.Property {

	// Needs to be set on both StoreFront and ponyExpress
	// Set the write percison for points generated
	case "precision":
		s.Precision = d.Value

		// Increment the tracer
		i.Tracer.Add(1)
		s.SendDirective(d)

	// Lives on StoreFront
	// Set the date for the first point entered into the database
	case "startdate":
		s.Lock()
		s.StartDate = d.Value
		s.Unlock()

	// Lives on StoreFront
	// Set the BatchSize for writes
	case "batchsize":
		s.Lock()
		s.BatchSize = parseInt(d.Value)
		s.Unlock()

	// Lives on StoreFront
	// Reset the ResultsClient to have a new address
	case "resultsaddress":
		s.Lock()
		s.SetResultsClient(influx.HTTPConfig{Addr: fmt.Sprintf("http://%v/", d.Value)})
		s.Unlock()

	// TODO: Make TestName actually change the reporting DB
	// Lives on StoreFront
	// Set the TestName that controls reporting DB
	case "testname":
		s.Lock()
		s.TestName = d.Value
		s.Unlock()

	// All other variables live on ponyExpress
	default:
		// Increment the tracer
		i.Tracer.Add(1)
		s.SendDirective(d)
	}
	i.Tracer.Wait()
}
Ejemplo n.º 6
0
func newTestQuery() *QueryStatement {
	return &QueryStatement{
		StatementID:    "foo_ID",
		Name:           "foo_name",
		TemplateString: "SELECT count(value) FROM cpu",
		Args:           []string{},
		Count:          5,
		Tracer:         ponyExpress.NewTracer(map[string]string{}),
	}
}
Ejemplo n.º 7
0
func blankResponse() ponyExpress.Response {
	// Points must have at least one field
	fields := map[string]interface{}{"done": true}
	// Make a 'blank' point
	p, err := influx.NewPoint("done", make(map[string]string), fields, time.Now())
	// Panic on error
	if err != nil {
		log.Fatalf("Error creating blank response point\n  error: %v\n", err)
	}
	// Add a tracer to prevent program from returning too early
	tracer := ponyExpress.NewTracer(make(map[string]string))
	// Add to the WaitGroup
	tracer.Add(1)
	// Make a new response with the point and the tracer
	resp := ponyExpress.NewResponse(p, tracer)
	return resp
}
Ejemplo n.º 8
0
// Run statisfies the Statement Interface
func (i *InfluxqlStatement) Run(s *ponyExpress.StoreFront) {

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	// Make the Package
	p := ponyExpress.NewPackage(ponyExpress.Query, []byte(i.Query), i.StatementID, i.Tracer)

	// Increment the tracer
	i.Tracer.Add(1)

	// Send the Package
	s.SendPackage(p)

	// Wait for all operations to finish
	i.Tracer.Wait()
}