Skip to content

Commit 853cac0

Browse files
authored
Update Parsing of Logs (#11)
* update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> * update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> * update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> * update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> * update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> * update log parsing Signed-off-by: Ashima-Ashima1 <[email protected]> --------- Signed-off-by: Ashima-Ashima1 <[email protected]>
1 parent b5311df commit 853cac0

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: ashimagarg/csi
8-
newTag: "43"
8+
newTag: "44"

controllers/logParser.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ func parseLogs(nodePodLogs string) map[string]string {
3939

4040
volumesStats := map[string]string{}
4141

42-
for ind, log := range logs {
42+
for _, log := range logs {
4343
logEntry := getLogEntry(log)
44+
4445
if logEntry != nil {
4546
logMsg := logEntry.Message
4647

47-
if strings.HasPrefix(logMsg, "NodeGetVolumeStats: Request:") {
48-
logMsg = strings.TrimSpace(strings.Trim(logMsg, "NodeGetVolumeStats Request:{}"))
49-
slice := strings.Fields(logMsg)
50-
data := map[string]string{}
51-
for _, val := range slice {
52-
kv := strings.Split(val, ":")
53-
if len(kv) == 2 {
54-
data[strings.TrimSpace(kv[0])] = strings.TrimSpace(kv[1])
55-
}
56-
}
57-
58-
reqLog := logs[ind+2]
59-
logEntry := getLogEntry(reqLog)
60-
volumesStats[data["Id"]] = logEntry.Message
48+
regexToGetMap := regexp.MustCompile(`map\[(.*?)\]`)
49+
matches := regexToGetMap.FindStringSubmatch(logMsg)
50+
51+
if len(matches) == 2 {
52+
mapContent := matches[1]
53+
54+
getVolumeID := regexp.MustCompile("VolumeId:\\S+").FindStringSubmatch(mapContent)
55+
volumeID := strings.Split(getVolumeID[0], ":")[1]
56+
57+
getErrMsg := strings.ReplaceAll(mapContent, getVolumeID[0], "")
58+
errMsg := strings.Split(getErrMsg, ":")[1]
59+
60+
volumesStats[volumeID] = errMsg
6161
}
6262
}
6363
}

controllers/test_variables.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ var (
4444
testNode3 = "test-node-3"
4545
)
4646

47-
var testNodeServerPodLogs = `I0207 09:02:14.466230 1 nodeserver.go:188] NodeGetVolumeStats: Request: {VolumeId:test-pv-1 VolumePath:/var/data/kubelet/pods/360289c4-6eca-4275-a9ce-14938335117e/volumes/kubernetes.io~csi/pvc-7400b05a-12a4-43ac-bfda-a5ce6445b6ef/mount StagingTargetPath: XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
48-
I0207 09:02:14.466270 1 nodeserver.go:198] NodeGetVolumeStats: Start getting Stats
49-
E0207 09:02:14.466335 1 server.go:158] GRPC error: transport endpoint is not connected`
47+
var testNodeServerPodLogs = `E0319 05:32:00.429871 1 nodeserver.go:245] NodeGetVolumeStats: error occurred while getting volume stats map[Error:transport endpoint is not connected VolumeId:test-pv-1]`
5048

5149
func setupScheme() *runtime.Scheme {
5250
s := scheme.Scheme

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ require (
66
github.com/evanphx/json-patch/v5 v5.9.0
77
github.com/go-logr/logr v1.4.1
88
github.com/imdario/mergo v0.3.16
9-
github.com/onsi/ginkgo/v2 v2.16.0
10-
github.com/onsi/gomega v1.31.1
9+
github.com/onsi/ginkgo/v2 v2.17.0
10+
github.com/onsi/gomega v1.32.0
1111
github.com/presslabs/controller-util v0.10.0
1212
github.com/stretchr/testify v1.9.0
13-
k8s.io/api v0.29.2
14-
k8s.io/apimachinery v0.29.2
15-
k8s.io/client-go v0.29.2
13+
k8s.io/api v0.29.3
14+
k8s.io/apimachinery v0.29.3
15+
k8s.io/client-go v0.29.3
1616
sigs.k8s.io/controller-runtime v0.17.2
1717
)
1818

@@ -31,7 +31,7 @@ require (
3131
github.com/go-test/deep v1.1.0 // indirect
3232
github.com/gogo/protobuf v1.3.2 // indirect
3333
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
34-
github.com/golang/protobuf v1.5.3 // indirect
34+
github.com/golang/protobuf v1.5.4 // indirect
3535
github.com/google/gnostic-models v0.6.8 // indirect
3636
github.com/google/go-cmp v0.6.0 // indirect
3737
github.com/google/gofuzz v1.2.0 // indirect
@@ -64,7 +64,7 @@ require (
6464
golang.org/x/tools v0.17.0 // indirect
6565
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
6666
google.golang.org/appengine v1.6.7 // indirect
67-
google.golang.org/protobuf v1.31.0 // indirect
67+
google.golang.org/protobuf v1.33.0 // indirect
6868
gopkg.in/inf.v0 v0.9.1 // indirect
6969
gopkg.in/yaml.v2 v2.4.0 // indirect
7070
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
3737
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
3838
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
3939
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
40-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
41-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
42-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
40+
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
41+
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
4342
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
4443
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
45-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4644
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4745
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4846
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -82,10 +80,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
8280
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
8381
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
8482
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
85-
github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM=
86-
github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
87-
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
88-
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
83+
github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI=
84+
github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
85+
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
86+
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
8987
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9088
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9189
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -170,10 +168,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw
170168
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
171169
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
172170
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
173-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
174-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
175-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
176-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
171+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
172+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
177173
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
178174
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
179175
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
@@ -185,14 +181,14 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
185181
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
186182
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
187183
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
188-
k8s.io/api v0.29.2 h1:hBC7B9+MU+ptchxEqTNW2DkUosJpp1P+Wn6YncZ474A=
189-
k8s.io/api v0.29.2/go.mod h1:sdIaaKuU7P44aoyyLlikSLayT6Vb7bvJNCX105xZXY0=
184+
k8s.io/api v0.29.3 h1:2ORfZ7+bGC3YJqGpV0KSDDEVf8hdGQ6A03/50vj8pmw=
185+
k8s.io/api v0.29.3/go.mod h1:y2yg2NTyHUUkIoTC+phinTnEa3KFM6RZ3szxt014a80=
190186
k8s.io/apiextensions-apiserver v0.29.0 h1:0VuspFG7Hj+SxyF/Z/2T0uFbI5gb5LRgEyUVE3Q4lV0=
191187
k8s.io/apiextensions-apiserver v0.29.0/go.mod h1:TKmpy3bTS0mr9pylH0nOt/QzQRrW7/h7yLdRForMZwc=
192-
k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8=
193-
k8s.io/apimachinery v0.29.2/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU=
194-
k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg=
195-
k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA=
188+
k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU=
189+
k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU=
190+
k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg=
191+
k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0=
196192
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
197193
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
198194
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=

0 commit comments

Comments
 (0)