Repository: istio/istio
File: pkg/envoy/proxy.go (Go)

Code before:
	}
	return logLevel, componentLogs
}

func (e *envoy) Drain(skipExit bool) error {
	adminPort := uint32(e.AdminPort)

	err := DrainListeners(adminPort, e.Sidecar, skipExit)
	if err != nil {
		log.Infof("failed draining listeners for Envoy on port %d: %v", adminPort, err)
	}
	return err
}

func (e *envoy) UpdateConfig(config []byte) error {
	return os.WriteFile(e.ConfigPath, config, 0o666)
}

func (e *envoy) args(fname string, overrideFname string) []string {
	proxyLocalAddressType := "v4"
	if network.AllIPv6(e.NodeIPs) {
		proxyLocalAddressType = "v6"
	}
	fileFlushInterval := "1000" // Default 1s
	if e.FileFlushIntervalSec > 0 {
		fileFlushInterval = fmt.Sprint(e.FileFlushIntervalSec)
	}

	startupArgs := []string{
		"-c", fname,
		"--drain-time-s", fmt.Sprint(int(e.DrainDuration.AsDuration().Seconds())),
		"--drain-strategy", "immediate", // Clients are notified as soon as the drain process starts.
		"--local-address-ip-version", proxyLocalAddressType,
		// Reduce default flush interval from 10s to 1s. The access log buffer size is 64k and each log is ~256 bytes
		// This means access logs will be written once we have ~250 requests, or ever 1s, which ever comes first.
		// Reducing this to 1s optimizes for UX while retaining performance.
		// At low QPS access logs are unlikely a bottleneck, and these users will now see logs after 1s rather than 10s.
		// At high QPS (>250 QPS) we will log the same amount as we will log due to exceeding buffer size, rather
		// than the flush interval.
		"--file-flush-interval-msec", fileFlushInterval,
		"--disable-hot-restart", // We don't use it, so disable it to simplify Envoy's logic
		"--allow-unknown-static-fields",
	}

	if e.FileFlushMinSizeKB > 0 {
		startupArgs = append(startupArgs, "--file-flush-min-size-kb", fmt.Sprint(e.FileFlushMinSizeKB))
	}

	startupArgs = append(startupArgs, e.extraArgs...)

	if overrideFname != "" {

Review comment (suggestion):
```suggestion
		fileFlushInterval = string(e.FileFlushIntervalSec * 1000)
```

Code after:
	}
	return logLevel, componentLogs
}

func (e *envoy) Drain(skipExit bool) error {
	adminPort := uint32(e.AdminPort)

	err := DrainListeners(adminPort, e.Sidecar, skipExit)
	if err != nil {
		log.Infof("failed draining listeners for Envoy on port %d: %v", adminPort, err)
	}
	return err
}

func (e *envoy) UpdateConfig(config []byte) error {
	return os.WriteFile(e.ConfigPath, config, 0o666)
}

func (e *envoy) args(fname string, overrideFname string) []string {
	proxyLocalAddressType := "v4"
	if network.AllIPv6(e.NodeIPs) {
		proxyLocalAddressType = "v6"
	}
	fileFlushInterval := "1000" // Default 1s
	if e.FileFlushInterval != nil {
		fileFlushInterval = fmt.Sprint(e.FileFlushInterval.AsDuration().Milliseconds())
	}

	startupArgs := []string{
		"-c", fname,
		"--drain-time-s", fmt.Sprint(int(e.DrainDuration.AsDuration().Seconds())),
		"--drain-strategy", "immediate", // Clients are notified as soon as the drain process starts.
		"--local-address-ip-version", proxyLocalAddressType,
		// Reduce default flush interval from 10s to 1s. The access log buffer size is 64k and each log is ~256 bytes
		// This means access logs will be written once we have ~250 requests, or ever 1s, which ever comes first.
		// Reducing this to 1s optimizes for UX while retaining performance.
		// At low QPS access logs are unlikely a bottleneck, and these users will now see logs after 1s rather than 10s.
		// At high QPS (>250 QPS) we will log the same amount as we will log due to exceeding buffer size, rather
		// than the flush interval.
		"--file-flush-interval-msec", fileFlushInterval,
		"--disable-hot-restart", // We don't use it, so disable it to simplify Envoy's logic
		"--allow-unknown-static-fields",
	}

	if e.FileFlushMinSizeKB > 0 {
		startupArgs = append(startupArgs, "--file-flush-min-size-kb", fmt.Sprint(e.FileFlushMinSizeKB))
	}

	startupArgs = append(startupArgs, e.extraArgs...)

	if overrideFname != "" {