Add cmd option to disable cardinality calc

This commit is contained in:
Samir Patel 2021-10-28 10:25:26 -05:00
parent 6cb9ce0315
commit b787fccf3a
4 changed files with 25 additions and 2 deletions

17
api.go
View file

@ -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)

View file

@ -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")
}

View file

@ -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
}

View file

@ -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")