Skip to content

Commit 280fb28

Browse files
committed
Use es-index-cleaner golang implementation
Signed-off-by: Pavol Loffay <[email protected]>
1 parent a818cd6 commit 280fb28

File tree

11 files changed

+50
-154
lines changed

11 files changed

+50
-154
lines changed

.github/workflows/ci-elasticsearch.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
jobs:
1010
elasticsearch:
1111
runs-on: ubuntu-latest
12+
services:
13+
registry:
14+
image: registry:2
15+
ports:
16+
- 5000:5000
1217
strategy:
1318
matrix:
1419
version:
@@ -41,5 +46,14 @@ jobs:
4146
- name: Install tools
4247
run: make install-ci
4348

49+
- uses: docker/setup-qemu-action@v1
50+
51+
- uses: docker/setup-buildx-action@v1
52+
with:
53+
driver-opts: network=host
54+
4455
- name: Run elasticsearch integration tests
4556
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.image }}
57+
env:
58+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
59+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ grpc-plugin-storage-integration-test:
115115
.PHONY: test-compile-es-scripts
116116
test-compile-es-scripts:
117117
docker run --rm -v ${PWD}:/tmp/jaeger python:3-alpine3.11 /usr/local/bin/python -m py_compile /tmp/jaeger/plugin/storage/es/esRollover.py
118-
docker run --rm -v ${PWD}:/tmp/jaeger python:3-alpine3.11 /usr/local/bin/python -m py_compile /tmp/jaeger/plugin/storage/es/esCleaner.py
119118

120119
.PHONY: index-cleaner-integration-test
121120
index-cleaner-integration-test: docker-images-elastic
@@ -216,6 +215,10 @@ build-esmapping-generator:
216215
build-esmapping-generator-linux:
217216
GOOS=linux GOARCH=amd64 $(GOBUILD) -o ./plugin/storage/es/esmapping-generator ./cmd/esmapping-generator/main.go
218217

218+
.PHONY: build-es-index-cleaner
219+
build-es-index-cleaner:
220+
$(GOBUILD) -o ./cmd/es-index-cleaner/es-index-cleaner-$(GOOS)-$(GOARCH) ./cmd/es-index-cleaner/main.go
221+
219222
.PHONY: docker-hotrod
220223
docker-hotrod:
221224
GOOS=linux $(MAKE) build-examples
@@ -306,7 +309,8 @@ build-platform-binaries: build-agent \
306309
build-examples \
307310
build-tracegen \
308311
build-anonymizer \
309-
build-esmapping-generator
312+
build-esmapping-generator \
313+
build-es-index-cleaner
310314

311315
.PHONY: build-all-platforms
312316
build-all-platforms: build-binaries-linux build-binaries-windows build-binaries-darwin build-binaries-s390x build-binaries-arm64 build-binaries-ppc64le
@@ -316,10 +320,13 @@ docker-images-cassandra:
316320
docker build -t $(DOCKER_NAMESPACE)/jaeger-cassandra-schema:${DOCKER_TAG} plugin/storage/cassandra/
317321
@echo "Finished building jaeger-cassandra-schema =============="
318322

323+
docker-images-elastic: TARGET = release
324+
319325
.PHONY: docker-images-elastic
320-
docker-images-elastic:
326+
docker-images-elastic: create-baseimg
321327
GOOS=linux GOARCH=$(GOARCH) $(MAKE) build-esmapping-generator
322-
docker build -t $(DOCKER_NAMESPACE)/jaeger-es-index-cleaner:${DOCKER_TAG} plugin/storage/es
328+
GOOS=linux GOARCH=$(GOARCH) $(MAKE) build-es-index-cleaner
329+
docker build --target $(TARGET) -t $(DOCKER_NAMESPACE)/jaeger-es-index-cleaner:${DOCKER_TAG} --build-arg base_image=$(BASE_IMAGE) --build-arg TARGETARCH=$(GOARCH) cmd/es-index-cleaner
323330
docker build -t $(DOCKER_NAMESPACE)/jaeger-es-rollover:${DOCKER_TAG} plugin/storage/es -f plugin/storage/es/Dockerfile.rollover --build-arg TARGETARCH=$(GOARCH)
324331
@echo "Finished building jaeger-es-indices-clean =============="
325332

cmd/es-index-cleaner/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG base_image
2+
3+
FROM $base_image AS release
4+
ARG TARGETARCH
5+
COPY es-index-cleaner-linux-$TARGETARCH /go/bin/es-index-cleaner-linux
6+
ENTRYPOINT ["/go/bin/es-index-cleaner-linux"]

