From 89f4aa6610d5c3e9d23f773c5bb89418b2ad0da4 Mon Sep 17 00:00:00 2001 From: Jan Knipper Date: Thu, 24 Feb 2022 11:45:33 +0100 Subject: [PATCH] Update default pattern, fix tests --- Makefile | 7 +++++-- main.go | 14 ++++++++++---- main_test.go | 12 ++++++------ yaml/oomkill-exporter.yaml | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c462c506..cdd20ca7 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ TARGET = kubernetes-oomkill-exporter GOTARGET = github.com/sapcc/$(TARGET) REGISTRY ?= sapcc -VERSION ?= 0.3.1 +VERSION ?= 0.4.0 IMAGE = $(REGISTRY)/$(BIN) DOCKER ?= docker all: container +test: + go test . + container: $(DOCKER) build --network=host -t $(REGISTRY)/$(TARGET):latest -t $(REGISTRY)/$(TARGET):$(VERSION) . @@ -14,7 +17,7 @@ push: $(DOCKER) push $(REGISTRY)/$(TARGET):latest $(DOCKER) push $(REGISTRY)/$(TARGET):$(VERSION) -.PHONY: all local container push +.PHONY: all test container push clean: rm -f $(TARGET) diff --git a/main.go b/main.go index bb1d6a08..8a7d8c4e 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,8 @@ import ( ) var ( - kmesgREStr = `/pod(\w+-\w+-\w+-\w+-\w+)/([a-f0-9]+) killed as a result of limit of /kubepods` - kmesgRE *regexp.Regexp + defaultPattern = `^oom-kill.+,task_memcg=\/kubepods(?:\.slice)?\/.+\/(?:kubepods-burstable-)?pod(\w+[-_]\w+[-_]\w+[-_]\w+[-_]\w+)(?:\.slice)?\/(?:docker-)?([a-f0-9]+)` + kmesgRE = regexp.MustCompile(defaultPattern) ) var ( @@ -35,8 +35,15 @@ var ( func init() { var err error + var newPattern string + flag.StringVar(&metricsAddr, "listen-address", ":9102", "The address to listen on for HTTP requests.") - flag.StringVar(&kmesgREStr, "regexp-pattern", kmesgREStr, "The regexp pattern matching and extracting Pod UID and Container ID.") + flag.StringVar(&newPattern, "regexp-pattern", defaultPattern, "Overwrites the default regexp pattern to match and extract Pod UID and Container ID.") + + if newPattern != "" { + kmesgRE = regexp.MustCompile(newPattern) + } + dockerClient, err = docker_client.NewEnvClient() if err != nil { glog.Fatal(err) @@ -46,7 +53,6 @@ func init() { func main() { flag.Parse() - kmesgRE = regexp.MustCompile(kmesgREStr) var labels []string for _, label := range prometheusContainerLabels { diff --git a/main_test.go b/main_test.go index bb3d324d..51b6ce5e 100644 --- a/main_test.go +++ b/main_test.go @@ -50,15 +50,15 @@ func parseMessage(input string) (kmsgparser.Message, error) { func getTestData() ([]string, []string, []string) { return []string{ - "6,22743,6115623303887,-;Task in /kubepods/burstable/pode501ca8a-ec23-11e8-b17a-0a586444015a/f24766bce80e0ce4f0ca2887da2be9d0d250448d7ef503d9f85bf5e549c757d5 killed as a result of limit of /kubepods/burstable/pode501ca8a-ec23-11e8-b17a-0a586444015a", - "6,23800,6780904484233,-;Task in /kubepods/burstable/pod0c4e2576-ef09-11e8-b17a-0a586444015a/9df959ad4292532c5d551226063bd840b906cbf118983fffefa0e3ab90331dc2 killed as a result of limit of /kubepods/burstable/pod0c4e2576-ef09-11e8-b17a-0a586444015a/9df959ad4292532c5d551226063bd840b906cbf118983fffefa0e3ab90331dc2", + "6,22743,6115623303887,-;oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=9f02d9fa0049eb2655fc83c765f142362b2cb403b57b70ba3185071015ca3b64,mems_allowed=0-1,oom_memcg=/kubepods/burstable/podd11ab7b0-d6db-4a24-a7de-4a2faf1e6980/9f02d9fa0049eb2655fc83c765f142362b2cb403b57b70ba3185071015ca3b64,task_memcg=/kubepods/burstable/podd11ab7b0-d6db-4a24-a7de-4a2faf1e6980/9f02d9fa0049eb2655fc83c765f142362b2cb403b57b70ba3185071015ca3b64,task=prometheus-conf,pid=3401999,uid=0", + "6,23800,6780904484233,-;oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=docker-2260b35b008a15bd118e629c0c5d74e7f3a1fe18c724fbac61a54862fea196dc.scope,mems_allowed=0,oom_memcg=/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-poddfc377c9_c533_4d51_af9e_6e0e0b3db83b.slice,task_memcg=/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-poddfc377c9_c533_4d51_af9e_6e0e0b3db83b.slice/docker-2260b35b008a15bd118e629c0c5d74e7f3a1fe18c724fbac61a54862fea196dc.scope,task=stress,pid=255629,uid=0", }, []string{ - "e501ca8a-ec23-11e8-b17a-0a586444015a", - "0c4e2576-ef09-11e8-b17a-0a586444015a", + "d11ab7b0-d6db-4a24-a7de-4a2faf1e6980", + "dfc377c9_c533_4d51_af9e_6e0e0b3db83b", }, []string{ - "f24766bce80e0ce4f0ca2887da2be9d0d250448d7ef503d9f85bf5e549c757d5", - "9df959ad4292532c5d551226063bd840b906cbf118983fffefa0e3ab90331dc2", + "9f02d9fa0049eb2655fc83c765f142362b2cb403b57b70ba3185071015ca3b64", + "2260b35b008a15bd118e629c0c5d74e7f3a1fe18c724fbac61a54862fea196dc", } } diff --git a/yaml/oomkill-exporter.yaml b/yaml/oomkill-exporter.yaml index 687c252d..45db36ce 100644 --- a/yaml/oomkill-exporter.yaml +++ b/yaml/oomkill-exporter.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: oomkill-exporter - image: sapcc/kubernetes-oomkill-exporter:0.3.1 + image: sapcc/kubernetes-oomkill-exporter:0.4.0 imagePullPolicy: IfNotPresent args: - -logtostderr