diff --git a/common/xfer/constants.go b/common/xfer/constants.go index 4045b1414..3ae0c9e84 100644 --- a/common/xfer/constants.go +++ b/common/xfer/constants.go @@ -9,6 +9,9 @@ const ( // ScopeProbeIDHeader is the header we use to carry the probe's unique ID. The // ID is currently set to the a random string on probe startup. ScopeProbeIDHeader = "X-Scope-Probe-ID" + + // ScopeProbeVersionHeader is the header we use to carry the probe's version. + ScopeProbeVersionHeader = "X-Scope-Probe-Version" ) // Details are some generic details that can be fetched from /api diff --git a/probe/appclient/app_client_internal_test.go b/probe/appclient/app_client_internal_test.go index 21f96e568..4508f054b 100644 --- a/probe/appclient/app_client_internal_test.go +++ b/probe/appclient/app_client_internal_test.go @@ -18,7 +18,7 @@ import ( "github.com/weaveworks/scope/test" ) -func dummyServer(t *testing.T, expectedToken, expectedID string, expectedReport report.Report, done chan struct{}) *httptest.Server { +func dummyServer(t *testing.T, expectedToken, expectedID string, expectedVersion string, expectedReport report.Report, done chan struct{}) *httptest.Server { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if have := r.Header.Get("Authorization"); fmt.Sprintf("Scope-Probe token=%s", expectedToken) != have { t.Errorf("want %q, have %q", expectedToken, have) @@ -28,6 +28,10 @@ func dummyServer(t *testing.T, expectedToken, expectedID string, expectedReport t.Errorf("want %q, have %q", expectedID, have) } + if have := r.Header.Get(xfer.ScopeProbeVersionHeader); expectedVersion != have { + t.Errorf("want %q, have %q", expectedID, have) + } + var have report.Report reader := r.Body @@ -59,10 +63,11 @@ func dummyServer(t *testing.T, expectedToken, expectedID string, expectedReport func TestAppClientPublish(t *testing.T) { var ( - token = "abcdefg" - id = "1234567" - rpt = report.MakeReport() - done = make(chan struct{}, 10) + token = "abcdefg" + id = "1234567" + version = "0.18" + rpt = report.MakeReport() + done = make(chan struct{}, 10) ) // marshalling->unmarshaling is not idempotent due to `json:"omitempty"` @@ -89,7 +94,7 @@ func TestAppClientPublish(t *testing.T) { rpt.Host.Controls = nil rpt.Overlay.Controls = nil - s := dummyServer(t, token, id, rpt, done) + s := dummyServer(t, token, id, version, rpt, done) defer s.Close() u, err := url.Parse(s.URL) @@ -98,9 +103,10 @@ func TestAppClientPublish(t *testing.T) { } pc := ProbeConfig{ - Token: token, - ProbeID: id, - Insecure: false, + Token: token, + ProbeVersion: version, + ProbeID: id, + Insecure: false, } p, err := NewAppClient(pc, u.Host, s.URL, nil) diff --git a/probe/appclient/probe_config.go b/probe/appclient/probe_config.go index c0fcaf2eb..2b8493a62 100644 --- a/probe/appclient/probe_config.go +++ b/probe/appclient/probe_config.go @@ -24,14 +24,16 @@ func init() { // ProbeConfig contains all the info needed for a probe to do HTTP requests type ProbeConfig struct { - Token string - ProbeID string - Insecure bool + Token string + ProbeVersion string + ProbeID string + Insecure bool } func (pc ProbeConfig) authorizeHeaders(headers http.Header) { headers.Set("Authorization", fmt.Sprintf("Scope-Probe token=%s", pc.Token)) headers.Set(xfer.ScopeProbeIDHeader, pc.ProbeID) + headers.Set(xfer.ScopeProbeVersionHeader, pc.ProbeVersion) } func (pc ProbeConfig) authorizedRequest(method string, urlStr string, body io.Reader) (*http.Request, error) { diff --git a/prog/probe.go b/prog/probe.go index 2b0bd94f8..766692477 100644 --- a/prog/probe.go +++ b/prog/probe.go @@ -104,9 +104,10 @@ func probeMain(flags probeFlags) { log.Infof("publishing to: %s", strings.Join(targets, ", ")) probeConfig := appclient.ProbeConfig{ - Token: flags.token, - ProbeID: probeID, - Insecure: flags.insecure, + Token: flags.token, + ProbeVersion: version, + ProbeID: probeID, + Insecure: flags.insecure, } clients := appclient.NewMultiAppClient(func(hostname, endpoint string) (appclient.AppClient, error) { return appclient.NewAppClient(