Skip to content

Commit a88f7d6

Browse files
authored
Made prom and health server url configurable (#351)
Fixes #349 Signed-off-by: Kuldeep Singh Pal <[email protected]> Signed-off-by: Kuldeep Singh Pal <[email protected]>
1 parent cba2541 commit a88f7d6

File tree

10 files changed

+17
-11
lines changed

10 files changed

+17
-11
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Usage:
4949

5050
Flags:
5151
--config string config file (default is $HOME/.flowlogs-pipeline)
52+
--health.address string Health server address (default "0.0.0.0")
5253
--health.port string Health server port (default "8080")
5354
-h, --help help for flowlogs-pipeline
5455
--log-level string Log level: debug, info, warning, error (default "error")
@@ -728,6 +729,7 @@ parameters:
728729
encode:
729730
type: prom
730731
prom:
732+
address: 0.0.0.0
731733
port: 9103
732734
prefix: test_
733735
metrics:

Diff for: cmd/flowlogs-pipeline/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func initFlags() {
137137
cobra.OnInitialize(initConfig)
138138
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is $HOME/%s)", defaultLogFileName))
139139
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "error", "Log level: debug, info, warning, error")
140+
rootCmd.PersistentFlags().StringVar(&opts.Health.Address, "health.address", "0.0.0.0", "Health server address")
140141
rootCmd.PersistentFlags().StringVar(&opts.Health.Port, "health.port", "8080", "Health server port")
141142
rootCmd.PersistentFlags().IntVar(&opts.Profile.Port, "profile.port", 0, "Go pprof tool port (default: disabled)")
142143
rootCmd.PersistentFlags().StringVar(&opts.PipeLine, "pipeline", "", "json of config file pipeline field")

Diff for: contrib/kubernetes/flowlogs-pipeline.conf.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ parameters:
443443
- service
444444
- _RecordType
445445
buckets: []
446+
address: 0.0.0.0
446447
port: 9102
447448
prefix: flp_
448449
- name: write_loki
@@ -452,4 +453,3 @@ parameters:
452453
url: http://loki.default.svc.cluster.local:3100
453454
staticLabels:
454455
job: flowlogs-pipeline
455-

Diff for: docs/api.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Following is the supported API format for prometheus encode:
1717
valueKey: entry key from which to resolve metric value
1818
labels: labels to be associated with the metric
1919
buckets: histogram buckets
20+
address: address to expose "/metrics" endpoint
2021
port: port number to expose "/metrics" endpoint
2122
prefix: prefix added to each metric name
2223
expiryTime: seconds of no-flow to wait before deleting prometheus data item

Diff for: pkg/api/encode_prom.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type PromTLSConf struct {
2424

2525
type PromEncode struct {
2626
Metrics PromMetricsItems `yaml:"metrics,omitempty" json:"metrics,omitempty" doc:"list of prometheus metric definitions, each includes:"`
27+
Address string `yaml:"address,omitempty" json:"address,omitempty" doc:"address to expose \"/metrics\" endpoint"`
2728
Port int `yaml:"port,omitempty" json:"port,omitempty" doc:"port number to expose \"/metrics\" endpoint"`
2829
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix added to each metric name"`
2930
ExpiryTime int `yaml:"expiryTime,omitempty" json:"expiryTime,omitempty" doc:"seconds of no-flow to wait before deleting prometheus data item"`

Diff for: pkg/confgen/flowlogs2metrics_config.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (cg *ConfGen) GenerateFlowlogs2PipelineConfig() *config.ConfigFileStruct {
5656
}
5757
if len(cg.promMetrics) > 0 {
5858
metricsNode.EncodePrometheus("encode_prom", api.PromEncode{
59+
Address: cg.config.Encode.Prom.Address,
5960
Port: cg.config.Encode.Prom.Port,
6061
Prefix: cg.config.Encode.Prom.Prefix,
6162
Metrics: cg.promMetrics,

Diff for: pkg/config/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type ConfigFileStruct struct {
4343
}
4444

4545
type Health struct {
46-
Port string
46+
Address string
47+
Port string
4748
}
4849

4950
type Profile struct {

Diff for: pkg/operational/health.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
log "github.com/sirupsen/logrus"
2828
)
2929

30-
const defaultServerHost = "0.0.0.0"
31-
3230
type Server struct {
3331
handler healthcheck.Handler
3432
Address string
@@ -45,8 +43,7 @@ func (hs *Server) Serve() {
4543
func NewHealthServer(opts *config.Options, isAlive healthcheck.Check, isReady healthcheck.Check) *Server {
4644

4745
handler := healthcheck.NewHandler()
48-
address := net.JoinHostPort(defaultServerHost, opts.Health.Port)
49-
46+
address := net.JoinHostPort(opts.Health.Address, opts.Health.Port)
5047
handler.AddLivenessCheck("PipelineCheck", isAlive)
5148
handler.AddReadinessCheck("PipelineCheck", isReady)
5249

Diff for: pkg/pipeline/encode/encode_prom.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ func NewEncodeProm(opMetrics *operational.Metrics, params config.StageParam) (En
348348
log.Debugf("histos = %v", histos)
349349
log.Debugf("aggHistos = %v", aggHistos)
350350

351-
addr := fmt.Sprintf(":%v", cfg.Port)
351+
// if value of address is empty, then by default it will take 0.0.0.0
352+
addr := fmt.Sprintf("%s:%v", cfg.Address, cfg.Port)
352353
log.Infof("startServer: addr = %s", addr)
353354

354355
w := &EncodeProm{

Diff for: pkg/pipeline/health_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestNewHealthServer(t *testing.T) {
3636
type args struct {
3737
pipeline Pipeline
3838
port string
39+
address string
3940
}
4041
type want struct {
4142
statusCode int
@@ -46,15 +47,15 @@ func TestNewHealthServer(t *testing.T) {
4647
args args
4748
want want
4849
}{
49-
{name: "pipeline running", args: args{pipeline: Pipeline{IsRunning: true}, port: "7000"}, want: want{statusCode: 200}},
50-
{name: "pipeline not running", args: args{pipeline: Pipeline{IsRunning: false}, port: "7001"}, want: want{statusCode: 503}},
50+
{name: "pipeline running", args: args{pipeline: Pipeline{IsRunning: true}, port: "7000", address: "0.0.0.0"}, want: want{statusCode: 200}},
51+
{name: "pipeline not running", args: args{pipeline: Pipeline{IsRunning: false}, port: "7001", address: "0.0.0.0"}, want: want{statusCode: 503}},
5152
}
5253

5354
for _, tt := range tests {
5455
t.Run(tt.name, func(t *testing.T) {
5556

56-
opts := config.Options{Health: config.Health{Port: tt.args.port}}
57-
expectedAddr := fmt.Sprintf("0.0.0.0:%s", opts.Health.Port)
57+
opts := config.Options{Health: config.Health{Port: tt.args.port, Address: tt.args.address}}
58+
expectedAddr := fmt.Sprintf("%s:%s", opts.Health.Address, opts.Health.Port)
5859
server := operational.NewHealthServer(&opts, tt.args.pipeline.IsAlive, tt.args.pipeline.IsReady)
5960
require.NotNil(t, server)
6061
require.Equal(t, expectedAddr, server.Address)

0 commit comments

Comments
 (0)