Skip to content

Commit 9e1a99f

Browse files
Merge pull request #1549 from cybozu/alloy-1.7.0
alloy: add alloy 1.7.0 container
2 parents 5ec44b8 + 891d547 commit 9e1a99f

File tree

6 files changed

+248
-0
lines changed

6 files changed

+248
-0
lines changed

.github/workflows/main.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
make-targets: "check-generate test"
2222
- dir: "./alertmanager"
2323
container-image: "alertmanager"
24+
- dir: "./alloy"
25+
container-image: "alloy"
2426
- dir: "./argocd"
2527
container-image: "argocd"
2628
- dir: "./argocd-image-updater"

alloy/Dockerfile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
FROM ghcr.io/cybozu/golang:1.22-jammy AS build
2+
ARG ALLOY_VERSION=1.7.0
3+
ARG SYSTEMD_VERSION=255
4+
5+
WORKDIR /work
6+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
7+
8+
# Dependencies for systemd copied from Build-Depends section written in the control file of groovy systemd package.
9+
# Archived in https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/systemd/246.6-1ubuntu1/systemd_246.6-1ubuntu1.debian.tar.xz
10+
RUN apt-get update && apt-get -y install --no-install-recommends \
11+
pkg-config \
12+
xsltproc \
13+
docbook-xsl \
14+
docbook-xml \
15+
meson \
16+
gettext \
17+
gperf \
18+
gnu-efi \
19+
libcap-dev \
20+
libpam0g-dev \
21+
libapparmor-dev \
22+
libidn2-dev \
23+
libiptc-dev \
24+
libaudit-dev \
25+
libdbus-1-dev \
26+
libcryptsetup-dev \
27+
libselinux1-dev \
28+
libacl1-dev \
29+
liblzma-dev \
30+
liblz4-dev \
31+
liblz4-tool \
32+
libbz2-dev \
33+
zlib1g-dev \
34+
libcurl4-gnutls-dev \
35+
libmicrohttpd-dev \
36+
libgnutls28-dev \
37+
libpcre2-dev \
38+
libgcrypt20-dev \
39+
libkmod-dev \
40+
libblkid-dev \
41+
libmount-dev \
42+
libseccomp-dev \
43+
libdw-dev \
44+
libpolkit-gobject-1-dev \
45+
libzstd-dev \
46+
linux-base \
47+
acl \
48+
python3:native \
49+
python3-jinja2 \
50+
python3-lxml:native \
51+
python3-pyparsing \
52+
python3-evdev \
53+
tzdata \
54+
libcap2-bin \
55+
iproute2 \
56+
zstd
57+
58+
RUN git clone --depth=1 -b v${SYSTEMD_VERSION} https://github.com/systemd/systemd /work/systemd
59+
RUN meson setup /work/systemd/build/ /work/systemd/ && \
60+
meson install -C /work/systemd/build/
61+
62+
RUN git clone --depth=1 -b v${ALLOY_VERSION} https://github.com/grafana/alloy /work/alloy
63+
COPY force-flush-partial-line.patch /work/
64+
RUN cd alloy && patch -p1 < ../force-flush-partial-line.patch
65+
66+
# we do not add `builtinassets` tag because we do not require alloy ui.
67+
ENV GO_TAGS="netgo promtail_journal_enabled"
68+
RUN make -C /work/alloy USE_CONTAINER=0 alloy
69+
70+
FROM ghcr.io/cybozu/ubuntu:22.04
71+
LABEL org.opencontainers.image.source="https://github.com/cybozu/neco-containers"
72+
73+
RUN apt-get update && \
74+
apt-get install --no-install-recommends -y tzdata ca-certificates && \
75+
rm -rf /var/lib/apt/lists/*
76+
77+
COPY --from=build /usr/lib/x86_64-linux-gnu/libsystemd.so.0 /usr/local/systemd/lib/libsystemd.so.0
78+
COPY --from=build /work/systemd/LICENSE.GPL2 /usr/local/systemd/LICENSE.GPL2
79+
COPY --from=build /work/systemd/LICENSE.LGPL2.1 /usr/local/systemd/LICENSE.LGPL2.1
80+
COPY --from=build /work/alloy/build/alloy /bin/alloy
81+
COPY --from=build /work/alloy/LICENSE /usr/local/alloy/LICENSE
82+
83+
ENV LD_LIBRARY_PATH=/usr/local/systemd/lib
84+
85+
RUN mkdir -p /var/lib/alloy/data
86+
RUN chown -R 10000:10000 /var/lib/alloy
87+
RUN chmod -R 770 /var/lib/alloy
88+
89+
USER 10000:10000
90+
ENTRYPOINT ["/bin/alloy"]
91+
ENV ALLOY_DEPLOY_MODE=docker
92+
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/var/lib/alloy/data"]

alloy/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Alloy container
2+
3+
This directory provides a Dockerfile to build a alloy container
4+
that runs [`alloy`](https://github.com/grafana/alloy).
5+
6+
## Docker images
7+
8+
Docker images are available on [ghcr.io](https://github.com/cybozu/neco-containers/pkgs/container/alloy)

alloy/TAG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.7.0.1

alloy/force-flush-partial-line.patch

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
diff --git a/internal/component/loki/process/stages/extensions.go b/internal/component/loki/process/stages/extensions.go
2+
index 3c7a4262b..0b19655ab 100644
3+
--- a/internal/component/loki/process/stages/extensions.go
4+
+++ b/internal/component/loki/process/stages/extensions.go
5+
@@ -3,6 +3,7 @@ package stages
6+
import (
7+
"fmt"
8+
"strings"
9+
+ "time"
10+
11+
"github.com/go-kit/log"
12+
"github.com/grafana/alloy/internal/featuregate"
13+
@@ -23,9 +24,10 @@ type DockerConfig struct{}
14+
// CRIConfig is an empty struct that is used to enable a pre-defined pipeline
15+
// for decoding entries that are using the CRI logging format.
16+
type CRIConfig struct {
17+
- MaxPartialLines int `alloy:"max_partial_lines,attr,optional"`
18+
- MaxPartialLineSize uint64 `alloy:"max_partial_line_size,attr,optional"`
19+
- MaxPartialLineSizeTruncate bool `alloy:"max_partial_line_size_truncate,attr,optional"`
20+
+ MaxPartialLines int `alloy:"max_partial_lines,attr,optional"`
21+
+ MaxPartialLineSize uint64 `alloy:"max_partial_line_size,attr,optional"`
22+
+ MaxPartialLineSizeTruncate bool `alloy:"max_partial_line_size_truncate,attr,optional"`
23+
+ MaxPartialLineAge time.Duration `alloy:"max_partial_line_age,attr,optional"`
24+
}
25+
26+
var (
27+
@@ -38,6 +40,7 @@ var DefaultCRIConfig = CRIConfig{
28+
MaxPartialLines: 100,
29+
MaxPartialLineSize: 0,
30+
MaxPartialLineSizeTruncate: false,
31+
+ MaxPartialLineAge: time.Minute,
32+
}
33+
34+
// SetToDefault implements syntax.Defaulter.
35+
@@ -50,6 +53,9 @@ func (args *CRIConfig) Validate() error {
36+
if args.MaxPartialLines <= 0 {
37+
return fmt.Errorf("max_partial_lines must be greater than 0")
38+
}
39+
+ if args.MaxPartialLineAge <= time.Duration(0) {
40+
+ return fmt.Errorf("max_partial_line_age must be greater than 0")
41+
+ }
42+
43+
return nil
44+
}
45+
@@ -110,7 +116,7 @@ func (*cri) Cleanup() {
46+
func (c *cri) Run(entry chan Entry) chan Entry {
47+
entry = c.base.Run(entry)
48+
49+
- in := RunWithSkipOrSendMany(entry, func(e Entry) ([]Entry, bool) {
50+
+ in := RunWithSkipOrSendManyWithTick(entry, func(e Entry) ([]Entry, bool) {
51+
fingerprint := e.Labels.Fingerprint()
52+
53+
// We received partial-line (tag: "P")
54+
@@ -157,6 +163,23 @@ func (c *cri) Run(entry chan Entry) chan Entry {
55+
delete(c.partialLines, fingerprint)
56+
}
57+
return []Entry{e}, false
58+
+ }, 10*time.Second, func() []Entry {
59+
+ // Send partial lines which are left unsent for a while.
60+
+ threshold := time.Now().Add(-c.cfg.MaxPartialLineAge)
61+
+
62+
+ entries := make([]Entry, 0)
63+
+ fingerprints := make([]model.Fingerprint, 0)
64+
+ for k, v := range c.partialLines {
65+
+ if v.Timestamp.Before(threshold) {
66+
+ level.Warn(c.base.logger).Log("msg", "cri stage: flushing partial line due to max age", "labels", v.Labels)
67+
+ entries = append(entries, v)
68+
+ fingerprints = append(fingerprints, k)
69+
+ }
70+
+ }
71+
+ for _, fp := range fingerprints {
72+
+ delete(c.partialLines, fp)
73+
+ }
74+
+ return entries
75+
})
76+
77+
return in
78+
diff --git a/internal/component/loki/process/stages/pipeline.go b/internal/component/loki/process/stages/pipeline.go
79+
index f4404941c..88ec9d600 100644
80+
--- a/internal/component/loki/process/stages/pipeline.go
81+
+++ b/internal/component/loki/process/stages/pipeline.go
82+
@@ -4,6 +4,7 @@ import (
83+
"context"
84+
"fmt"
85+
"sync"
86+
+ "time"
87+
88+
"github.com/go-kit/log"
89+
"github.com/prometheus/client_golang/prometheus"
90+
@@ -108,6 +109,38 @@ func RunWithSkipOrSendMany(input chan Entry, process func(e Entry) ([]Entry, boo
91+
return out
92+
}
93+
94+
+// RunWithSkipOrSendManyWithTick same as RunWithSkipOrSendMany, except it can run `tick` function periodically.
95+
+func RunWithSkipOrSendManyWithTick(input chan Entry, process func(e Entry) ([]Entry, bool), interval time.Duration, tick func() []Entry) chan Entry {
96+
+ out := make(chan Entry)
97+
+ go func() {
98+
+ defer close(out)
99+
+ ticker := time.NewTicker(interval)
100+
+ defer ticker.Stop()
101+
+ for {
102+
+ select {
103+
+ case e, ok := <-input:
104+
+ if !ok {
105+
+ return
106+
+ }
107+
+ results, skip := process(e)
108+
+ if skip {
109+
+ continue
110+
+ }
111+
+ for _, result := range results {
112+
+ out <- result
113+
+ }
114+
+ case <-ticker.C:
115+
+ results := tick()
116+
+ for _, result := range results {
117+
+ out <- result
118+
+ }
119+
+ }
120+
+ }
121+
+ }()
122+
+
123+
+ return out
124+
+}
125+
+
126+
// Run implements Stage
127+
func (p *Pipeline) Run(in chan Entry) chan Entry {
128+
in = RunWith(in, func(e Entry) Entry {

maintenance.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ In case of components whose Go source code are in neco-containers, all dependent
2020

2121
- [admission (neco-admission)](#admission-neco-admission)
2222
- [alertmanager](#alertmanager)
23+
- [alloy](#alloy)
2324
- [argocd](#argocd)
2425
- [argocd-image-updater](#argocd-image-updater)
2526
- [bird](#bird)
@@ -165,6 +166,22 @@ In Regular update, do the following as part of the update of each CRD-providing
165166
3. Update version variables in `Dockerfile`.
166167
4. Update `BRANCH` and `TAG` files.
167168

169+
## alloy
170+
171+
![Regular Update](./regular_update.svg)
172+
173+
Alloy contains two versions, one for alloy and the other for libsystemd.
174+
The libsystemd version should be the same with the one running on [the stable Flatcar OS](https://www.flatcar.org/releases).
175+
176+
1. Check the release page.
177+
- https://github.com/grafana/alloy/releases
178+
2. Check the upstream Dockerfile and Makefile. If there are any updates, update our `Dockefile`.
179+
- `https://github.com/grafana/alloy/blob/vX.Y.Z/Dockerfile`
180+
- `https://github.com/grafana/alloy/blob/vX.Y.Z/Makefile`
181+
3. Update `ALLOY_VERSION` in `Dockerfile`.
182+
4. Update `SYSTEMD_VERSION` in `Dockerfile` if needed.
183+
5. Update `TAG` file.
184+
168185
## argocd
169186

170187
![Regular Update](./regular_update.svg)

0 commit comments

Comments
 (0)