cmd/es-index-cleaner/app/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Config struct {
4545
// AddFlags adds flags for TLS to the FlagSet.
4646
func (c *Config) AddFlags(flags *flag.FlagSet) {
4747
flags.String(indexPrefix, "", "Index prefix")
48-
flags.Bool(archive, false, "Whether to remove archive indices")
48+
flags.Bool(archive, false, "Whether to remove archive indices. It works only for rollover")
4949
flags.Bool(rollover, false, "Whether to remove indices created by rollover")
5050
flags.Int(timeout, 120, "Number of seconds to wait for master node response")
5151
flags.String(indexDateSeparator, "-", "Index date separator")

cmd/es-index-cleaner/app/index_filter.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,13 @@ func (i *IndexFilter) Filter(indices []Index) []Index {
4242

4343
func (i *IndexFilter) filter(indices []Index) []Index {
4444
var reg *regexp.Regexp
45-
if !i.Rollover && !i.Archive {
46-
// daily indices
47-
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies)-\\d{4}%s\\d{2}%s\\d{2}", i.IndexPrefix, i.IndexDateSeparator, i.IndexDateSeparator))
48-
} else if !i.Rollover && i.Archive {
49-
// daily archive
50-
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-span-archive", i.IndexPrefix))
51-
} else if i.Rollover && !i.Archive {
52-
// rollover
45+
if i.Archive {
46+
// archive works only for rollover
47+
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-span-archive-\\d{6}", i.IndexPrefix))
48+
} else if i.Rollover {
5349
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service)-\\d{6}", i.IndexPrefix))
5450
} else {
55-
// rollover archive
56-
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-span-archive-\\d{6}", i.IndexPrefix))
51+
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies)-\\d{4}%s\\d{2}%s\\d{2}", i.IndexPrefix, i.IndexDateSeparator, i.IndexDateSeparator))
5752
}
5853

5954
var filtered []Index

cmd/es-index-cleaner/app/index_filter_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,21 @@ func testIndexFilter(t *testing.T, prefix string) {
229229
},
230230
},
231231
{
232-
name: "archive indices, remove older 2 days",
232+
name: "archive indices, remove older 1 days - archive works only for rollover",
233233
filter: &IndexFilter{
234234
IndexPrefix: prefix,
235235
IndexDateSeparator: "-",
236236
Archive: true,
237237
Rollover: false,
238-
DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(2)),
238+
DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(1)),
239239
},
240240
expected: []Index{
241241
{
242-
Index: prefix + "jaeger-span-archive",
243-
CreationTime: time.Date(2020, time.August, 0, 15, 0, 0, 0, time.UTC),
244-
Aliases: map[string]bool{},
242+
Index: prefix + "jaeger-span-archive-000001",
243+
CreationTime: time.Date(2020, time.August, 5, 15, 0, 0, 0, time.UTC),
244+
Aliases: map[string]bool{
245+
prefix + "jaeger-span-archive-read": true,
246+
},
245247
},
246248
},
247249
},

docker/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ ROOT_IMAGE ?= alpine:3.13
33
CERT_IMAGE := $(ROOT_IMAGE)
44
GOLANG_IMAGE := golang:1.16-alpine
55

6-
BASE_IMAGE := localhost:5000/baseimg_alpine:latest
7-
DEBUG_IMAGE := localhost:5000/debugimg_alpine:latest
8-
PLATFORMS := linux/amd64,linux/s390x,linux/ppc64le,linux/arm64
6+
BASE_IMAGE ?= localhost:5000/baseimg_alpine:latest
7+
DEBUG_IMAGE ?= localhost:5000/debugimg_alpine:latest
8+
PLATFORMS ?= linux/amd64,linux/s390x,linux/ppc64le,linux/arm64
99

1010
create-baseimg-debugimg: create-baseimg create-debugimg
1111

plugin/storage/es/Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

plugin/storage/es/esCleaner.py

Lines changed: 0 additions & 117 deletions
This file was deleted.

plugin/storage/integration/es_index_cleaner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func TestIndexCleaner(t *testing.T) {
114114
},
115115
}
116116
for _, test := range tests {
117-
t.Run(fmt.Sprintf("%s_no_prefix", test.name), func(t *testing.T) {
117+
t.Run(fmt.Sprintf("%s_no_prefix, %s", test.name, test.envVars), func(t *testing.T) {
118118
runIndexCleanerTest(t, client, "", test.expectedIndices, test.envVars)
119119
})
120-
t.Run(fmt.Sprintf("%s_prefix", test.name), func(t *testing.T) {
120+
t.Run(fmt.Sprintf("%s_prefix, %s", test.name, test.envVars), func(t *testing.T) {
121121
runIndexCleanerTest(t, client, indexPrefix, test.expectedIndices, append(test.envVars, "INDEX_PREFIX="+indexPrefix))
122122
})
123123
}

0 commit comments

Comments
 (0)