Skip to content

Commit 8304899

Browse files
committed
Remove check for spec.Logs.RetentionPeriod when adding volume for logrotate config.
Round up (ceil) on retentionPeriod duration and add a test. Fix typo.
1 parent a1f8383 commit 8304899

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

internal/collector/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func generateLogrotateConfig(logFilePath string, retentionPeriod *v1beta1.Durati
166166
// number of hours and "hourly"; otherwise, we will round up to the nearest day
167167
// and return the day count and "daily"
168168
func parseDurationForLogrotate(retentionPeriod *v1beta1.Duration) (int, string) {
169-
hours := math.Round(retentionPeriod.AsDuration().Hours())
169+
hours := math.Ceil(retentionPeriod.AsDuration().Hours())
170170
if hours < 24 {
171171
return int(hours), "hourly"
172172
}

internal/collector/config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ func TestParseDurationForLogrotate(t *testing.T) {
138138
number int
139139
interval string
140140
}{
141+
{
142+
retentionPeriod: "1 h 20 min",
143+
number: 2,
144+
interval: "hourly",
145+
},
141146
{
142147
retentionPeriod: "12h",
143148
number: 12,

internal/collector/instance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func AddToPod(
4747
return
4848
}
4949

50-
// Create volume and volume mound for otel collector config
50+
// Create volume and volume mount for otel collector config
5151
configVolumeMount := corev1.VolumeMount{
5252
Name: "collector-config",
5353
MountPath: "/etc/otel-collector",
@@ -105,9 +105,9 @@ func AddToPod(
105105
VolumeMounts: append(volumeMounts, configVolumeMount),
106106
}
107107

108-
// If a retentionPeriod is set and this is a pod that uses logrotate for
109-
// log rotation, add config volume and mount for logrotate config
110-
if includeLogrotate && spec != nil && spec.Logs != nil && spec.Logs.RetentionPeriod != nil {
108+
// If this is a pod that uses logrotate for log rotation, add config volume
109+
// and mount for logrotate config
110+
if includeLogrotate {
111111
logrotateConfigVolumeMount := corev1.VolumeMount{
112112
Name: "logrotate-config",
113113
MountPath: "/etc/logrotate.d",

0 commit comments

Comments
 (0)