https://github.com/awslabs/logparserforkarpenter

Log parser for Karpenter controller logs

https://github.com/awslabs/logparserforkarpenter

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.5%) to scientific vocabulary

Keywords

k8s karpenter
Last synced: 9 months ago · JSON representation

Repository

Log parser for Karpenter controller logs

Basic Info
  • Host: GitHub
  • Owner: awslabs
  • License: apache-2.0
  • Language: Go
  • Default Branch: main
  • Homepage:
  • Size: 313 KB
Statistics
  • Stars: 8
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 12
Topics
k8s karpenter
Created about 1 year ago · Last pushed 9 months ago
Metadata Files
Readme Contributing License Code of conduct

README.md

Log Parser for Karpenter (LogParserForKarpenter)

Log Parser for Karpenter is a Golang based command line tool which can parse the output of Karpenter Controller logs, tested against logs from Karpenter versions: * v0.37.7 * * v1.0.x * * v1.1.x * v1.2.x * v1.3.x * v1.4.x

* Note: "messageKind":"spot_interrupted" is first supported with Karpenter version v1.1.x, so LogParserForKarpenter (lp4k) does not provide interruptiontime and interruptionkind in earlier versions

It allows using either STDIN (for example for piping live Karpenter controller logs) or multiple Karpenter log files as input and will print CSV style formatted output of nodeclaim data ordered by createdtime to STDOUT, so one can easily redirect it into a file and analyse with tools like Amazon QuickSight or Microsoft Excel.

If neither STDIN nor log files are used as input, lp4k will attach to a running K8s/EKS cluster and parses Karpenter logs (streamed logs, similar to kubectl logs -f using LP4KKARPENTERNAMESPACE and LP4KKARPENTERLABEL) and creates a ConfigMap lp4k-cm-<date> in same namespace, which gets updated every LP4KCMUPDATE_FREQ.

K8s handling can be configured using the following OS environment variables:

| Environment variable | Default value | Description | ------------- | ------------- | ------------- | | LP4KKARPENTERNAMESPACE | "karpenter" | K8s namespace where Karpenter controller is running | LP4KKARPENTERLABEL | "app.kubernetes.io/name=karpenter" | Karpenter controller K8s pod labels | LP4KCMUPDATEFREQ | "30s" | update frequency of ConfigMap and STDOUT if enabled (default), must be valid Go time.Duration string like "30s" or 2m30s" | LP4KCMPREFIX | "lp4k-cm" | nodeclaim ConfigMap prefix, if KARPENTERLP4KCMOVERRIDE=false or ConfigMap name, if KARPENTERLP4KCMOVERRIDE=true | LP4KCMOVERRIDE | "false" | determines, if ConfigMap will just use prefix and will be overriden upon every start of lp4k | LP4KNODECLAIMPRINT | "true" | print nodeclaim information every KARPENTERCMUPDATEFREQ to STDOUT

* Note: In mode LP4K_CM_OVERRIDE=true lp4k will read existing nodeclaim data from ConfigMap specified by LP4KCMPREFIX

Use: bash LP4K_CM_UPDATE_FREQ=10s ./bin/lp4k or permanently ```bash export LP4KCMUPDATE_FREQ=10s ./bin/lp4k

```

To start using LogParserForKarpenter

Just run: bash make A binary lp4k for your OS and platform is build in directory bin.

Then run it like: bash ./bin/lp4k sample-input.txt or bash ./bin/lp4k <Karpenter log output file 1> [... <Karpenter log output file n>] or bash kubectl logs -n kube-system deployments/karpenter --all-pods=true [-f] | ./lp4k or for attaching to K8s/EKS cluster in current KUBECONFIG context bash ./bin/lp4k The sample output file sample-multi-file-klp-output.csv shows all exposed nodeclaim information and can be used as a sample starter to build analysis on top of it. * Note: lp4k will recognise new nodeclaims and populate its internal structures first when Karpenter controller logs show a logline containing "message":"created nodeclaim". That means after a Karpenter controller restart and a subsequent and required restart lp4k will not recognise already existing nodeclaims and shows No results - empty "nodeclaim" map

lp4kcm

lp4kcm is a helper tool to display lp4k ConfigMap data in same CSV format.

Just run: bash make tools A binary lp4kcm for your OS and platform is build in directory bin.

Then run it like: bash ./bin/lp4k <lp4k ConfigMap name 1> [... <lp4k ConfigMap name n>]

Analyse LogParserForKarpenter output

