Skip to content

Commit 44af00c

Browse files
committed
Adding service_log handler and refactoring the SendServiceLogs function accordingly
Updated the handler to only send SL for a specific cluster to the OCM API and refactored the SendServiceLog func Update the SendServiceLogs function to handle the references Added test cases for the service_logs handler Move the SendServceLog function to handler and some updates based on review feedback
1 parent 5cc1396 commit 44af00c

File tree

8 files changed

+177
-123
lines changed

8 files changed

+177
-123
lines changed

go.mod

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ require (
77
github.com/gorilla/mux v1.8.0
88
github.com/onsi/ginkgo/v2 v2.9.5
99
github.com/onsi/gomega v1.27.7
10-
github.com/openshift-online/ocm-cli v0.1.66
11-
github.com/openshift-online/ocm-sdk-go v0.1.378
10+
github.com/openshift-online/ocm-sdk-go v0.1.331
1211
github.com/openshift/ocm-agent-operator v0.0.0-20230918023348-0f78780ccb89
1312
github.com/prometheus/alertmanager v0.25.0
1413
github.com/prometheus/client_golang v1.15.1
@@ -24,7 +23,6 @@ require (
2423
)
2524

2625
require (
27-
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
2826
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
2927
github.com/MakeNowJust/heredoc v1.0.0 // indirect
3028
github.com/aymerick/douceur v0.2.0 // indirect
@@ -58,7 +56,6 @@ require (
5856
github.com/google/uuid v1.3.0 // indirect
5957
github.com/gorilla/css v1.0.0 // indirect
6058
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
61-
github.com/hashicorp/go-version v1.6.0 // indirect
6259
github.com/hashicorp/hcl v1.0.0 // indirect
6360
github.com/imdario/mergo v0.3.12 // indirect
6461
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -74,16 +71,11 @@ require (
7471
github.com/jackc/pgx/v4 v4.17.2 // indirect
7572
github.com/josharian/intern v1.0.0 // indirect
7673
github.com/json-iterator/go v1.1.12 // indirect
77-
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
7874
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
7975
github.com/magiconair/properties v1.8.7 // indirect
8076
github.com/mailru/easyjson v0.7.7 // indirect
81-
github.com/mattn/go-colorable v0.1.13 // indirect
82-
github.com/mattn/go-isatty v0.0.16 // indirect
8377
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
84-
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
8578
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
86-
github.com/mitchellh/go-homedir v1.1.0 // indirect
8779
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
8880
github.com/mitchellh/mapstructure v1.5.0 // indirect
8981
github.com/moby/spdystream v0.2.0 // indirect

go.sum

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
3636
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3737
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
39-
github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw=
40-
github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
4139
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
4240
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
4341
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -46,8 +44,6 @@ github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ
4644
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
4745
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
4846
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
49-
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
50-
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
5147
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5248
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5349
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -84,7 +80,6 @@ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7
8480
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
8581
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
8682
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
87-
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
8883
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
8984
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9085
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -230,14 +225,10 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
230225
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
231226
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
232227
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
233-
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
234-
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
235228
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
236229
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
237230
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
238231
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
239-
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
240-
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
241232
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
242233
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
243234
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -316,8 +307,6 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
316307
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
317308
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
318309
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
319-
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
320-
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
321310
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
322311
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
323312
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -347,29 +336,18 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v
347336
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
348337
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
349338
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
350-
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
351339
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
352-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
353-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
354340
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
355341
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
356-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
357342
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
358343
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
359-
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
360-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
361344
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
362345
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
363346
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
364347
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
365-
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
366-
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
367-
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
368348
github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
369349
github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg=
370350
github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM=
371-
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
372-
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
373351
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
374352
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
375353
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
@@ -408,10 +386,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
408386
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
409387
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
410388
github.com/onsi/gomega v1.27.7/go.mod h1:1p8OOlwo2iUUDsHnOrjE5UKYJ+e3W8eQ3qSlRahPmr4=
411-
github.com/openshift-online/ocm-cli v0.1.66 h1:+zBcNLVF4zv5ru0tSelIlzWBb35/dxwXRTKwO9MYNgE=
412-
github.com/openshift-online/ocm-cli v0.1.66/go.mod h1:lTq3/GbsStzceXeIijnMHbe80w1kDWqNnTvOQV43V+w=
413-
github.com/openshift-online/ocm-sdk-go v0.1.378 h1:XpUYMRoKyl7KFhjX8GRjrPzQYxx68pLqtoD3STEoezQ=
414-
github.com/openshift-online/ocm-sdk-go v0.1.378/go.mod h1:KYOw8kAKAHyPrJcQoVR82CneQ4ofC02Na4cXXaTq4Nw=
389+
github.com/openshift-online/ocm-sdk-go v0.1.331 h1:itr1qCJja8Edrjezxoq7FPG4NBAllWNyg4Ahxcn1GVE=
390+
github.com/openshift-online/ocm-sdk-go v0.1.331/go.mod h1:KYOw8kAKAHyPrJcQoVR82CneQ4ofC02Na4cXXaTq4Nw=
415391
github.com/openshift/ocm-agent-operator v0.0.0-20230918023348-0f78780ccb89 h1:JKAJaFGjRvndjysvzfhlXgoMpyP1oJGpU0l9cAazORY=
416392
github.com/openshift/ocm-agent-operator v0.0.0-20230918023348-0f78780ccb89/go.mod h1:7M37isxr8YkoR9LZ1qsIihAl5v2j+WSPxdGjvBaTybw=
417393
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
@@ -724,15 +700,12 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
724700
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
725701
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
726702
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
727-
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
728703
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
729-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
730704
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
731705
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
732706
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
733707
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
734708
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
735-
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
736709
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
737710
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
738711
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=

pkg/consts/test/test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
1313

1414
ocmagentv1alpha1 "github.com/openshift/ocm-agent-operator/api/v1alpha1"
15-
"github.com/openshift/ocm-agent/pkg/ocm"
1615
)
1716

1817
const (
@@ -154,16 +153,6 @@ func NewTestAlert(resolved, fleet bool) template.Alert {
154153
return alert
155154
}
156155

157-
func NewServiceLog(summary, desc string) ocm.ServiceLog {
158-
return ocm.ServiceLog{
159-
ServiceName: "SREManualAction",
160-
ClusterUUID: "ddb5e04c-87ea-4fcd-b1f9-640981726cc5",
161-
Summary: summary,
162-
InternalOnly: false,
163-
Description: desc,
164-
}
165-
}
166-
167156
func setScheme(scheme *runtime.Scheme) *runtime.Scheme {
168157
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
169158
utilruntime.Must(ocmagentv1alpha1.SchemeBuilder.AddToScheme(scheme))

pkg/handlers/helper.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ import (
55
"fmt"
66
"net/http"
77

8-
"github.com/openshift-online/ocm-cli/pkg/arguments"
98
sdk "github.com/openshift-online/ocm-sdk-go"
10-
"github.com/openshift/ocm-agent-operator/api/v1alpha1"
119
"github.com/prometheus/alertmanager/template"
1210
log "github.com/sirupsen/logrus"
1311
"sigs.k8s.io/controller-runtime/pkg/client"
1412

15-
"github.com/openshift/ocm-agent/pkg/consts"
16-
"github.com/openshift/ocm-agent/pkg/ocm"
17-
1813
_ "github.com/golang/mock/mockgen/model"
1914
)
2015

@@ -56,12 +51,6 @@ type AMReceiverData template.Data
5651
type AMReceiverAlert template.Alert
5752

5853
// OCMClient enables implementation of OCM Client
59-
//
60-
//go:generate mockgen -destination=mocks/helper.go -package=mocks github.com/openshift/ocm-agent/pkg/handlers OCMClient
61-
type OCMClient interface {
62-
SendServiceLog(summary, firingDesc, resolveDesc, clusterID string, severity v1alpha1.NotificationSeverity, logType string, references []v1alpha1.NotificationReferenceType, firing bool) error
63-
}
64-
6554
type ocmsdkclient struct {
6655
ocm *sdk.Connection
6756
}
@@ -139,53 +128,6 @@ func alertName(a template.Alert) (*string, error) {
139128
return nil, fmt.Errorf("no alertname defined in alert")
140129
}
141130

142-
// SendServiceLog sends a servicelog notification for the given alert
143-
func (o *ocmsdkclient) SendServiceLog(summary, firingDesc, resolveDesc, clusterID string, severity v1alpha1.NotificationSeverity, logType string, references []v1alpha1.NotificationReferenceType, firing bool) error {
144-
req := o.ocm.Post()
145-
err := arguments.ApplyPathArg(req, "/api/service_logs/v1/cluster_logs")
146-
if err != nil {
147-
return err
148-
}
149-
150-
sl := ocm.ServiceLog{
151-
ServiceName: consts.ServiceLogServiceName,
152-
ClusterUUID: clusterID,
153-
Summary: summary,
154-
InternalOnly: false,
155-
Severity: severity,
156-
LogType: logType,
157-
DocReferences: references,
158-
}
159-
160-
// Use different Summary and Description for firing and resolved status for an alert
161-
if firing {
162-
sl.Description = firingDesc
163-
sl.Summary = ServiceLogActivePrefix + ": " + summary
164-
} else {
165-
sl.Description = resolveDesc
166-
sl.Summary = ServiceLogResolvePrefix + ": " + summary
167-
}
168-
slAsBytes, err := json.Marshal(sl)
169-
if err != nil {
170-
return err
171-
}
172-
173-
req.Bytes(slAsBytes)
174-
175-
res, err := req.Send()
176-
if err != nil {
177-
return err
178-
}
179-
180-
operationId := res.Header(HeaderOperationId)
181-
err = responseChecker(operationId, res.Status(), res.Bytes())
182-
if err != nil {
183-
return err
184-
}
185-
186-
return nil
187-
}
188-
189131
// responseChecker checks the ocm response returns error or not
190132
func responseChecker(opId string, statusCode int, asBytes []byte) error {
191133
if statusCode == http.StatusCreated {

pkg/handlers/service_logs.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
sdk "github.com/openshift-online/ocm-sdk-go"
9+
slv1 "github.com/openshift-online/ocm-sdk-go/servicelogs/v1"
10+
"github.com/openshift/ocm-agent-operator/api/v1alpha1"
11+
"github.com/openshift/ocm-agent/pkg/consts"
12+
log "github.com/sirupsen/logrus"
13+
)
14+
15+
type OCMClient interface {
16+
SendServiceLog(summary, firingDesc, resolveDesc, clusterID string, severity v1alpha1.NotificationSeverity, logType string, references []v1alpha1.NotificationReferenceType, firing bool) error
17+
}
18+
19+
// ServiceLogsHandler manages service logs via the OCM API.
20+
type ServiceLogsHandler struct {
21+
ocm *sdk.Connection
22+
}
23+
24+
// NewServiceLogsHandler creates a new handler for service logs.
25+
func NewServiceLogsHandler(o *sdk.Connection) *ServiceLogsHandler {
26+
log.Debug("Creating new service logs handler")
27+
return &ServiceLogsHandler{
28+
ocm: o,
29+
}
30+
}
31+
32+
// PostServiceLog sends a service log for a specific cluster to the OCM API.
33+
func (h *ServiceLogsHandler) PostServiceLog(logEntry *slv1.LogEntry) error {
34+
// Use the OCM SDK to construct the request for posting a service log for a specific cluster.
35+
request := h.ocm.ServiceLogs().V1().ClusterLogs().Add().Body(logEntry)
36+
37+
// Send the request to the OCM API.
38+
response, err := request.Send()
39+
if err != nil {
40+
return fmt.Errorf("can't post service log: %v", err)
41+
}
42+
43+
// Check the response status code.
44+
if response.Status() != http.StatusCreated {
45+
// Extract error details from the response and return an appropriate error.
46+
return fmt.Errorf("unexpected status: %d", response.Status())
47+
}
48+
49+
return nil
50+
}
51+
52+
func (o *ocmsdkclient) SendServiceLog(summary, firingDesc, resolveDesc, clusterUUID string, severity v1alpha1.NotificationSeverity, logType string, references []v1alpha1.NotificationReferenceType, firing bool) error {
53+
// Construct the LogEntry using the builder pattern provided by the SDK.
54+
logBuilder := slv1.NewLogEntry().
55+
Summary(summary).
56+
Description(firingDesc).
57+
ServiceName(consts.ServiceLogServiceName).
58+
ClusterUUID(clusterUUID).
59+
InternalOnly(false).
60+
Severity(slv1.Severity(severity)).
61+
LogType(slv1.LogType(logType))
62+
63+
// Adjust the summary based on whether the alert is firing or resolved.
64+
if firing {
65+
refs, err := json.Marshal(references)
66+
if err != nil {
67+
return fmt.Errorf("failed to marshal references: %v", err)
68+
}
69+
refsDesc := fmt.Sprintf("References: %s", string(refs))
70+
descriptionWithRefs := fmt.Sprintf("%s\n%s", firingDesc, refsDesc)
71+
logBuilder = logBuilder.Summary(ServiceLogActivePrefix + ": " + summary).Description(descriptionWithRefs)
72+
} else {
73+
logBuilder = logBuilder.Summary(ServiceLogResolvePrefix + ": " + summary).Description(resolveDesc)
74+
}
75+
76+
// Build the log entry.
77+
logEntry, err := logBuilder.Build()
78+
if err != nil {
79+
return fmt.Errorf("failed to build log entry: %v", err)
80+
}
81+
82+
// Initialize the ServiceLogsHandler with the OCM client.
83+
serviceLogsHandler := NewServiceLogsHandler(o.ocm)
84+
85+
// Use the servicelog handler to send the service log.
86+
if err := serviceLogsHandler.PostServiceLog(logEntry); err != nil {
87+
return fmt.Errorf("failed to post service log: %v", err)
88+
}
89+
90+
return nil
91+
}

0 commit comments

Comments
 (0)