Skip to content

Commit

Permalink
Update default pattern, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jknipper committed Feb 24, 2022
1 parent a73d21f commit 89f4aa6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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) .

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)
Expand Down
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand All @@ -46,7 +53,6 @@ func init() {

func main() {
flag.Parse()
kmesgRE = regexp.MustCompile(kmesgREStr)

var labels []string
for _, label := range prometheusContainerLabels {
Expand Down
12 changes: 6 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
2 changes: 1 addition & 1 deletion yaml/oomkill-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89f4aa6

Please sign in to comment.