Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug-fixing: http probe report the unsupported document type #235

Merged
merged 3 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// refer to https://github.com/golang/go/issues/51442
// using the workaround to remove the directory by a retry loop
func removeDir(dir string) {
for i := 0; i < 10; i++ {
for i := 0; i < 100; i++ {
if err := os.RemoveAll(dir); err == nil {
return
}
Expand Down
7 changes: 5 additions & 2 deletions probe/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ func (h *HTTP) Config(gConf global.ProbeSettings) error {
return err
}

if err := h.Evaluator.Config(); err != nil {
return err
// if the evaluator is set, config it
if h.Evaluator.DocType != eval.Unsupported && len(strings.TrimSpace(h.Evaluator.Expression)) > 0 {
if err := h.Evaluator.Config(); err != nil {
return err
}
}

h.metrics = newMetrics(kind, tag)
Expand Down
24 changes: 23 additions & 1 deletion probe/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package http

import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"reflect"
"testing"

Expand All @@ -33,6 +35,7 @@ import (
"github.com/megaease/easeprobe/global"
"github.com/megaease/easeprobe/probe"
"github.com/megaease/easeprobe/probe/base"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -68,9 +71,28 @@ func createHTTP() *HTTP {
},
}
}

func createSimpleHTTP() *HTTP {
return &HTTP{
DefaultProbe: base.DefaultProbe{ProbeName: "dummy http"},
URL: "http://localhost:8888",
ContentEncoding: "text/json",
Headers: map[string]string{"header1": "value1", "header2": "value2", "Host": "host.com"},
Body: "{ \"key1\": \"value1\", \"key2\": \"value2\" }",
}
}

func TestHTTPConfig(t *testing.T) {
h := createHTTP()
h := createSimpleHTTP()
var buf bytes.Buffer
log.SetOutput(&buf)
err := h.Config(global.ProbeSettings{})
assert.NoError(t, err)
assert.NotContains(t, buf.String(), "Unsupported document type")
log.SetOutput(os.Stdout)

h = createHTTP()
err = h.Config(global.ProbeSettings{})
assert.Error(t, err)

//TLS config success
Expand Down