这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
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 docker/data/bosun.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ EnableReload = true

# Configuration to enable the OpenTSDB Backend
[OpenTSDBConf]
Host = "opentsdb:4242"
Host = "http://opentsdb:4242"
# Default is 2.1, certain features like filters are enabled when the version is set to 2.2
Version = 2.2
# ResponseLimit will make requests error if the response from opentsdb is larger than this setting in bytes. Default of 1MB
Expand Down
4 changes: 3 additions & 1 deletion docs/system_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ Bosun's UI by using the Expression tab.

#### Host
OpenTSDB hostname and port to connect to.
Since 0.9.0 this can be specified with a scheme.
e.g. https://tsdb-querier:4242

#### Version
Either 2.1 or 2.2. Default: 2.1. If set to 2.2, certain features that
Expand All @@ -407,7 +409,7 @@ This does not cancel the query with OpenTSDB, but Bosun will stop processing the

```
[OpenTSDBConf]
Host = "ny-tsdb01:4242"
Host = "https://ny-tsdb01:4242"
Version = 2.2
ResponseLimit = 25000000
```
Expand Down
11 changes: 11 additions & 0 deletions opentsdb/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,22 @@ var DefaultClient = &http.Client{
// QueryResponse performs a v2 OpenTSDB request to the given host. host should
// be of the form hostname:port. A nil client uses DefaultClient.
func (r *Request) QueryResponse(host string, client *http.Client) (*http.Response, error) {

u := url.URL{
Scheme: "http",
Host: host,
Path: "/api/query",
}

pu, err := url.Parse(host)
if err == nil && pu.Scheme != "" && pu.Host != "" {
u.Scheme = pu.Scheme
u.Host = pu.Host
if pu.Path != "" {
u.Path = pu.Path
}
}

b, err := json.Marshal(&r)
if err != nil {
return nil, err
Expand Down
50 changes: 50 additions & 0 deletions opentsdb/tsdb_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package opentsdb

import (
"bytes"
"io/ioutil"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
)

func TestClean(t *testing.T) {
Expand Down Expand Up @@ -433,6 +439,50 @@ func TestReplace(t *testing.T) {
}
}

// RoundTripFunc .
type RoundTripFunc func(req *http.Request) *http.Response

// RoundTrip .
func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), nil
}

//NewTestClient returns *http.Client with Transport replaced to avoid making real calls
func NewTestClient(fn RoundTripFunc) *http.Client {
return &http.Client{
Transport: RoundTripFunc(fn),
}
}

func TestQueryResponseUrlParsing(t *testing.T) {

tests := []struct {
raw string
URL url.URL
}{
{"localhost:4242", url.URL{Scheme: "http", Host: "localhost:4242", Path: "/api/query"}},
{"127.0.0.1:4444", url.URL{Scheme: "http", Host: "127.0.0.1:4444", Path: "/api/query"}},
{"https://tsdb.skyscanner.net:4242", url.URL{Scheme: "https", Host: "tsdb.skyscanner.net:4242", Path: "/api/query"}},
}

r := Request{}
stockResponse := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)),
Header: make(http.Header),
}

for _, test := range tests {
client := NewTestClient(func(req *http.Request) *http.Response {
assert.Equal(t, test.URL, *req.URL)
return &stockResponse
})
_, _ = r.QueryResponse(test.raw, client)

}

}

func BenchmarkReplace_Noop(b *testing.B) {
for i := 0; i < b.N; i++ {
Replace("abcdefghijklmnopqrstuvwxyz", "")
Expand Down