The simplest way for analysis is to use the output and parse it using standard Linux utilities like awk, cut and grep. ```console

indexed header

$ head -1 sample-multi-file-klp-output.csv nodeclaim[1],createdtime[2],nodepool[3],instancetypes[4],launchedtime[5],providerid[6],instancetype[7],zone[8],capacitytype[9],registeredtime[10],k8snodename[11],initializedtime[12],nodereadytime[13],nodereadytimesec[14],disruptiontime[15],disruptionreason[16],disruptiondecision[17],disruptednodecount[18],replacementnodecount[19],disruptedpodcount[20],annotationtime[21],annotation[22],tainttime[23],taint[24],interruptiontime[25],interruptionkind[26],deletedtime[27],nodeterminationtime[28],nodeterminationtimesec[29],nodelifecycletime[30],nodelifecycletimesec[31],initialized[32],deleted[33]

print nodeclaim[index/column=1], nodereadytime[13],nodereadytimesec[14]

$ cat sample-multi-file-klp-output.csv | awk -F ',' '{print $1,$13,$14 }' | more nodeclaim[1] nodereadytime[13] nodereadytimesec[14] spot-844xp 1m18.591s 78.6 default-brbk4 0s 0.0 default-lpc62 50.935s 50.9 default-j4lj7 43.617s 43.6 default-mpz2w 46.277s 46.3 default-8sxj9 36.714s 36.7 default-zgb22 35.008s 35.0 local-storage-raid-al2023-kdsvk 41.839s 41.8 local-storage-raid-al2023-tq7v5 43.922s 43.9 local-storage-raid-al2023-9kx8z 48.781s 48.8 ...

search for specific value sof a specific nodeclaim

$ cat sample-multi-file-klp-output.csv | awk -F ',' '/local-storage-raid-al2023-nccxt/ { print $1,$13,$14 }' local-storage-raid-al2023-nccxt 1m8.447s 68.4

combine directly with lp4k and raw Karpenter controller logs

$ ./bin/lp4k karpenter-log-0.37.7.txt | awk -F ',' '{ print $1,$13,$14 }' nodeclaim(1) nodereadytime(13) nodereadytimesec(14) default-brbk4 0s 0.0 default-lpc62 50.935s 50.9 default-j4lj7 43.617s 43.6 default-mpz2w 46.277s 46.3 ``` Amazon QuickSight or Microsoft Excel are possible choices to use the CSV output for advanced analysis to create graphs and/or pivot tables.

Sample 1 Sample 2

Contributing

We welcome contributions to lp4k ! Please see CONTRIBUTING.md for more information on how to report bugs or submit pull requests.

Code of conduct

This project has adopted the Amazon Open Source Code of Conduct. See CODEOFCONDUCT.md for more details.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache 2.0 License.

Owner

  • Name: Amazon Web Services - Labs
  • Login: awslabs
  • Kind: organization
  • Location: Seattle, WA

AWS Labs

GitHub Events

Total
  • Release event: 10
  • Watch event: 8
  • Delete event: 1
  • Push event: 24
  • Public event: 1
  • Create event: 10
Last Year
  • Release event: 10
  • Watch event: 8
  • Delete event: 1
  • Push event: 24
  • Public event: 1
  • Create event: 10

Dependencies

go.mod go
  • github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2
  • github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
  • github.com/emicklei/go-restful/v3 v3.12.2
  • github.com/fxamacker/cbor/v2 v2.8.0
  • github.com/go-logr/logr v1.4.2
  • github.com/go-openapi/jsonpointer v0.21.1
  • github.com/go-openapi/jsonreference v0.21.0
  • github.com/go-openapi/swag v0.23.1
  • github.com/gogo/protobuf v1.3.2
  • github.com/golang/protobuf v1.5.4
  • github.com/google/gnostic-models v0.6.9
  • github.com/google/go-cmp v0.7.0
  • github.com/google/gofuzz v1.2.0
  • github.com/google/uuid v1.6.0
  • github.com/josharian/intern v1.0.0
  • github.com/json-iterator/go v1.1.12
  • github.com/mailru/easyjson v0.9.0
  • github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
  • github.com/modern-go/reflect2 v1.0.2
  • github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
  • github.com/nav-inc/datetime v0.1.3
  • github.com/pkg/errors v0.9.1
  • github.com/spf13/pflag v1.0.6
  • github.com/x448/float16 v0.8.4
  • golang.org/x/net v0.39.0
  • golang.org/x/oauth2 v0.29.0
  • golang.org/x/sys v0.32.0
  • golang.org/x/term v0.31.0
  • golang.org/x/text v0.24.0
  • golang.org/x/time v0.11.0
  • google.golang.org/protobuf v1.36.6
  • gopkg.in/evanphx/json-patch.v4 v4.12.0
  • gopkg.in/inf.v0 v0.9.1
  • gopkg.in/yaml.v3 v3.0.1
  • k8s.io/api v0.32.3
  • k8s.io/apimachinery v0.32.3
  • k8s.io/client-go v0.32.3
  • k8s.io/klog/v2 v2.130.1
  • k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff
  • k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
  • sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8
  • sigs.k8s.io/randfill v1.0.0
  • sigs.k8s.io/structured-merge-diff/v4 v4.7.0
  • sigs.k8s.io/yaml v1.4.0
