Skip to content

Commit

Permalink
add tests for user actions and basic stream/batch tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Nov 17, 2015
1 parent d948afd commit 761641e
Show file tree
Hide file tree
Showing 16 changed files with 854 additions and 58 deletions.
14 changes: 7 additions & 7 deletions cmd/kapacitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// These variables are populated via the Go linker.
var (
version string = "v0.1"
version string
commit string
branch string
)
Expand Down Expand Up @@ -228,15 +228,15 @@ Examples:
This records the live data stream for 1 minute using the databases and retention policies
from the named task.
$ kapacitor record batch -name cpu_idle -start 2015-09-01T00:00:00Z -stop 2015-09-02T00:00:00Z
This records the result of the query defined in task 'cpu_idle' and runs the query as many times
as many times as defined by the schedule until the queries reaches the stop time.
starting at time 'start' and incrementing by the schedule defined in the task.
$ kapacitor record batch -name cpu_idle -past 10h
This records the result of the query defined in task 'cpu_idle' and runs the query
as many times as defined by the schedule until the queries reaches the present time.
The starting time for the queries is 'now - 10h' and increments by the schedule defined in the task.
Expand Down Expand Up @@ -379,7 +379,7 @@ For example:
$ kapacitor define -name my_task -tick path/to/TICKscript -type stream -dbrp mydb.myrp
Later you can change a sinlge property of the task by referencing its name
Later you can change a sinlge property of the task by referencing its name
and only providing the single option you wish to modify.
$ kapacitor define -name my_task -tick path/to/TICKscript
Expand Down Expand Up @@ -613,7 +613,7 @@ func doShow(args []string) error {
}

v := url.Values{}
v.Add("task", args[0])
v.Add("name", args[0])
r, err := http.Get(*kapacitordURL + "/task?" + v.Encode())
if err != nil {
return err
Expand Down Expand Up @@ -736,7 +736,7 @@ func deleteUsage() {
var u = `Usage: kapacitor delete (tasks|recordings) [task name|recording ID]...
Delete a task or recording.
If a task is enabled it will be disabled and then deleted.
`
fmt.Fprintln(os.Stderr, u)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kapacitord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// These variables are populated via the Go linker.
var (
version string = "v0.1"
version string
commit string
branch string
)
Expand Down
3 changes: 1 addition & 2 deletions cmd/kapacitord/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ func (cmd *Command) Run(args ...string) error {

// Create server from config and start it.
buildInfo := &BuildInfo{Version: cmd.Version, Commit: cmd.Commit, Branch: cmd.Branch}
l := cmd.logService.NewLogger("[srv] ", log.LstdFlags)
s, err := NewServer(config, buildInfo, l, cmd.logService)
s, err := NewServer(config, buildInfo, cmd.logService)
if err != nil {
return fmt.Errorf("create server: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kapacitord/run/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func NewDemoConfig() (*Config, error) {

c.Replay.Dir = filepath.Join(homeDir, ".kapacitor", c.Replay.Dir)
c.Task.Dir = filepath.Join(homeDir, ".kapacitor", c.Task.Dir)

c.DataDir = filepath.Join(homeDir, ".kapacitor", c.DataDir)

return c, nil
}

Expand Down
53 changes: 30 additions & 23 deletions cmd/kapacitord/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ import (
const clusterIDFilename = "cluster.id"
const serverIDFilename = "server.id"

var (
//Published vars
cidVar = &expvar.String{}

sidVar = &expvar.String{}

hostVar = &expvar.String{}

productVar = &expvar.String{}

versionVar = &expvar.String{}
)

func init() {
expvar.Publish(kapacitor.ClusterIDVarName, cidVar)
expvar.Publish(kapacitor.ServerIDVarName, sidVar)
expvar.Publish(kapacitor.HostVarName, hostVar)
expvar.Publish(kapacitor.ProductVarName, productVar)
expvar.Publish(kapacitor.VersionVarName, versionVar)
}

// BuildInfo represents the build details for the server code.
type BuildInfo struct {
Version string
Expand All @@ -55,7 +76,7 @@ type Server struct {

TaskMaster *kapacitor.TaskMaster

LogService *logging.Service
LogService logging.Interface
HTTPDService *httpd.Service
Streamer *streamer.Service
TaskStore *task_store.Service
Expand All @@ -79,8 +100,8 @@ type Server struct {
}

// NewServer returns a new instance of Server built from a config.
func NewServer(c *Config, buildInfo *BuildInfo, l *log.Logger, logService *logging.Service) (*Server, error) {

func NewServer(c *Config, buildInfo *BuildInfo, logService logging.Interface) (*Server, error) {
l := logService.NewLogger("[srv] ", log.LstdFlags)
s := &Server{
buildInfo: *buildInfo,
dataDir: c.DataDir,
Expand Down Expand Up @@ -272,26 +293,12 @@ func (s *Server) Open() error {
return err
}

// Publish Vars
cid := &expvar.String{}
cid.Set(s.ClusterID)
expvar.Publish(kapacitor.ClusterIDVarName, cid)

sid := &expvar.String{}
sid.Set(s.ServerID)
expvar.Publish(kapacitor.ServerIDVarName, sid)

host := &expvar.String{}
host.Set(s.hostname)
expvar.Publish(kapacitor.HostVarName, host)

product := &expvar.String{}
product.Set(kapacitor.Product)
expvar.Publish(kapacitor.ProductVarName, product)

version := &expvar.String{}
version.Set(s.buildInfo.Version)
expvar.Publish(kapacitor.VersionVarName, version)
// Set published vars
cidVar.Set(s.ClusterID)
sidVar.Set(s.ServerID)
hostVar.Set(s.hostname)
productVar.Set(kapacitor.Product)
versionVar.Set(s.buildInfo.Version)

// Start profiling, if set.
s.startProfile(s.CPUProfile, s.MemProfile)
Expand Down
Loading

0 comments on commit 761641e

Please sign in to comment.