Skip to content

Commit

Permalink
Merged pull request influxdata#1542 from bonitoo-io/vh-fix#916
Browse files Browse the repository at this point in the history
Fix of the Kapacitor crash on windows when starting recording: issues influxdata#902, influxdata#916
  • Loading branch information
nathanielc committed Sep 8, 2017
2 parents d571d95 + 9cb96bb commit d36f371
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

### Bugfixes

- [#916](https://github.com/influxdata/kapacitor/issues/916): Crash of Kapacitor on Windows x64 when starting a recording
- [#1400](https://github.com/influxdata/kapacitor/issues/1400): Allow for `.yml` file extensions in `define-topic-handler`
- [#1402](https://github.com/influxdata/kapacitor/pull/1402): Fix http server error logging.
- [#1500](https://github.com/influxdata/kapacitor/pull/1500): Fix bugs with stopping running UDF agent.
Expand Down
11 changes: 11 additions & 0 deletions server/server_const_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !windows

//Platform dependent constants for non-windows
package server_test

const (
ExecutableSuffix = ""
PythonExecutable = "python2"
LogFileExpectedMode = 0604
AlertLogPath = `/var/log/alert.log`
)
11 changes: 11 additions & 0 deletions server/server_const_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build windows

//Platform dependent constants for tests on windows
package server_test

const (
ExecutableSuffix = ".exe"
PythonExecutable = "python"
LogFileExpectedMode = 0666
AlertLogPath = `c:\alert.log`
)
39 changes: 21 additions & 18 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -2970,7 +2970,7 @@ test value=1 0000000012
t.Errorf("replay failed: %s", replay.Error)
}

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3173,7 +3173,7 @@ func TestServer_RecordReplayBatch(t *testing.T) {
}
}

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3386,7 +3386,7 @@ func TestServer_ReplayBatch(t *testing.T) {
}
}

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3639,7 +3639,7 @@ func TestServer_RecordReplayQuery(t *testing.T) {
}
}

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3923,7 +3923,7 @@ func TestServer_ReplayQuery(t *testing.T) {
}
}

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -4249,7 +4249,7 @@ func TestServer_RecordReplayQuery_Missing(t *testing.T) {

// Validate we got the data in the alert.log

f, err := os.Open(path.Join(tmpDir, "alert.log"))
f, err := os.Open(filepath.Join(tmpDir, "alert.log"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -4533,7 +4533,7 @@ func TestServer_UDFStreamAgents(t *testing.T) {
"go",
"build",
"-o",
filepath.Join(tdir, "movavg"),
filepath.Join(tdir, "movavg"+ExecutableSuffix),
filepath.Join(udfDir, "agent/examples/moving_avg/moving_avg.go"),
)
out, err := cmd.CombinedOutput()
Expand All @@ -4552,7 +4552,7 @@ func TestServer_UDFStreamAgents(t *testing.T) {
{
buildFunc: func() error { return nil },
config: udf.FunctionConfig{
Prog: "python2",
Prog: PythonExecutable,
Args: []string{"-u", filepath.Join(udfDir, "agent/examples/moving_avg/moving_avg.py")},
Timeout: toml.Duration(time.Minute),
Env: map[string]string{
Expand Down Expand Up @@ -4673,6 +4673,9 @@ test,group=b value=0 0000000011
// If this test fails due to missing python dependencies, run 'INSTALL_PREFIX=/usr/local ./install-deps.sh' from the root directory of the
// kapacitor project.
func TestServer_UDFStreamAgentsSocket(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on windows as unix sockets are not available")
}
tdir, err := ioutil.TempDir("", "kapacitor_server_test")
if err != nil {
t.Fatal(err)
Expand All @@ -4690,7 +4693,7 @@ func TestServer_UDFStreamAgentsSocket(t *testing.T) {
"go",
"build",
"-o",
filepath.Join(tdir, "mirror"),
filepath.Join(tdir, "mirror"+ExecutableSuffix),
filepath.Join(udfDir, "agent/examples/mirror/mirror.go"),
)
out, err := cmd.CombinedOutput()
Expand All @@ -4714,7 +4717,7 @@ func TestServer_UDFStreamAgentsSocket(t *testing.T) {
{
startFunc: func() *exec.Cmd {
cmd := exec.Command(
"python2",
PythonExecutable,
"-u",
filepath.Join(udfDir, "agent/examples/mirror/mirror.py"),
filepath.Join(tdir, "mirror.py.sock"),
Expand Down Expand Up @@ -4855,7 +4858,7 @@ func TestServer_UDFBatchAgents(t *testing.T) {
"go",
"build",
"-o",
filepath.Join(tdir, "outliers"),
filepath.Join(tdir, "outliers"+ExecutableSuffix),
filepath.Join(udfDir, "agent/examples/outliers/outliers.go"),
)
out, err := cmd.CombinedOutput()
Expand All @@ -4874,7 +4877,7 @@ func TestServer_UDFBatchAgents(t *testing.T) {
{
buildFunc: func() error { return nil },
config: udf.FunctionConfig{
Prog: "python2",
Prog: PythonExecutable,
Args: []string{"-u", filepath.Join(udfDir, "agent/examples/outliers/outliers.py")},
Timeout: toml.Duration(time.Minute),
Env: map[string]string{
Expand Down Expand Up @@ -7946,15 +7949,15 @@ func TestServer_AlertHandlers_CRUD(t *testing.T) {
{
Path: "/options/path",
Operation: "add",
Value: "/var/log/alert.log",
Value: AlertLogPath,
},
},
expPatch: client.TopicHandler{
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1preview/alerts/topics/system/handlers/myhandler"},
ID: "myhandler",
Kind: "log",
Options: map[string]interface{}{
"path": "/var/log/alert.log",
"path": AlertLogPath,
},
},
put: client.TopicHandlerOptions{
Expand Down Expand Up @@ -8189,7 +8192,7 @@ func TestServer_AlertHandlers(t *testing.T) {
},
setup: func(c *server.Config, ha *client.TopicHandler) (context.Context, error) {
tdir := MustTempDir()
p := path.Join(tdir, "alert.log")
p := filepath.Join(tdir, "alert.log")

ha.Options["path"] = p

Expand All @@ -8204,7 +8207,7 @@ func TestServer_AlertHandlers(t *testing.T) {
defer os.RemoveAll(tdir)
l := ctxt.Value("log").(*alerttest.Log)
expData := []alert.Data{alertData}
expMode := os.FileMode(0604)
expMode := os.FileMode(LogFileExpectedMode)

m, err := l.Mode()
if err != nil {
Expand Down Expand Up @@ -9464,7 +9467,7 @@ func TestServer_AlertTopic_PersistedState(t *testing.T) {

tmpDir := MustTempDir()
defer os.RemoveAll(tmpDir)
tmpPath := path.Join(tmpDir, "alert.log")
tmpPath := filepath.Join(tmpDir, "alert.log")

// Create default config
c := NewConfig()
Expand Down
12 changes: 9 additions & 3 deletions services/replay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (s *Service) syncRecordingMetadata() error {
}
dataUrl := url.URL{
Scheme: "file",
Path: filepath.Join(s.saveDir, info.Name()),
Path: filepath.ToSlash(filepath.Join(s.saveDir, info.Name())),
}
recording := Recording{
ID: id,
Expand Down Expand Up @@ -578,7 +578,7 @@ func (s *Service) handleDeleteRecording(w http.ResponseWriter, r *http.Request)
func (s *Service) dataURLFromID(id, ext string) url.URL {
return url.URL{
Scheme: "file",
Path: filepath.Join(s.saveDir, id+ext),
Path: filepath.ToSlash(filepath.Join(s.saveDir, id+ext)),
}
}

Expand Down Expand Up @@ -1637,12 +1637,18 @@ func parseDataSourceURL(rawurl string) (DataSource, error) {
}
switch u.Scheme {
case "file":
return fileSource(u.Path), nil
return fileSource(getFilePathFromUrl(u)), nil
default:
return nil, fmt.Errorf("unsupported data source scheme %s", u.Scheme)
}
}

//getFilePathFromUrl restores filesystem path from file URL
func getFilePathFromUrl(url *url.URL) string {
//Host part on windows contains drive, on non windows it is empty
return url.Host + filepath.FromSlash(url.Path)
}

func (s fileSource) Size() (int64, error) {
info, err := os.Stat(string(s))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tick/cmd/tickdoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"html"
"log"
"os"
"path"
"path/filepath"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -139,7 +139,7 @@ func main() {
weight = w
}
n.Render(&buf, r, nodes, weight)
filename := path.Join(out, snaker.CamelToSnake(name)+".md")
filename := filepath.Join(out, snaker.CamelToSnake(name)+".md")
log.Println("Writing file:", filename, i)
f, err := os.Create(filename)
if err != nil {
Expand Down

0 comments on commit d36f371

Please sign in to comment.