예제 #1
0
func validateTasks(tb testing.TB, tm *kapacitor.TaskMaster, tasks []*kapacitor.ExecutingTask, expectedProcessedCount int) {
	for _, task := range tasks {
		if !tm.IsExecuting(task.Task.ID) {
			tb.Fatalf("task %s failed", task.Task.ID)
		}
		stats, err := tm.ExecutionStats(task.Task.ID)
		if err != nil {
			tb.Fatal(err)
		}
		if got, exp := stats.NodeStats["stream0"]["collected"], int64(expectedProcessedCount); got != exp {
			tb.Fatalf("task %s didn't process correct amount of points: got %d exp %d", task.Task.ID, got, exp)
		}
	}
}
예제 #2
0
func fastForwardTask(
	clock clock.Setter,
	et *kapacitor.ExecutingTask,
	replayErr <-chan error,
	tm *kapacitor.TaskMaster,
	duration time.Duration,
) error {
	// Move time forward
	clock.Set(clock.Zero().Add(duration))
	// Wait till the replay has finished
	if err := <-replayErr; err != nil {
		return err
	}
	tm.Drain()
	// Wait till the task is finished
	if err := et.Err(); err != nil {
		return err
	}
	return nil
}
예제 #3
0
func createTasks(tb testing.TB, tm *kapacitor.TaskMaster, count int, tickScript string, dbrps []kapacitor.DBRP) []*kapacitor.ExecutingTask {
	tasks := make([]*kapacitor.ExecutingTask, count)
	for i := 0; i < count; i++ {
		task, err := tm.NewTask(
			fmt.Sprintf("task_%v", i),
			tickScript,
			kapacitor.StreamTask,
			dbrps,
			0,
			nil,
		)
		if err != nil {
			tb.Fatal(err)
		}

		tasks[i], err = tm.StartTask(task)
		if err != nil {
			tb.Fatal(err)
		}
	}
	return tasks
}
예제 #4
0
func (ts *Service) convertTask(t Task, scriptFormat, dotView string, tm *kapacitor.TaskMaster) (client.Task, error) {
	script := t.TICKscript
	if scriptFormat == "formatted" {
		// Format TICKscript
		formatted, err := tick.Format(script)
		if err == nil {
			// Only format if it succeeded.
			// Otherwise a change in syntax may prevent task retrieval.
			script = formatted
		}
	}

	executing := tm.IsExecuting(t.ID)
	errMsg := t.Error
	dot := ""
	stats := client.ExecutionStats{}
	task, err := ts.newKapacitorTask(t)
	if err == nil {
		if executing {
			dot = tm.ExecutingDot(t.ID, dotView == "labels")
			s, err := tm.ExecutionStats(t.ID)
			if err != nil {
				ts.logger.Printf("E! failed to retrieve stats for task %s: %v", t.ID, err)
			} else {
				stats.TaskStats = s.TaskStats
				stats.NodeStats = s.NodeStats
			}
		} else {
			dot = string(task.Dot())
		}
	} else {
		errMsg = err.Error()
	}

	var status client.TaskStatus
	switch t.Status {
	case Disabled:
		status = client.Disabled
	case Enabled:
		status = client.Enabled
	default:
		return client.Task{}, fmt.Errorf("invalid task status %v", t.Status)
	}

	var typ client.TaskType
	switch t.Type {
	case StreamTask:
		typ = client.StreamTask
	case BatchTask:
		typ = client.BatchTask
	default:
		return client.Task{}, fmt.Errorf("invalid task type %v", t.Type)
	}

	dbrps := make([]client.DBRP, len(t.DBRPs))
	for i, dbrp := range t.DBRPs {
		dbrps[i] = client.DBRP{
			Database:        dbrp.Database,
			RetentionPolicy: dbrp.RetentionPolicy,
		}
	}

	vars, err := ts.convertToClientVars(t.Vars)
	if err != nil {
		return client.Task{}, err
	}

	return client.Task{
		Link:           ts.taskLink(t.ID),
		ID:             t.ID,
		TemplateID:     t.TemplateID,
		Type:           typ,
		DBRPs:          dbrps,
		TICKscript:     script,
		Vars:           vars,
		Status:         status,
		Dot:            dot,
		Executing:      executing,
		ExecutionStats: stats,
		Created:        t.Created,
		Modified:       t.Modified,
		LastEnabled:    t.LastEnabled,
		Error:          errMsg,
	}, nil
}