Repository: microsoft/retina
File: pkg/capture/capture_manager.go (Go)

Code before:
}

func (cm *CaptureManager) Cleanup() error {
	if err := cm.networkCaptureProvider.Cleanup(); err != nil {
		cm.l.Error("Failed to cleanup capture job", zap.String("capture name", cm.captureName()), zap.Error(err))
		return err
	}

	return nil
}

func (cm *CaptureManager) captureName() string {
	return os.Getenv(captureConstants.CaptureNameEnvKey)
}

func (cm *CaptureManager) captureNodeHostName() string {
	return os.Getenv(captureConstants.NodeHostNameEnvKey)
}

func (cm *CaptureManager) captureStartTimestamp() (time.Time, error) {
	tmp := os.Getenv(captureConstants.CaptureStartTimestampEnvKey)

	timestamp, err := captureUtils.ConvertStringToTimestamp(tmp)
	if err != nil {
		cm.l.Error("Failed to parse the timestamp into the right format", zap.Error(err))
		return time.Time{}, err
	}
	return timestamp, nil
}

func (cm *CaptureManager) captureFilter() string {
	captureFilter := os.Getenv(captureConstants.TcpdumpFilterEnvKey)
	if runtime.GOOS == "windows" {
		captureFilter = os.Getenv(captureConstants.NetshFilterEnvKey)
	}
	return captureFilter
}

func (cm *CaptureManager) captureDuration() (int, error) {
	captureDurationStr := os.Getenv(captureConstants.CaptureDurationEnvKey)
	duration, err := time.ParseDuration(captureDurationStr)
	if err != nil {
		return 0, err
	}
	return int(duration.Seconds()), nil
}

func (cm *CaptureManager) includeMetadata() bool {
	includeMetadataStr := os.Getenv(captureConstants.IncludeMetadataEnvKey)
	if len(includeMetadataStr) == 0 {
		return false

Review comment (suggestion):
It's best to either log or return errors wrapped with context to someone that will log them for you. The latter is generally preferred in the Go community. `(github.com/pkg/errors).Wrap` is what this team has decided to use for that.

Code after:

	return tmpLocation, nil
}

func (cm *CaptureManager) Cleanup() error {
	if err := cm.networkCaptureProvider.Cleanup(); err != nil {
		cm.l.Error("Failed to cleanup capture job", zap.String("capture name", cm.captureName()), zap.Error(err))
		return err
	}

	return nil
}

func (cm *CaptureManager) captureName() string {
	return os.Getenv(captureConstants.CaptureNameEnvKey)
}

func (cm *CaptureManager) captureNodeHostName() string {
	return os.Getenv(captureConstants.NodeHostNameEnvKey)
}

func (cm *CaptureManager) captureStartTimestamp() (*file.Timestamp, error) {
	timestamp, err := file.StringToTimestamp((os.Getenv(captureConstants.CaptureStartTimestampEnvKey)))
	if err != nil {
		return nil, errors.Wrap(err, "failed to parse timestamp")
	}
	return timestamp, nil
}

func (cm *CaptureManager) captureFilter() string {
	captureFilter := os.Getenv(captureConstants.TcpdumpFilterEnvKey)
	if runtime.GOOS == "windows" {
		captureFilter = os.Getenv(captureConstants.NetshFilterEnvKey)
	}
	return captureFilter
}

func (cm *CaptureManager) captureDuration() (int, error) {
	captureDurationStr := os.Getenv(captureConstants.CaptureDurationEnvKey)
	duration, err := time.ParseDuration(captureDurationStr)
	if err != nil {
		return 0, err
	}
	return int(duration.Seconds()), nil
}

func (cm *CaptureManager) includeMetadata() bool {
	includeMetadataStr := os.Getenv(captureConstants.IncludeMetadataEnvKey)
	if len(includeMetadataStr) == 0 {
		return false
	}