Skip to content

Commit b705581

Browse files
Copilotdol
authored andcommitted
feat: add /var/lib persistent state directories for collector RPM/DEB packages
Add packaged /var/lib/<package> directories to otelcol, otelcol-contrib, and otelcol-otlp distributions. These directories are needed for the file_storage resiliency extension which persists the collector queue to disk. See https://opentelemetry.io/docs/collector/resiliency/ - Add withVarLibDir(user, group) helper in builder.go - Set mode 0750 (rwxr-x---) owned by the service user/group - Regenerate .goreleaser.yaml files for affected distributions
1 parent 6d94db7 commit b705581

8 files changed

Lines changed: 53 additions & 3 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
change_type: enhancement
2+
3+
component: packaging
4+
5+
note: Add /var/lib persistent state directories for collector RPM/DEB packages
6+
7+
issues: [1396]
8+
9+
subtext:
10+
11+
change_logs: [user]

cmd/goreleaser/internal/builder.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ func (b *distributionBuilder) newNfpms(dist string) []config.NFPM {
225225
}
226226
}
227227

228+
func (b *distributionBuilder) withVarLibDir(user, group string) *distributionBuilder {
229+
b.configFuncs = append(b.configFuncs, func(d *distribution) {
230+
for i := range d.Nfpms {
231+
d.Nfpms[i].Contents = append(d.Nfpms[i].Contents, config.NFPMContent{
232+
Destination: path.Join("/var", "lib", d.Name),
233+
Type: "dir",
234+
FileInfo: config.FileInfo{
235+
Owner: user,
236+
Group: group,
237+
// 0750 (octal) = 488 (decimal). The generated YAML emits 488 because
238+
// go.yaml.in/yaml/v3 serializes integers as decimal. This is intentional:
239+
// decimal 488 is unambiguous across YAML 1.1 and 1.2, whereas octal
240+
// notations (0750 / 0o750) are misinterpreted by one or the other.
241+
Mode: 0750,
242+
},
243+
})
244+
}
245+
})
246+
return b
247+
}
248+
228249
func (b *distributionBuilder) withDefaultMSIConfig() *distributionBuilder {
229250
b.configFuncs = append(b.configFuncs, func(d *distribution) {
230251
d.MsiConfig = b.newMSIConfig(d.Name)

cmd/goreleaser/internal/distro_contrib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
d.ContainerImageManifests = slices.Concat(
4444
newContainerImageManifests(d.Name, "linux", baseArchs, containerImageOptions{}),
4545
)
46-
}).withPackagingDefaults().withDefaultConfigIncluded().build()
46+
}).withPackagingDefaults().withDefaultConfigIncluded().withVarLibDir("otelcol-contrib", "otelcol-contrib").build()
4747

4848
// contrib build-only project
4949
contribBuildOnlyDist = newDistributionBuilder(contribDistro).withConfigFunc(func(d *distribution) {

cmd/goreleaser/internal/distro_otelcol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ var (
2121
d.ContainerImageManifests = slices.Concat(
2222
newContainerImageManifests(d.Name, "linux", baseArchs, containerImageOptions{}),
2323
)
24-
}).withPackagingDefaults().withDefaultConfigIncluded().build()
24+
}).withPackagingDefaults().withDefaultConfigIncluded().withVarLibDir("otel", "otel").build()
2525
)

cmd/goreleaser/internal/distro_otlp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ var (
2121
d.ContainerImageManifests = slices.Concat(
2222
newContainerImageManifests(d.Name, "linux", baseArchs, containerImageOptions{}),
2323
)
24-
}).withPackagingDefaults().build()
24+
}).withPackagingDefaults().withVarLibDir("otelcol-otlp", "otelcol-otlp").build()
2525
)

distributions/otelcol-contrib/.goreleaser.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ nfpms:
8787
- src: config.yaml
8888
dst: /etc/otelcol-contrib/config.yaml
8989
type: config|noreplace
90+
- dst: /var/lib/otelcol-contrib
91+
type: dir
92+
file_info:
93+
owner: otelcol-contrib
94+
group: otelcol-contrib
95+
mode: 488
9096
scripts:
9197
preinstall: preinstall.sh
9298
postinstall: postinstall.sh

distributions/otelcol-otlp/.goreleaser.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ nfpms:
7878
- src: otelcol-otlp.conf
7979
dst: /etc/otelcol-otlp/otelcol-otlp.conf
8080
type: config|noreplace
81+
- dst: /var/lib/otelcol-otlp
82+
type: dir
83+
file_info:
84+
owner: otelcol-otlp
85+
group: otelcol-otlp
86+
mode: 488
8187
scripts:
8288
preinstall: preinstall.sh
8389
postinstall: postinstall.sh

distributions/otelcol/.goreleaser.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ nfpms:
8282
- src: config.yaml
8383
dst: /etc/otelcol/config.yaml
8484
type: config|noreplace
85+
- dst: /var/lib/otelcol
86+
type: dir
87+
file_info:
88+
owner: otel
89+
group: otel
90+
mode: 488
8591
scripts:
8692
preinstall: preinstall.sh
8793
postinstall: postinstall.sh

0 commit comments

Comments
 (0)