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

feat: add SQA telemetry #535

Merged
merged 5 commits into from
Apr 7, 2021
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 cmd/server/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ on configuration options, open the configuration documentation:
return err
}

return reg.ServeAll(cmd.Context())
return reg.ServeAllSQA(cmd)
},
}
disableTelemetry, err := strconv.ParseBool(os.Getenv("DISABLE_TELEMETRY"))
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/luna-duclos/instrumentedsql v1.1.3
github.com/luna-duclos/instrumentedsql/opentracing v0.0.0-20201103091713-40d03108b6f4
github.com/mattn/goveralls v0.0.8
github.com/ory/analytics-go/v4 v4.0.0
github.com/ory/cli v0.0.48
github.com/ory/go-acc v0.2.6
github.com/ory/graceful v0.1.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/bmatcuk/doublestar/v2 v2.0.3/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bufbuild/buf v0.31.1 h1:IbOhb3xaDR6/dZpbonOBi+9XZYlWD6RIrHMd6aLRjK8=
github.com/bufbuild/buf v0.31.1/go.mod h1:/r1xLhsU+T6zm5sp7ydjKfXIFJ0MD89rQ3bB/EUrI4o=
Expand Down Expand Up @@ -1153,6 +1154,7 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/openzipkin/zipkin-go v0.2.2 h1:nY8Hti+WKaP0cRsSeQ026wU03QsM762XBeCXBb9NAWI=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/ory/analytics-go/v4 v4.0.0 h1:KQ2P00j9dbj4lDC/Albw/zn/scK67041RhqeW5ptsbw=
github.com/ory/analytics-go/v4 v4.0.0/go.mod h1:FMx9cLRD9xN+XevPvZ5FDMfignpmcqPP6FUKnJ9/MmE=
github.com/ory/cli v0.0.35/go.mod h1:8iyLto6q8TiVgxbm4/D64Mt+Tavk1k18g786ZDM298Q=
github.com/ory/cli v0.0.41/go.mod h1:l5KYqpqmTB81BF+SlHwgH56Fp5IY+TMIdFKTPDkPolw=
Expand Down Expand Up @@ -1324,6 +1326,7 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/segmentio/analytics-go v3.0.1+incompatible/go.mod h1:C7CYBtQWk4vRk2RyLu0qOcbHJ18E3F1HV2C/8JvKN48=
github.com/segmentio/analytics-go v3.1.0+incompatible/go.mod h1:C7CYBtQWk4vRk2RyLu0qOcbHJ18E3F1HV2C/8JvKN48=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c/go.mod h1:kJ9mm9YmoWSkk+oQ+5Cj8DEoRCX2JT6As4kEtIIOp1M=
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 h1:ZuhckGJ10ulaKkdvJtiAqsLTiPrLaXSdnVgXJKJkTxE=
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3/go.mod h1:9/Rh6yILuLysoQnZ2oNooD2g7aBnvM7r/fNVxRNWfBc=
github.com/segmentio/conf v1.2.0/go.mod h1:Y3B9O/PqqWqjyxyWWseyj/quPEtMu1zDp/kVbSWWaB0=
github.com/segmentio/go-snakecase v1.1.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto=
Expand Down Expand Up @@ -1481,6 +1484,7 @@ github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHM
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 4 additions & 0 deletions internal/driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func New(ctx context.Context, flags *pflag.FlagSet, l *logrusx.Logger) (*Provide
return kp, nil
}

func (k *Provider) Source() *configx.Provider {
return k.p
}

func (k *Provider) resetNamespaceManager() {
k.nmLock.Lock()
defer k.nmLock.Unlock()
Expand Down
46 changes: 46 additions & 0 deletions internal/driver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,59 @@ import (
"net/http"
"strings"

"github.com/ory/keto/internal/check"
"github.com/ory/keto/internal/expand"
"github.com/ory/keto/internal/relationtuple"

"github.com/ory/analytics-go/v4"
"github.com/ory/x/healthx"
"github.com/ory/x/metricsx"
"github.com/spf13/cobra"

"github.com/ory/keto/internal/driver/config"

"github.com/ory/graceful"
"github.com/pkg/errors"
"github.com/soheilhy/cmux"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
)

func (r *RegistryDefault) enableSqa(cmd *cobra.Command) {
r.sqaService = metricsx.New(
cmd,
r.Logger(),
r.Config().Source(),
&metricsx.Options{
Service: "ory-keto",
ClusterID: metricsx.Hash(r.Config().DSN()),
aeneasr marked this conversation as resolved.
Show resolved Hide resolved
IsDevelopment: strings.HasPrefix(r.Config().DSN(), "sqlite"),
WriteKey: "qQlI6q8Q4WvkzTjKQSor4sHYOikHIvvi",
WhitelistedPaths: []string{
"/",
healthx.AliveCheckPath,
healthx.ReadyCheckPath,
healthx.VersionPath,
zepatrik marked this conversation as resolved.
Show resolved Hide resolved

relationtuple.RouteBase,
check.RouteBase,
expand.RouteBase,
},
BuildVersion: config.Version,
BuildHash: config.Commit,
BuildTime: config.Date,
Config: &analytics.Config{
Endpoint: "https://sqa.ory.sh",
},
},
)
}

func (r *RegistryDefault) ServeAllSQA(cmd *cobra.Command) error {
r.enableSqa(cmd)
return r.ServeAll(cmd.Context())
}

func (r *RegistryDefault) ServeAll(ctx context.Context) error {
eg := &errgroup.Group{}

Expand Down
3 changes: 3 additions & 0 deletions internal/driver/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"net/http"

"github.com/spf13/cobra"

"google.golang.org/grpc"

"github.com/ory/x/healthx"
Expand Down Expand Up @@ -46,6 +48,7 @@ type (
WriteGRPCServer() *grpc.Server

ServeAll(ctx context.Context) error
ServeAllSQA(cmd *cobra.Command) error
ServeRead(ctx context.Context) func() error
ServeWrite(ctx context.Context) func() error
}
Expand Down
11 changes: 11 additions & 0 deletions internal/driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"net/http"

"github.com/ory/x/metricsx"

acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"

grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
Expand Down Expand Up @@ -54,6 +56,7 @@ type (
healthH *healthx.Handler
healthServer *health.Server
handlers []Handler
sqaService *metricsx.Service
tracer *tracing.Tracer
}
Handler interface {
Expand Down Expand Up @@ -235,6 +238,10 @@ func (r *RegistryDefault) ReadRouter() http.Handler {
n.Use(t)
}

if r.sqaService != nil {
zepatrik marked this conversation as resolved.
Show resolved Hide resolved
n.Use(r.sqaService)
}

return n
}

Expand All @@ -255,6 +262,10 @@ func (r *RegistryDefault) WriteRouter() http.Handler {
n.Use(t)
}

if r.sqaService != nil {
n.Use(r.sqaService)
}

return n
}

Expand Down