Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgoStephenAkiki committed Mar 1, 2022
1 parent fcbfeb2 commit d6772b3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ The Indexer has a default set of disabled parameters. To view the disabled para
This will output ONLY the disabled parameters in a YAML configuration. To view all parameters (both enabled and disabled) issue:

```
~$ algorand-indexer api-config all
~$ algorand-indexer api-config --all
```

### Interpreting The Configuration

Below is a sample output of what the output of `algorand-indexer api-config` will look like:
Below is a snippet of the output from `algorand-indexer api-config`:

```
/v2/accounts:
Expand Down
7 changes: 5 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type ExtraOptions struct {

// ReadTimeout is the maximum duration for reading the entire request, including the body.
ReadTimeout time.Duration

// DisabledMapConfig is the disabled map configuration that is being used by the server
DisabledMapConfig *DisabledMapConfig
}

func (e ExtraOptions) handlerTimeout() time.Duration {
Expand All @@ -50,7 +53,7 @@ func (e ExtraOptions) handlerTimeout() time.Duration {
}

// Serve starts an http server for the indexer API. This call blocks.
func Serve(ctx context.Context, disabledMapConfig *DisabledMapConfig, serveAddr string, db idb.IndexerDb, fetcherError error, log *log.Logger, options ExtraOptions) {
func Serve(ctx context.Context, serveAddr string, db idb.IndexerDb, fetcherError error, log *log.Logger, options ExtraOptions) {
e := echo.New()
e.HideBanner = true

Expand Down Expand Up @@ -83,7 +86,7 @@ func Serve(ctx context.Context, disabledMapConfig *DisabledMapConfig, serveAddr
log.Fatal(err)
}

disabledMap, err := MakeDisabledMapFromOA3(swag, disabledMapConfig)
disabledMap, err := MakeDisabledMapFromOA3(swag, options.DisabledMapConfig)
if err != nil {
log.Fatal(err)
}
Expand Down
24 changes: 14 additions & 10 deletions cmd/algorand-indexer/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/algorand/indexer/config"
)

var (
showAllDisabled bool
)

var apiConfigCmd = &cobra.Command{
Use: "api-config",
Short: "dump api configuration",
Expand All @@ -31,19 +35,14 @@ var apiConfigCmd = &cobra.Command{
os.Exit(1)
}

options := makeOptions()

var displayDisabledMapConfig *api.DisplayDisabledMap
// Show a limited subset
if len(args) == 0 {
displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, disabledMapConfig, true)

if !showAllDisabled {
displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, options.DisabledMapConfig, true)
} else {
// This is the only acceptable option
if args[0] != "all" {
fmt.Fprintf(os.Stderr, "unrecognized option to api-config: %s", args[0])
os.Exit(1)
}

displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, disabledMapConfig, false)
displayDisabledMapConfig = api.MakeDisplayDisabledMapFromConfig(swag, options.DisabledMapConfig, false)
}

output, err := displayDisabledMapConfig.String()
Expand All @@ -58,3 +57,8 @@ var apiConfigCmd = &cobra.Command{

},
}

func init() {
apiConfigCmd.Flags().BoolVarP(&showAllDisabled, "all", "", false, "show all api config parameters, enabled and disabled")
apiConfigCmd.Flags().Lookup("all").NoOptDefVal = "true"
}
8 changes: 7 additions & 1 deletion cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var daemonCmd = &cobra.Command{

fmt.Printf("serving on %s\n", daemonServerAddr)
logger.Infof("serving on %s", daemonServerAddr)
api.Serve(ctx, disabledMapConfig, daemonServerAddr, db, bot, logger, makeOptions())
api.Serve(ctx, daemonServerAddr, db, bot, logger, makeOptions())
wg.Wait()
},
}
Expand Down Expand Up @@ -175,6 +175,12 @@ func makeOptions() (options api.ExtraOptions) {
options.WriteTimeout = writeTimeout
options.ReadTimeout = readTimeout

// TODO enable this when command line options allows for disabling/enabling overrides
//disabledMapConfig := api.GetDefaultDisabledMapConfigForPostgres()
disabledMapConfig := api.MakeDisabledMapConfig()

options.DisabledMapConfig = disabledMapConfig

return
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/algorand-indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/algorand/indexer/api"
bg "github.com/algorand/indexer/cmd/block-generator/core"
iv "github.com/algorand/indexer/cmd/import-validator/core"
v "github.com/algorand/indexer/cmd/validator/core"
Expand All @@ -24,8 +23,6 @@ import (
"github.com/algorand/indexer/version"
)

var disabledMapConfig *api.DisabledMapConfig

func maybeFail(err error, errfmt string, params ...interface{}) {
if err == nil {
return
Expand Down Expand Up @@ -207,11 +204,6 @@ func configureLogger() error {
}

func main() {

// TODO enable this when command line options allows for disabling/enabling overrides
//disabledMapConfig = api.GetDefaultDisabledMapConfigForPostgres()
disabledMapConfig = api.MakeDisabledMapConfig()

if err := rootCmd.Execute(); err != nil {
logger.WithError(err).Error("an error occurred running indexer")
os.Exit(1)
Expand Down

0 comments on commit d6772b3

Please sign in to comment.