go.sum go
  • github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2
  • github.com/davecgh/go-spew v1.1.0
  • github.com/davecgh/go-spew v1.1.1
  • github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
  • github.com/emicklei/go-restful/v3 v3.12.2
  • github.com/fxamacker/cbor/v2 v2.8.0
  • github.com/go-logr/logr v1.4.2
  • github.com/go-openapi/jsonpointer v0.21.1
  • github.com/go-openapi/jsonreference v0.21.0
  • github.com/go-openapi/swag v0.23.1
  • github.com/go-task/slim-sprig/v3 v3.0.0
  • github.com/gogo/protobuf v1.3.2
  • github.com/golang/protobuf v1.5.4
  • github.com/google/gnostic-models v0.6.9
  • github.com/google/go-cmp v0.5.9
  • github.com/google/go-cmp v0.7.0
  • github.com/google/gofuzz v1.2.0
  • github.com/google/gofuzz v1.0.0
  • github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db
  • github.com/google/uuid v1.6.0
  • github.com/josharian/intern v1.0.0
  • github.com/json-iterator/go v1.1.12
  • github.com/kisielk/errcheck v1.5.0
  • github.com/kisielk/gotool v1.0.0
  • github.com/kr/pretty v0.3.1
  • github.com/kr/text v0.2.0
  • github.com/mailru/easyjson v0.9.0
  • github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
  • github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421
  • github.com/modern-go/reflect2 v1.0.2
  • github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
  • github.com/nav-inc/datetime v0.1.3
  • github.com/onsi/ginkgo/v2 v2.21.0
  • github.com/onsi/gomega v1.35.1
  • github.com/pkg/errors v0.9.1
  • github.com/pmezard/go-difflib v1.0.0
  • github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
  • github.com/rogpeppe/go-internal v1.12.0
  • github.com/spf13/pflag v1.0.6
  • github.com/stretchr/objx v0.1.0
  • github.com/stretchr/testify v1.2.1
  • github.com/stretchr/testify v1.3.0
  • github.com/stretchr/testify v1.10.0
  • github.com/x448/float16 v0.8.4
  • github.com/yuin/goldmark v1.1.27
  • github.com/yuin/goldmark v1.2.1
  • golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
  • golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
  • golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
  • golang.org/x/mod v0.2.0
  • golang.org/x/mod v0.3.0
  • golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
  • golang.org/x/net v0.0.0-20201021035429-f5854403a974
  • golang.org/x/net v0.39.0
  • golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
  • golang.org/x/net v0.0.0-20190620200207-3b0461eec859
  • golang.org/x/oauth2 v0.29.0
  • golang.org/x/sync v0.0.0-20190423024810-112230192c58
  • golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
  • golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
  • golang.org/x/sys v0.0.0-20190412213103-97732733099d
  • golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
  • golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f
  • golang.org/x/sys v0.32.0
  • golang.org/x/term v0.31.0
  • golang.org/x/text v0.3.0
  • golang.org/x/text v0.3.3
  • golang.org/x/text v0.24.0
  • golang.org/x/time v0.11.0
  • golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e
  • golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
  • golang.org/x/tools v0.0.0-20200619180055-7c47624df98f
  • golang.org/x/tools v0.0.0-20210106214847-113979e3529a
  • golang.org/x/tools v0.26.0
  • golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
  • golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
  • golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
  • golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
  • google.golang.org/protobuf v1.36.6
  • gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
  • gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
  • gopkg.in/evanphx/json-patch.v4 v4.12.0
  • gopkg.in/inf.v0 v0.9.1
  • gopkg.in/yaml.v3 v3.0.1
  • k8s.io/api v0.32.3
  • k8s.io/apimachinery v0.32.3
  • k8s.io/client-go v0.32.3
  • k8s.io/klog/v2 v2.130.1
  • k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff
  • k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e
  • sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8
  • sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016
  • sigs.k8s.io/randfill v1.0.0
  • sigs.k8s.io/structured-merge-diff/v4 v4.7.0
  • sigs.k8s.io/yaml v1.4.0