Skip to content

Commit

Permalink
feat: add flag categories (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored May 22, 2024
1 parent 0d22ee4 commit 3f5bbc4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 53 deletions.
26 changes: 16 additions & 10 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@ const (
FlagLogCtx = "log.ctx"
)

// CategoryLog is the log flag category.
var CategoryLog = "Logging"

// LogFlags are flags that configure logging.
var LogFlags = Flags{
&cli.StringFlag{
Name: FlagLogFormat,
Usage: "Specify the format of logs. Supported formats: 'logfmt', 'json', 'console'",
EnvVars: []string{"LOG_FORMAT"},
Name: FlagLogFormat,
Category: CategoryLog,
Usage: "Specify the format of logs. Supported formats: 'logfmt', 'json', 'console'",
EnvVars: []string{"LOG_FORMAT"},
},
&cli.StringFlag{
Name: FlagLogLevel,
Value: "info",
Usage: "Specify the log level. e.g. 'trace', 'debug', 'info', 'error'.",
EnvVars: []string{"LOG_LEVEL"},
Name: FlagLogLevel,
Category: CategoryLog,
Value: "info",
Usage: "Specify the log level. e.g. 'trace', 'debug', 'info', 'error'.",
EnvVars: []string{"LOG_LEVEL"},
},
&cli.StringSliceFlag{
Name: FlagLogCtx,
Usage: "A list of context field appended to every log. Format: key=value.",
EnvVars: []string{"LOG_CTX"},
Name: FlagLogCtx,
Category: CategoryLog,
Usage: "A list of context field appended to every log. Format: key=value.",
EnvVars: []string{"LOG_CTX"},
},
}

Expand Down
29 changes: 18 additions & 11 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,36 @@ const (
FlagProfilingTypes = "profiling.types"
)

// CategoryProfiling is the profiling category.
var CategoryProfiling = "Profiling"

// ProfilingFlags are flags that configure profiling.
var ProfilingFlags = Flags{
&cli.StringFlag{
Name: FlagProfilingDSN,
Name: FlagProfilingDSN,
Category: CategoryProfiling,
Usage: "The address to the Pyroscope server, in the format " +
"'http://basic:auth@server:port?token=auth-token&tenantid=tenant-id'.",
EnvVars: []string{"PROFILING_DSN"},
},
&cli.DurationFlag{
Name: FlagProfileUploadRate,
Usage: "The rate at which profiles are uploaded.",
Value: 15 * time.Second,
EnvVars: []string{"PROFILING_UPLOAD_RATE"},
Name: FlagProfileUploadRate,
Category: CategoryProfiling,
Usage: "The rate at which profiles are uploaded.",
Value: 15 * time.Second,
EnvVars: []string{"PROFILING_UPLOAD_RATE"},
},
&cli.StringSliceFlag{
Name: FlagProfilingTags,
Usage: "A list of tags appended to every profile. Format: key=value.",
EnvVars: []string{"PROFILING_TAGS"},
Name: FlagProfilingTags,
Category: CategoryProfiling,
Usage: "A list of tags appended to every profile. Format: key=value.",
EnvVars: []string{"PROFILING_TAGS"},
},
&cli.StringSliceFlag{
Name: FlagProfilingTypes,
Usage: "The type of profiles to include. Defaults to all.",
EnvVars: []string{"PROFILING_TYPES"},
Name: FlagProfilingTypes,
Category: CategoryProfiling,
Usage: "The type of profiles to include. Defaults to all.",
EnvVars: []string{"PROFILING_TYPES"},
},
}

Expand Down
33 changes: 20 additions & 13 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,35 @@ const (
FlagStatsTags = "stats.tags"
)

// CategoryStats is the stats flag category.
var CategoryStats = "Stats"

// StatsFlags are flags that configure stats.
var StatsFlags = Flags{
&cli.StringFlag{
Name: FlagStatsDSN,
Usage: "The DSN of a stats backend.",
EnvVars: []string{"STATS_DSN"},
Name: FlagStatsDSN,
Category: CategoryStats,
Usage: "The DSN of a stats backend.",
EnvVars: []string{"STATS_DSN"},
},
&cli.DurationFlag{
Name: FlagStatsInterval,
Usage: "The frequency at which the stats are reported.",
Value: time.Second,
EnvVars: []string{"STATS_INTERVAL"},
Name: FlagStatsInterval,
Category: CategoryStats,
Usage: "The frequency at which the stats are reported.",
Value: time.Second,
EnvVars: []string{"STATS_INTERVAL"},
},
&cli.StringFlag{
Name: FlagStatsPrefix,
Usage: "The prefix of the measurements names.",
EnvVars: []string{"STATS_PREFIX"},
Name: FlagStatsPrefix,
Category: CategoryStats,
Usage: "The prefix of the measurements names.",
EnvVars: []string{"STATS_PREFIX"},
},
&cli.StringSliceFlag{
Name: FlagStatsTags,
Usage: "A list of tags appended to every measurement. Format: key=value.",
EnvVars: []string{"STATS_TAGS"},
Name: FlagStatsTags,
Category: CategoryStats,
Usage: "A list of tags appended to every measurement. Format: key=value.",
EnvVars: []string{"STATS_TAGS"},
},
}

Expand Down
47 changes: 28 additions & 19 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,47 @@ const (
FlagTracingRatio = "tracing.ratio"
)

// CategoryTracing is the tracing flag category.
var CategoryTracing = "Tracing"

// TracingFlags are flags that configure tracing.
var TracingFlags = Flags{
&cli.StringFlag{
Name: FlagTracingExporter,
Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.",
EnvVars: []string{"TRACING_EXPORTER"},
Name: FlagTracingExporter,
Category: CategoryTracing,
Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.",
EnvVars: []string{"TRACING_EXPORTER"},
},
&cli.StringFlag{
Name: FlagTracingEndpoint,
Usage: "The tracing backend endpoint.",
EnvVars: []string{"TRACING_ENDPOINT"},
Name: FlagTracingEndpoint,
Category: CategoryTracing,
Usage: "The tracing backend endpoint.",
EnvVars: []string{"TRACING_ENDPOINT"},
},
&cli.BoolFlag{
Name: FlagTracingEndpointInsecure,
Usage: "Determines if the endpoint is insecure.",
EnvVars: []string{"TRACING_ENDPOINT_INSECURE"},
Name: FlagTracingEndpointInsecure,
Category: CategoryTracing,
Usage: "Determines if the endpoint is insecure.",
EnvVars: []string{"TRACING_ENDPOINT_INSECURE"},
},
&cli.StringSliceFlag{
Name: FlagTracingTags,
Usage: "A list of tags appended to every trace. Format: key=value.",
EnvVars: []string{"TRACING_TAGS"},
Name: FlagTracingTags,
Category: CategoryTracing,
Usage: "A list of tags appended to every trace. Format: key=value.",
EnvVars: []string{"TRACING_TAGS"},
},
&cli.StringSliceFlag{
Name: FlagTracingHeaders,
Usage: "A list of headers appended to every trace when supported by the exporter. Format: key=value.",
EnvVars: []string{"TRACING_HEADERS"},
Name: FlagTracingHeaders,
Category: CategoryTracing,
Usage: "A list of headers appended to every trace when supported by the exporter. Format: key=value.",
EnvVars: []string{"TRACING_HEADERS"},
},
&cli.Float64Flag{
Name: FlagTracingRatio,
Usage: "The ratio between 0 and 1 of sample traces to take.",
Value: 0.5,
EnvVars: []string{"TRACING_RATIO"},
Name: FlagTracingRatio,
Category: CategoryTracing,
Usage: "The ratio between 0 and 1 of sample traces to take.",
Value: 0.5,
EnvVars: []string{"TRACING_RATIO"},
},
}

Expand Down

0 comments on commit 3f5bbc4

Please sign in to comment.