From b787fccf3a356ad9cc6c54799008f1eca44282ca Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Thu, 28 Oct 2021 10:25:26 -0500 Subject: [PATCH] Add cmd option to disable cardinality calc --- api.go | 17 +++++++++++++++-- ctl/server.go | 3 +++ server/config.go | 6 ++++++ server/server.go | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 7bcc0dda7..f7d9001f4 100644 --- a/api.go +++ b/api.go @@ -62,7 +62,8 @@ type API struct { importWorkerPoolSize int importWork chan importJob - usageCache *usageCache + usageCache *usageCache + schemaDetailsOn bool Serializer Serializer } @@ -84,6 +85,14 @@ func OptAPIServer(s *Server) apiOption { } } +// Used to configure API option: schemaDetailsOn +func OptAPISchemaDetailsOn(isOn bool) apiOption { + return func(a *API) error { + a.schemaDetailsOn = isOn + return nil + } +} + func OptAPIImportWorkerPoolSize(size int) apiOption { return func(a *API) error { a.importWorkerPoolSize = size @@ -1237,7 +1246,8 @@ func (api *API) Schema(ctx context.Context, withViews bool) ([]*IndexInfo, error } // SchemaDetails returns information about each index in Pilosa including which -// fields they contain, and additional field information such as cardinality +// fields they contain. Additional field information such as cardinality unless +// turned off via the schemaDetailsOn cli option. func (api *API) SchemaDetails(ctx context.Context) ([]*IndexInfo, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.Schema") defer span.Finish() @@ -1245,6 +1255,9 @@ func (api *API) SchemaDetails(ctx context.Context) ([]*IndexInfo, error) { if err != nil { return nil, errors.Wrap(err, "getting schema") } + if !api.schemaDetailsOn { + return schema, nil + } for _, index := range schema { for _, field := range index.Fields { q := fmt.Sprintf("Count(Distinct(field=%s))", field.Name) diff --git a/ctl/server.go b/ctl/server.go index 71c26bb3c..d53bf81af 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -118,4 +118,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { // Future flags. flags.BoolVar(&srv.Config.Future.Rename, "future.rename", false, "Present application name as FeatureBase. Defaults to false, will default to true in an upcoming release.") + + // Toggle /schema/details endpoint. + flags.BoolVar(&srv.Config.SchemaDetailsOn, "schema-details-on", true, "Disable /schema/details endpoint") } diff --git a/server/config.go b/server/config.go index 344440ded..a42eb7917 100644 --- a/server/config.go +++ b/server/config.go @@ -237,6 +237,9 @@ type Config struct { // as FeatureBase instead of Pilosa. Rename bool `toml:"rename"` } `toml:"future"` + + // Toggles /schema/details endpoint. If off, it returns empty. + SchemaDetailsOn bool `toml:"schema-details-on"` } // Namespace returns the namespace to use based on the Future flag. @@ -386,6 +389,9 @@ func NewConfig() *Config { // Future flags. c.Future.Rename = false + // Schema Details Toggle + c.SchemaDetailsOn = true + return c } diff --git a/server/server.go b/server/server.go index 8d227ade7..929404852 100644 --- a/server/server.go +++ b/server/server.go @@ -511,6 +511,7 @@ func (m *Command) SetupServer() error { m.API, err = pilosa.NewAPI( pilosa.OptAPIServer(m.Server), pilosa.OptAPIImportWorkerPoolSize(m.Config.ImportWorkerPoolSize), + pilosa.OptAPISchemaDetailsOn(m.Config.SchemaDetailsOn), ) if err != nil { return errors.Wrap(err, "new api")