Skip to content

Commit

Permalink
fix: node stats (#96)
Browse files Browse the repository at this point in the history
* fix: node stats

* license fix
  • Loading branch information
dhyaniarun1993 authored Sep 2, 2021
1 parent 8e9adf5 commit ec95a2b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 44 deletions.
2 changes: 1 addition & 1 deletion crawler/crawl/crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (c *crawler) updateGeolocation(ctx context.Context, peer *models.Peer) {
func (c *crawler) insertToHistory() {
ctx := context.Background()
// get count
aggregateData, err := c.peerStore.AggregateBySyncStatus(ctx, 15)
aggregateData, err := c.peerStore.AggregateBySyncStatus(ctx)
if err != nil {
log.Error("error getting sync status", log.Ctx{"err": err})
}
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -982,7 +984,9 @@ github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.0 h1:P2KMzcFwrPoSjkF1WLRPsp3UMLyql8L4v9hQpVeK5so=
github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
Expand Down Expand Up @@ -1013,6 +1017,7 @@ github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122/go.mod h1:b
github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2/go.mod h1:eWdoE5JD4R5UVWDucdOPg1g2fqQRq78IQa9zlOV1vpQ=
github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lToEk4d2s07G3XGfz2QrgHXg4RJBvjrOozvoWfk=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
Expand Down Expand Up @@ -1073,8 +1078,10 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
Expand Down
37 changes: 5 additions & 32 deletions graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Query {
aggregateByNetwork: [AggregateData!]!
aggregateByClientVersion: [ClientVersionAggregation!]!
getHeatmapData: [HeatmapData!]!
getNodeStats(unsyncedPercentage: Int!): NodeStats!
getNodeStats: NodeStats!
getNodeStatsOverTime(start: Float!, end: Float!): [NodeStatsOverTime!]!
getRegionalStats: RegionalStats!
}
4 changes: 2 additions & 2 deletions graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (r *queryResolver) GetHeatmapData(ctx context.Context) ([]*model.HeatmapDat
return result, nil
}

func (r *queryResolver) GetNodeStats(ctx context.Context, unsyncedPercentage int) (*model.NodeStats, error) {
aggregateData, err := r.peerStore.AggregateBySyncStatus(ctx, unsyncedPercentage)
func (r *queryResolver) GetNodeStats(ctx context.Context) (*model.NodeStats, error) {
aggregateData, err := r.peerStore.AggregateBySyncStatus(ctx)
if err != nil {
return nil, err
}
Expand Down
9 changes: 2 additions & 7 deletions store/peerstore/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,10 @@ type aggregateSyncData struct {
Unsynced []count `json:"unsynced" bson:"unsynced"`
}

func (s *mongoStore) AggregateBySyncStatus(ctx context.Context, percentageUnsynced int) (*models.SyncAggregateData, error) {
func (s *mongoStore) AggregateBySyncStatus(ctx context.Context) (*models.SyncAggregateData, error) {
total := bson.A{bson.D{{Key: "$count", Value: "count"}}}
synced := bson.A{bson.D{{Key: "$match", Value: bson.D{{Key: "sync.status", Value: true}}}}, bson.D{{Key: "$count", Value: "count"}}}
unsynced := bson.A{bson.D{{Key: "$match", Value: bson.D{
{Key: "$and", Value: bson.A{
bson.D{{Key: "sync.status", Value: false}},
bson.D{{Key: "sync.distance", Value: bson.D{{Key: "$gt", Value: percentageUnsynced}}}},
}}}}},
bson.D{{Key: "$count", Value: "count"}}}
unsynced := bson.A{bson.D{{Key: "$match", Value: bson.D{{Key: "sync.status", Value: false}}}}, bson.D{{Key: "$count", Value: "count"}}}

facetStage := bson.D{{Key: "$facet", Value: bson.D{
{Key: "total", Value: total},
Expand Down
2 changes: 1 addition & 1 deletion store/peerstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ type Provider interface {
AggregateByOperatingSystem(ctx context.Context) ([]*models.AggregateData, error)
AggregateByCountry(ctx context.Context) ([]*models.AggregateData, error)
AggregateByNetworkType(ctx context.Context) ([]*models.AggregateData, error)
AggregateBySyncStatus(ctx context.Context, percentageUnsynced int) (*models.SyncAggregateData, error)
AggregateBySyncStatus(ctx context.Context) (*models.SyncAggregateData, error)
AggregateByClientVersion(ctx context.Context) ([]*models.ClientVersionAggregation, error)
}

0 comments on commit ec95a2b

Please sign in to comment.