mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Add version checkin (#2413)
* Initial commit of code to do a version check-in on startup * Add json tag to the response struct for version check * Adjusted version check response types * Changed error message in version check-in goroutine to use the logger. Changed URL to prod from dev. * Updated version checkin URL to be analytics Co-authored-by: Fletcher Haynes <fletcher.haynes@featurebase.com>
This commit is contained in:
parent
7386f13159
commit
c38210bef5
2 changed files with 72 additions and 0 deletions
12
server.go
12
server.go
|
|
@ -603,6 +603,18 @@ func (s *Server) Open() error {
|
|||
log.Println(errors.Wrap(err, "logging startup"))
|
||||
}
|
||||
|
||||
// Do version check in. This is in a goroutine so that we don't block server startup if the server endpoint is down/having issues.
|
||||
go func() {
|
||||
s.logger.Printf("Beginning featurebase version check-in")
|
||||
vc := VersionChecker{URL: "https://analytics.featurebase.com/v2/featurebase/version"}
|
||||
resp, err := vc.CheckIn()
|
||||
if err != nil {
|
||||
s.logger.Errorf("doing version checkin. Error was %s", err)
|
||||
return
|
||||
}
|
||||
s.logger.Printf("Version check-in complete. Latest version is %s", resp.Information.Version)
|
||||
}()
|
||||
|
||||
// Start DisCo.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||
defer cancel()
|
||||
|
|
|
|||
60
verchk.go
Normal file
60
verchk.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package pilosa
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type VersionChecker struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
func NewVersionChecker(endpoint string) *VersionChecker {
|
||||
v := VersionChecker{
|
||||
URL: endpoint,
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
func (v *VersionChecker) CheckIn() (*Response, error) {
|
||||
|
||||
body := make(map[string]string, 2)
|
||||
body["entry_type"] = "user"
|
||||
body["version"] = VersionInfo(true)
|
||||
req, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = http.Post(v.URL, "application/json", bytes.NewBuffer(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var json_resp Response
|
||||
r, err := http.Get(v.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &json_resp)
|
||||
if err != nil {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
return &json_resp, nil
|
||||
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Information InfoSubResponse `json:"info"`
|
||||
}
|
||||
|
||||
type InfoSubResponse struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue