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

Check response status when posting telemtry data. #4726

Merged
merged 2 commits into from
Feb 4, 2020
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 dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *Server) periodicallyPostTelemetry() {
glog.V(2).Infof("Starting telemetry data collection for zero...")
start := time.Now()

ticker := time.NewTicker(time.Minute)
ticker := time.NewTicker(time.Minute * 10)
defer ticker.Stop()

var lastPostedAt time.Time
Expand Down
2 changes: 1 addition & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func PeriodicallyPostTelemetry() {
glog.V(2).Infof("Starting telemetry data collection for alpha...")

start := time.Now()
ticker := time.NewTicker(time.Minute)
ticker := time.NewTicker(time.Minute * 10)
defer ticker.Stop()

var lastPostedAt time.Time
Expand Down
39 changes: 22 additions & 17 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ import (
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
"github.com/pkg/errors"
)

// Telemetry holds information about the state of the zero and alpha server.
type Telemetry struct {
Arch string
Cid string
ClusterSize int
DiskUsageMB int64
NumAlphas int
NumGroups int
NumTablets int
NumZeros int
OS string
SinceHours int
Version string
NumGraphQLPM uint64
NumGraphQL uint64
Arch string `json:",omitempty"`
Cid string `json:",omitempty"`
ClusterSize int `json:",omitempty"`
DiskUsageMB int64 `json:",omitempty"`
NumAlphas int `json:",omitempty"`
NumGroups int `json:",omitempty"`
NumTablets int `json:",omitempty"`
NumZeros int `json:",omitempty"`
OS string `json:",omitempty"`
SinceHours int `json:",omitempty"`
Version string `json:",omitempty"`
NumGraphQLPM uint64 `json:",omitempty"`
NumGraphQL uint64 `json:",omitempty"`
}

var url = "https://ping.dgraph.io/3.0/projects/5b809dfac9e77c0001783ad0/events"
const url = "https://ping.dgraph.io/3.0/projects/5b809dfac9e77c0001783ad0/events"

// NewZero returns a Telemetry struct that holds information about the state of zero server.
func NewZero(ms *pb.MembershipState) *Telemetry {
Expand Down Expand Up @@ -91,12 +92,13 @@ func (t *Telemetry) Post() error {
return err
}

var requestURL string
if len(t.Version) > 0 {
url += "/pings"
requestURL = url + "/pings"
} else {
url += "/dev"
requestURL = url + "/dev"
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(data))
if err != nil {
return err
}
Expand All @@ -116,6 +118,9 @@ func (t *Telemetry) Post() error {
if err != nil {
return err
}
if resp.StatusCode != 201 {
return errors.Errorf(string(body))
}
glog.V(2).Infof("Telemetry response status: %v", resp.Status)
glog.V(2).Infof("Telemetry response body: %s", body)
return nil
Expand Down