Skip to content

Commit 7dd990f

Browse files
committed
Make health server optional
Related: #943
1 parent 8ded3b0 commit 7dd990f

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Flags:
5252
--config string config file (default is $HOME/.flowlogs-pipeline)
5353
--dynamicParameters string json of configmap location for dynamic parameters
5454
--health.address string Health server address (default "0.0.0.0")
55-
--health.port string Health server port (default "8080")
55+
--health.port int Health server port (default: disable health server)
5656
-h, --help help for flowlogs-pipeline
5757
--log-level string Log level: debug, info, warning, error (default "error")
5858
--metricsSettings string json for global metrics settings
@@ -955,6 +955,7 @@ Images
955955
image-push Push MULTIARCH_TARGETS images
956956
manifest-build Build MULTIARCH_TARGETS manifest
957957
manifest-push Push MULTIARCH_TARGETS manifest
958+
extract-binaries Extract all MULTIARCH_TARGETS binaries
958959
goyacc Regenerate filters query langage
959960
960961
kubernetes

cmd/flowlogs-pipeline/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func initFlags() {
143143
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is $HOME/%s)", defaultLogFileName))
144144
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "error", "Log level: debug, info, warning, error")
145145
rootCmd.PersistentFlags().StringVar(&opts.Health.Address, "health.address", "0.0.0.0", "Health server address")
146-
rootCmd.PersistentFlags().StringVar(&opts.Health.Port, "health.port", "8080", "Health server port")
146+
rootCmd.PersistentFlags().IntVar(&opts.Health.Port, "health.port", 0, "Health server port (default: disable health server) ")
147147
rootCmd.PersistentFlags().IntVar(&opts.Profile.Port, "profile.port", 0, "Go pprof tool port (default: disabled)")
148148
rootCmd.PersistentFlags().StringVar(&opts.PipeLine, "pipeline", "", "json of config file pipeline field")
149149
rootCmd.PersistentFlags().StringVar(&opts.Parameters, "parameters", "", "json of config file parameters field")
@@ -199,15 +199,20 @@ func run() {
199199
}
200200

201201
// Start health report server
202-
healthServer := operational.NewHealthServer(&opts, mainPipeline.IsAlive, mainPipeline.IsReady)
202+
var healthServer *http.Server
203+
if opts.Health.Port > 0 {
204+
healthServer = operational.NewHealthServer(&opts, mainPipeline.IsAlive, mainPipeline.IsReady)
205+
}
203206

204207
// Starts the flows pipeline
205208
mainPipeline.Run()
206209

207210
if promServer != nil {
208211
_ = promServer.Shutdown(context.Background())
209212
}
210-
_ = healthServer.Shutdown(context.Background())
213+
if healthServer != nil {
214+
_ = healthServer.Shutdown(context.Background())
215+
}
211216

212217
// Give all threads a chance to exit and then exit the process
213218
time.Sleep(time.Second)

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Following is the supported API format for filter transformations:
229229
input: entry input field
230230
value: specified value of input field:
231231
castInt: set true to cast the value field as an int (numeric values are float64 otherwise)
232+
samplingField: sampling field name to be set when sampling is used; if the field already exists in flows, its value is multiplied with the new sampling
232233
</pre>
233234
## Transform Network API
234235
Following is the supported API format for network transformations:

hack/examples/docker-ipfix-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
log-level: info
2+
health:
3+
port: 8080
24
pipeline:
35
- name: ingest
46
- name: conntrack

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type HotReloadStruct struct {
6060

6161
type Health struct {
6262
Address string
63-
Port string
63+
Port int
6464
}
6565

6666
type Profile struct {

pkg/operational/health.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package operational
1919

2020
import (
21-
"net"
21+
"fmt"
2222
"net/http"
2323
"time"
2424

@@ -30,7 +30,7 @@ import (
3030

3131
func NewHealthServer(opts *config.Options, isAlive healthcheck.Check, isReady healthcheck.Check) *http.Server {
3232
handler := healthcheck.NewHandler()
33-
address := net.JoinHostPort(opts.Health.Address, opts.Health.Port)
33+
address := fmt.Sprintf("%s:%d", opts.Health.Address, opts.Health.Port)
3434
handler.AddLivenessCheck("PipelineCheck", isAlive)
3535
handler.AddReadinessCheck("PipelineCheck", isReady)
3636

pkg/pipeline/health_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestNewHealthServer(t *testing.T) {
3535

3636
type args struct {
3737
pipeline Pipeline
38-
port string
38+
port int
3939
address string
4040
}
4141
type want struct {
@@ -47,15 +47,15 @@ func TestNewHealthServer(t *testing.T) {
4747
args args
4848
want want
4949
}{
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}},
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}},
5252
}
5353

5454
for _, tt := range tests {
5555
t.Run(tt.name, func(t *testing.T) {
5656

5757
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)
58+
expectedAddr := fmt.Sprintf("%s:%d", opts.Health.Address, opts.Health.Port)
5959
server := operational.NewHealthServer(&opts, tt.args.pipeline.IsAlive, tt.args.pipeline.IsReady)
6060
require.NotNil(t, server)
6161
require.Equal(t, expectedAddr, server.Addr)

0 commit comments

Comments
 (0)