Skip to content

Commit

Permalink
fix: added the missing log format params
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Webber <[email protected]>
  • Loading branch information
sebastianwebber committed Feb 17, 2021
1 parent a782291 commit bcffadb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 52 deletions.
5 changes: 3 additions & 2 deletions cmd/api/handlers/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/pgconfig/api/pkg/category"
"github.com/pgconfig/api/pkg/config"
"github.com/pgconfig/api/pkg/defaults"
"github.com/pgconfig/api/pkg/docs"
"github.com/pgconfig/api/pkg/format"
"github.com/pgconfig/api/pkg/rules"
Expand Down Expand Up @@ -76,7 +77,7 @@ func processConfig(c *fiber.Ctx, args *configArgs) ([]category.SliceOutput, erro
return nil, err
}

output := tune.ToSlice(args.pgVersion, args.includePgbadger)
output := tune.ToSlice(args.pgVersion, args.includePgbadger, args.logFormat)

if args.showDoc {
doc := pgDocs.Documentation[docs.FormatVer(args.pgVersion)]
Expand Down Expand Up @@ -113,7 +114,7 @@ func processConfig(c *fiber.Ctx, args *configArgs) ([]category.SliceOutput, erro

func parseConfigArgs(c *fiber.Ctx) (*configArgs, error) {

pgVersion, err := strconv.ParseFloat(c.Query("pg_version", defaultPgVersion), 32)
pgVersion, err := strconv.ParseFloat(c.Query("pg_version", defaults.PGVersion), 32)

if err != nil {
return nil, err
Expand Down
27 changes: 0 additions & 27 deletions cmd/api/handlers/v1/rules.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func New() *fiber.App {
v1 := app.Group("/v1/tuning/")

v1.Get("/list-environments", handV1.ListEnvs)
v1.Get("/get-rules", handV1.GetRules)
v1.Get("/get-config", handV1.GetConfig)
v1.Get("/get-config-all-environments", handV1.GetConfigEnvs)

Expand Down
13 changes: 9 additions & 4 deletions cmd/pgconfigctl/cmd/tune.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/pgconfig/api/pkg/category"
"github.com/pgconfig/api/pkg/config"
"github.com/pgconfig/api/pkg/defaults"
"github.com/pgconfig/api/pkg/format"
"github.com/pgconfig/api/pkg/rules"
"github.com/spf13/cobra"
Expand All @@ -47,6 +48,7 @@ var (
profile string
outputFormat string
includePgbadger bool
logFormat string
)

// tuneCmd represents the tune command
Expand All @@ -71,17 +73,19 @@ var tuneCmd = &cobra.Command{
panic(err)
}

data := out.ToSlice(pgVersion, includePgbadger, logFormat)

switch outputFormat {
case "json":
b, err := json.MarshalIndent(out.ToSlice(pgVersion, includePgbadger), "", " ")
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(b))
case "conf", "unix":
export("config", out.ToSlice(pgVersion, includePgbadger))
export("config", data)
case "alter-system", "sql":
export("sql", out.ToSlice(pgVersion, includePgbadger))
export("sql", data)
default:
fmt.Println("Invalid format")
os.Exit(1)
Expand All @@ -105,11 +109,12 @@ func init() {
tuneCmd.PersistentFlags().StringVarP(&diskType, "disk-type", "D", "SSD", "Disk type (possible values are SSD, HDD and SAN)")
tuneCmd.PersistentFlags().StringVarP(&profile, "profile", "", "WEB", "Tuning profile (possible values are WEB, HDD and SAN)")
tuneCmd.PersistentFlags().StringVarP(&outputFormat, "format", "", "conf", "config file format (possible values are unix, alter-system, and json) - file extension also work (conf, sql, json)")
tuneCmd.PersistentFlags().Float32VarP(&pgVersion, "version", "", 13.1, "PostgreSQL Version")
tuneCmd.PersistentFlags().Float32VarP(&pgVersion, "version", "", defaults.PGVersionF, "PostgreSQL Version")
tuneCmd.PersistentFlags().IntVarP(&totalCPU, "cpus", "c", runtime.NumCPU(), "Total CPU cores")
tuneCmd.PersistentFlags().Int64VarP(&totalRAM, "ram", "", int64(memory.Total), "Total Memory in bytes")
tuneCmd.PersistentFlags().IntVarP(&maxConnections, "max-connections", "M", 100, "Max expected connections")
tuneCmd.PersistentFlags().BoolVarP(&includePgbadger, "include-pgbadger", "B", false, "Include pgbadger params?")
tuneCmd.PersistentFlags().StringVarP(&logFormat, "log-format", "L", "csvlog", "Default log format")
}

func export(f string, report []category.SliceOutput) {
Expand Down
20 changes: 2 additions & 18 deletions pkg/category/export_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,10 @@ import (
"github.com/pgconfig/api/pkg/docs"
)


var PGBadgerConfig = SliceOutput{
Name: "log_config",
Description: "Logging configuration for pgbadger",
Parameters: []ParamSliceOutput{
ParamSliceOutput{Format:"bool", Name: "logging_collector", Value: "on"},
ParamSliceOutput{Format:"bool", Name: "log_checkpoints", Value: "on"},
ParamSliceOutput{Format:"bool", Name: "log_connections", Value: "on"},
ParamSliceOutput{Format:"bool", Name: "log_disconnections", Value: "on"},
ParamSliceOutput{Format:"bool", Name: "log_lock_waits", Value: "on"},
ParamSliceOutput{Format:"int", Name: "log_temp_files", Value: "0"},
ParamSliceOutput{Format:"string", Name: "lc_messages", Value: "C"},
ParamSliceOutput{Format:"string", Name: "log_min_duration_statement", Value: "10s", Comment:"Adjust the minimum time to collect the data"},
ParamSliceOutput{Format:"int", Name: "log_autovacuum_min_duration", Value: "0"},
},
}

// ToSlice converts de report into a slice
// with categories and parameters like that is used today on the
// api.pgconfig website.
func (e *ExportCfg) ToSlice(pgVersion float32, includePGBadger bool) []SliceOutput {
func (e *ExportCfg) ToSlice(pgVersion float32, includePGBadger bool, logFormat string) []SliceOutput {

var out []SliceOutput

Expand Down Expand Up @@ -62,6 +45,7 @@ func (e *ExportCfg) ToSlice(pgVersion float32, includePGBadger bool) []SliceOutp

if includePGBadger {
out = append(out, PGBadgerConfig)
out = append(out, LogOptions[logFormat])
}

return out
Expand Down
49 changes: 49 additions & 0 deletions pkg/category/log_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package category

var (
// PGBadgerConfig contains the extra category, that contains pgbadger's log configuration
PGBadgerConfig = SliceOutput{
Name: "log_config",
Description: "Logging configuration for pgbadger",
Parameters: []ParamSliceOutput{
ParamSliceOutput{Format: "bool", Name: "logging_collector", Value: "on"},
ParamSliceOutput{Format: "bool", Name: "log_checkpoints", Value: "on"},
ParamSliceOutput{Format: "bool", Name: "log_connections", Value: "on"},
ParamSliceOutput{Format: "bool", Name: "log_disconnections", Value: "on"},
ParamSliceOutput{Format: "bool", Name: "log_lock_waits", Value: "on"},
ParamSliceOutput{Format: "int", Name: "log_temp_files", Value: "0"},
ParamSliceOutput{Format: "string", Name: "lc_messages", Value: "C"},
ParamSliceOutput{Format: "string", Name: "log_min_duration_statement", Value: "10s", Comment: "Adjust the minimum time to collect the data"},
ParamSliceOutput{Format: "int", Name: "log_autovacuum_min_duration", Value: "0"},
},
}

// LogOptions contains an option to the log configuration
LogOptions = map[string]SliceOutput{
"stderr": SliceOutput{
Name: "stder_config",
Description: "STDERR Configuration",
Parameters: []ParamSliceOutput{
ParamSliceOutput{Format: "string", Name: "log_destination", Value: "stder"},
ParamSliceOutput{Format: "string", Name: "log_line_prefix", Value: "%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h "},
},
},
"syslog": SliceOutput{
Name: "syslog_config",
Description: "SYSLOG Configuration",
Parameters: []ParamSliceOutput{
ParamSliceOutput{Format: "string", Name: "log_destination", Value: "syslog"},
ParamSliceOutput{Format: "string", Name: "log_line_prefix", Value: "user=%u,db=%d,app=%a,client=%h "},
ParamSliceOutput{Format: "string", Name: "syslog_facility", Value: "LOCAL0"},
ParamSliceOutput{Format: "string", Name: "syslog_ident", Value: "postgres"},
},
},
"csvlog": SliceOutput{
Name: "csv_config",
Description: "CSV Configuration",
Parameters: []ParamSliceOutput{
ParamSliceOutput{Format: "string", Name: "log_destination", Value: "csvlog"},
},
},
}
)
9 changes: 9 additions & 0 deletions pkg/defaults/pg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package defaults

const (
// PGVersion is the current stable version of PostgreSQL
PGVersion = "13"

// PGVersionF is the current stable version of PostgreSQL - on the float Format
PGVersionF = 13.1
)

0 comments on commit bcffadb

Please sign in to comment.