From fa2ecf2e2308f3ff5badb8d8148d2f2ea5f97b46 Mon Sep 17 00:00:00 2001 From: Mahan Zendedel DH Date: Thu, 4 Jul 2024 16:00:51 +0400 Subject: [PATCH] feat: update sdk and refactor (#35) --- go.mod | 55 ++++- go.sum | 185 ++++++++++++++++- main.go | 5 +- plugin/gcp/compute.go | 26 ++- plugin/gcp/compute_test.go | 34 ++-- plugin/gcp/config_test.go | 2 - plugin/gcp/metrics.go | 10 +- plugin/gcp/metrics_test.go | 10 +- .../compute_instance/compute_instance.go | 13 +- .../compute_instance/compute_instance_item.go | 189 ++++++++---------- .../job_compute_instance_list.go | 24 +-- .../job_get_compute_instance_metrics.go | 89 ++++----- .../job_optimize_compute_instance.go | 74 +++---- plugin/service.go | 13 +- utils/concurrent_map.go | 37 ---- 15 files changed, 466 insertions(+), 300 deletions(-) delete mode 100644 utils/concurrent_map.go diff --git a/go.mod b/go.mod index 732967d..a7bc982 100644 --- a/go.mod +++ b/go.mod @@ -5,34 +5,79 @@ go 1.21.5 require ( cloud.google.com/go/compute v1.25.1 cloud.google.com/go/monitoring v1.18.0 + github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 - github.com/kaytu-io/kaytu v0.14.0-rc.0.0.20240619114201-51f5733d10b6 + github.com/kaytu-io/kaytu v0.14.6 golang.org/x/oauth2 v0.21.0 google.golang.org/api v0.169.0 + google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.2 ) require ( cloud.google.com/go/compute/metadata v0.3.0 // indirect + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect + github.com/agext/levenshtein v1.2.3 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/bubbles v0.18.0 // indirect + github.com/charmbracelet/bubbletea v0.26.4 // indirect github.com/charmbracelet/lipgloss v0.10.0 // indirect + github.com/charmbracelet/x/ansi v0.1.2 // indirect + github.com/charmbracelet/x/input v0.1.1 // indirect + github.com/charmbracelet/x/term v0.1.1 // indirect + github.com/charmbracelet/x/windows v0.1.2 // indirect + github.com/cloudflare/circl v1.3.8 // indirect + github.com/cyphar/filepath-securejoin v0.2.5 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/evertras/bubble-table v0.16.0 // indirect + github.com/fatih/color v1.17.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-git/go-git/v5 v5.12.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/google/go-github v17.0.0+incompatible // indirect + github.com/google/go-github/v62 v62.0.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.12.2 // indirect + github.com/hashicorp/hcl/v2 v2.20.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jedib0t/go-pretty/v6 v6.5.9 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/schollz/progressbar/v3 v3.14.3 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect github.com/spf13/cobra v1.8.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + github.com/zclconf/go-cty v1.14.4 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect @@ -40,13 +85,17 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.24.0 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.21.0 // indirect + golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect - google.golang.org/grpc v1.64.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d44d9ac..4329946 100644 --- a/go.sum +++ b/go.sum @@ -7,29 +7,88 @@ cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2Qx cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= cloud.google.com/go/monitoring v1.18.0 h1:NfkDLQDG2UR3WYZVQE8kwSbUIEyIqJUPl+aOQdFH1T4= cloud.google.com/go/monitoring v1.18.0/go.mod h1:c92vVBCeq/OB4Ioyo+NbN2U7tlg5ZH41PZcdvfc+Lcg= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= +github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= +github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= +github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= +github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= +github.com/charmbracelet/bubbletea v0.26.4 h1:2gDkkzLZaTjMl/dQBpNVtnvcCxsh/FCkimep7FC9c40= +github.com/charmbracelet/bubbletea v0.26.4/go.mod h1:P+r+RRA5qtI1DOHNFn0otoNwB4rn+zNAzSj/EXz6xU0= github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= +github.com/charmbracelet/x/ansi v0.1.2 h1:6+LR39uG8DE6zAmbu023YlqjJHkYXDF1z36ZwzO4xZY= +github.com/charmbracelet/x/ansi v0.1.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/input v0.1.1 h1:YDOJaTUKCqtGnq9PHzx3pkkl4pXDOANUHmhH3DqMtM4= +github.com/charmbracelet/x/input v0.1.1/go.mod h1:jvdTVUnNWj/RD6hjC4FsoB0SeZCJ2ZBkiuFP9zXvZI0= +github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= +github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= +github.com/charmbracelet/x/windows v0.1.2 h1:Iumiwq2G+BRmgoayww/qfcvof7W/3uLoelhxojXlRWg= +github.com/charmbracelet/x/windows v0.1.2/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI= +github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= +github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +github.com/evertras/bubble-table v0.16.0 h1:Bt2cPukoP8DSWVpBcPSq2E3W2fs7R0mf5BaIFQxFPfM= +github.com/evertras/bubble-table v0.16.0/go.mod h1:SPOZKbIpyYWPHBNki3fyNpiPBQkvkULAtOT7NTD5fKY= +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= +github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -51,9 +110,16 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= +github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4= +github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -63,21 +129,56 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= +github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/kaytu-io/kaytu v0.14.0-rc.0.0.20240619114201-51f5733d10b6 h1:OyrvbIttya/35K+6N1tyI953BlKclIkHGWIZ/IPYheg= -github.com/kaytu-io/kaytu v0.14.0-rc.0.0.20240619114201-51f5733d10b6/go.mod h1:csDLaCgTnp/D9SZuo55KjOzp/BYfkhkeSkGuEiCljtc= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU= +github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= +github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= +github.com/kaytu-io/kaytu v0.14.6 h1:nub3/JEKoUKaUCqhDuiItXp5O1Gl0rcxGFXtvdkowE8= +github.com/kaytu-io/kaytu v0.14.6/go.mod h1:nQyzQiNDH4pPZBENaevC85kdvZSdhECHRIfo7ZVVF1c= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -85,7 +186,16 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/schollz/progressbar/v3 v3.14.3 h1:oOuWW19ka12wxYU1XblR4n16wF/2Y1dBLMarMo6p4xU= +github.com/schollz/progressbar/v3 v3.14.3/go.mod h1:aT3UQ7yGm+2ZjeXPqsjTenwL3ddUiuZ0kfQ/2tHlyNI= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -93,11 +203,23 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= +github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= @@ -114,18 +236,35 @@ go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -134,17 +273,46 @@ golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -154,6 +322,12 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= @@ -187,6 +361,13 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 8f092be..9054519 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,13 @@ package main import ( + "context" + "github.com/kaytu-io/kaytu/cmd" "github.com/kaytu-io/kaytu/pkg/plugin/sdk" "github.com/kaytu-io/plugin-gcp/plugin" ) func main() { - sdk.New(plugin.NewPlugin(), 4).Execute() + ctx := cmd.AppendSignalHandling(context.Background()) + sdk.New(plugin.NewPlugin(), 4).Execute(ctx) } diff --git a/plugin/gcp/compute.go b/plugin/gcp/compute.go index cde40b1..50ff20f 100644 --- a/plugin/gcp/compute.go +++ b/plugin/gcp/compute.go @@ -6,6 +6,7 @@ import ( computeApi "cloud.google.com/go/compute/apiv1" "cloud.google.com/go/compute/apiv1/computepb" "context" + "errors" "google.golang.org/api/compute/v1" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -27,7 +28,10 @@ func NewCompute(scopes []string) *Compute { func (c *Compute) InitializeClient(ctx context.Context) error { - c.GCP.GetCredentials(ctx) + err := c.GCP.GetCredentials(ctx) + if err != nil { + return err + } // log.Println(string(c.GCP.credentials.JSON)) // log.Println(c.GCP.ProjectID) @@ -77,19 +81,19 @@ func (c *Compute) CloseClient() error { return nil } -func (c *Compute) ListAllInstances() error { +func (c *Compute) ListAllInstances(ctx context.Context) error { req := &computepb.AggregatedListInstancesRequest{ Project: c.ProjectID, } - it := c.instancesClient.AggregatedList(context.Background(), req) + it := c.instancesClient.AggregatedList(ctx, req) log.Println("instances found: ") for { pair, err := it.Next() - if err == iterator.Done { + if errors.Is(err, iterator.Done) { break } if err != nil { @@ -108,7 +112,7 @@ func (c *Compute) ListAllInstances() error { return nil } -func (c *Compute) GetAllInstances() ([]*computepb.Instance, error) { +func (c *Compute) GetAllInstances(ctx context.Context) ([]*computepb.Instance, error) { var allInstances []*computepb.Instance @@ -116,7 +120,7 @@ func (c *Compute) GetAllInstances() ([]*computepb.Instance, error) { Project: c.ProjectID, } - it := c.instancesClient.AggregatedList(context.Background(), req) + it := c.instancesClient.AggregatedList(ctx, req) log.Println("instances found: ") @@ -146,23 +150,23 @@ func (c *Compute) GetAllInstances() ([]*computepb.Instance, error) { return allInstances, nil } -func (c *Compute) GetDiskDetails(zone, diskName string) (*compute.Disk, error) { - disk, err := c.computeService.Disks.Get(c.ProjectID, zone, diskName).Context(context.Background()).Do() +func (c *Compute) GetDiskDetails(ctx context.Context, zone, diskName string) (*compute.Disk, error) { + disk, err := c.computeService.Disks.Get(c.ProjectID, zone, diskName).Context(ctx).Do() if err != nil { return nil, err } return disk, nil } -func (c *Compute) GetMemory(InstanceMachineType string, zone string) (*int32, error) { +func (c *Compute) GetMemory(ctx context.Context, instanceMachineType string, zone string) (*int32, error) { request := &computepb.GetMachineTypeRequest{ Project: c.ProjectID, - MachineType: InstanceMachineType, + MachineType: instanceMachineType, Zone: zone, } - machineType, err := c.machineTypeClient.Get(context.Background(), request) + machineType, err := c.machineTypeClient.Get(ctx, request) if err != nil { return nil, err } diff --git a/plugin/gcp/compute_test.go b/plugin/gcp/compute_test.go index dd7a8cc..d52a36f 100644 --- a/plugin/gcp/compute_test.go +++ b/plugin/gcp/compute_test.go @@ -7,6 +7,10 @@ import ( "testing" ) +var ( + ctx = context.Background() +) + func TestListAllInstances(t *testing.T) { log.Printf("running %s", t.Name()) compute := NewCompute( @@ -14,20 +18,18 @@ func TestListAllInstances(t *testing.T) { "https://www.googleapis.com/auth/compute.readonly", }, ) - err := compute.InitializeClient(context.Background()) + err := compute.InitializeClient(ctx) if err != nil { t.Errorf("[%s]: %s", t.Name(), err.Error()) + return } - + defer compute.CloseClient() log.Printf("[%s]: %s", t.Name(), compute.ProjectID) - err = compute.ListAllInstances() + err = compute.ListAllInstances(ctx) if err != nil { - compute.CloseClient() t.Errorf("[%s]: %s", t.Name(), err.Error()) } - compute.CloseClient() - } func TestGetAllInstances(t *testing.T) { @@ -38,27 +40,24 @@ func TestGetAllInstances(t *testing.T) { "https://www.googleapis.com/auth/compute.readonly", }, ) - err := compute.InitializeClient(context.Background()) + err := compute.InitializeClient(ctx) if err != nil { t.Errorf("[%s]: %s", t.Name(), err.Error()) + return } + defer compute.CloseClient() log.Printf("[%s]: %s", t.Name(), compute.ProjectID) - instances, err := compute.GetAllInstances() + instances, err := compute.GetAllInstances(ctx) if err != nil { - compute.CloseClient() t.Errorf("[%s]: %s", t.Name(), err.Error()) + return } for _, instance := range instances { log.Println(instance.GetMachineType()) } - - // log.Println(instances) - - compute.CloseClient() - } // TEST_INSTANCE_ZONE="us-east1-b" TEST_INSTANCE_MACHINE_TYPE="e2-micro" TEST_INSTANCE_ID="7828543314219019363" make testgcp @@ -73,16 +72,17 @@ func TestGetMemory(t *testing.T) { "https://www.googleapis.com/auth/compute.readonly", }, ) - err := compute.InitializeClient(context.Background()) + err := compute.InitializeClient(ctx) if err != nil { t.Errorf("[%s]: %s", t.Name(), err.Error()) + return } + defer compute.CloseClient() - memory, err := compute.GetMemory(machineType, zone) + memory, err := compute.GetMemory(ctx, machineType, zone) if err != nil { t.Errorf("[%s]: %s", t.Name(), err.Error()) } log.Printf("Memory : %d", &memory) - } diff --git a/plugin/gcp/config_test.go b/plugin/gcp/config_test.go index a9904d7..ffae0e0 100644 --- a/plugin/gcp/config_test.go +++ b/plugin/gcp/config_test.go @@ -6,7 +6,6 @@ import ( ) func TestIdentify(t *testing.T) { - test_project_id := "test-project-id" gcp := GCP{ ProjectID: test_project_id, @@ -18,5 +17,4 @@ func TestIdentify(t *testing.T) { if identification["project_id"] != test_project_id { t.Error("TestIdentify failed") } - } diff --git a/plugin/gcp/metrics.go b/plugin/gcp/metrics.go index 7c7bd46..f65fd9d 100644 --- a/plugin/gcp/metrics.go +++ b/plugin/gcp/metrics.go @@ -23,8 +23,10 @@ func NewCloudMonitoring(scopes []string) *CloudMonitoring { } func (c *CloudMonitoring) InitializeClient(ctx context.Context) error { - - c.GCP.GetCredentials(ctx) + err := c.GCP.GetCredentials(ctx) + if err != nil { + return err + } metricClient, err := monitoring.NewMetricClient(ctx) if err != nil { @@ -60,10 +62,10 @@ func (c *CloudMonitoring) NewTimeSeriesRequest( } -func (c *CloudMonitoring) GetMetric(request *monitoringpb.ListTimeSeriesRequest) ([]*golang2.DataPoint, error) { +func (c *CloudMonitoring) GetMetric(ctx context.Context, request *monitoringpb.ListTimeSeriesRequest) ([]*golang2.DataPoint, error) { var dps []*golang2.DataPoint - it := c.client.ListTimeSeries(context.Background(), request) + it := c.client.ListTimeSeries(ctx, request) for { resp, err := it.Next() diff --git a/plugin/gcp/metrics_test.go b/plugin/gcp/metrics_test.go index 8f2a388..98bb087 100644 --- a/plugin/gcp/metrics_test.go +++ b/plugin/gcp/metrics_test.go @@ -1,7 +1,6 @@ package gcp import ( - "context" "fmt" "os" "testing" @@ -30,10 +29,12 @@ func TestGetMetrics(t *testing.T) { "https://www.googleapis.com/auth/monitoring.read", }, ) - err := metric.InitializeClient(context.Background()) + err := metric.InitializeClient(ctx) if err != nil { t.Errorf("[%s]: %s", t.Name(), err.Error()) + return } + defer metric.CloseClient() // creating the metric request for the instance memoryRequest := metric.NewTimeSeriesRequest( @@ -55,9 +56,10 @@ func TestGetMetrics(t *testing.T) { ) // execute the request - resp, err := metric.GetMetric(memoryRequest) + resp, err := metric.GetMetric(ctx, memoryRequest) if err != nil { t.Error(err) + return } // log.Printf("metrics: %s", resp.GetMetric().String()) @@ -69,6 +71,4 @@ func TestGetMetrics(t *testing.T) { // for _, point := range resp.Points { // log.Printf("Point : %.0f", point.GetValue().GetDoubleValue()) // } - - metric.CloseClient() } diff --git a/plugin/processor/compute_instance/compute_instance.go b/plugin/processor/compute_instance/compute_instance.go index b68af47..39bc684 100644 --- a/plugin/processor/compute_instance/compute_instance.go +++ b/plugin/processor/compute_instance/compute_instance.go @@ -8,7 +8,6 @@ import ( "github.com/kaytu-io/kaytu/pkg/utils" "github.com/kaytu-io/plugin-gcp/plugin/gcp" golang2 "github.com/kaytu-io/plugin-gcp/plugin/proto/src/golang/gcp" - util "github.com/kaytu-io/plugin-gcp/utils" "strconv" "strings" "sync/atomic" @@ -17,7 +16,7 @@ import ( type ComputeInstanceProcessor struct { provider *gcp.Compute metricProvider *gcp.CloudMonitoring - items util.ConcurrentMap[string, ComputeInstanceItem] + items utils.ConcurrentMap[string, ComputeInstanceItem] publishOptimizationItem func(item *golang.ChartOptimizationItem) publishResultSummary func(summary *golang.ResultSummary) kaytuAcccessToken string @@ -25,7 +24,9 @@ type ComputeInstanceProcessor struct { lazyloadCounter atomic.Uint32 client golang2.OptimizationClient - summary util.ConcurrentMap[string, ComputeInstanceSummary] + defaultPreferences []*golang.PreferenceItem + + summary utils.ConcurrentMap[string, ComputeInstanceSummary] } func NewComputeInstanceProcessor( @@ -36,17 +37,19 @@ func NewComputeInstanceProcessor( kaytuAcccessToken string, jobQueue *sdk.JobQueue, client golang2.OptimizationClient, + defaultPreferences []*golang.PreferenceItem, ) *ComputeInstanceProcessor { r := &ComputeInstanceProcessor{ provider: prv, metricProvider: metricPrv, - items: util.NewMap[string, ComputeInstanceItem](), + items: utils.NewConcurrentMap[string, ComputeInstanceItem](), publishOptimizationItem: publishOptimizationItem, publishResultSummary: publishResultSummary, kaytuAcccessToken: kaytuAcccessToken, jobQueue: jobQueue, lazyloadCounter: atomic.Uint32{}, client: client, + defaultPreferences: defaultPreferences, } jobQueue.Push(NewListComputeInstancesJob(r)) @@ -59,7 +62,7 @@ func (m *ComputeInstanceProcessor) ReEvaluate(id string, items []*golang.Prefere m.items.Set(id, v) v.OptimizationLoading = true m.publishOptimizationItem(v.ToOptimizationItem()) - m.jobQueue.Push(NewOptimizeComputeInstancesJob(m, v)) + m.jobQueue.Push(NewOptimizeComputeInstancesJob(m, id)) } func (m *ComputeInstanceProcessor) ExportNonInteractive() *golang.NonInteractiveExport { diff --git a/plugin/processor/compute_instance/compute_instance_item.go b/plugin/processor/compute_instance/compute_instance_item.go index 86f9e49..6d46d0e 100644 --- a/plugin/processor/compute_instance/compute_instance_item.go +++ b/plugin/processor/compute_instance/compute_instance_item.go @@ -28,7 +28,7 @@ type ComputeInstanceItem struct { Disks []compute.Disk Metrics map[string][]*golang2.DataPoint DisksMetrics map[string]map[string][]*golang2.DataPoint - Wastage golang2.GCPComputeOptimizationResponse + Wastage *golang2.GCPComputeOptimizationResponse } func (i ComputeInstanceItem) ComputeInstanceDevice() (*golang.ChartRow, map[string]*golang.Properties) { @@ -48,58 +48,50 @@ func (i ComputeInstanceItem) ComputeInstanceDevice() (*golang.ChartRow, map[stri Value: "Compute Instance", } - row.Values["current_cost"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost), + row.Values["project_id"] = &golang.ChartRowItem{ + Value: i.ProjectId, } - RegionProperty := &golang.Property{ - Key: "Region", - Current: i.Wastage.Rightsizing.Current.Region, - } + RegionProperty := &golang.Property{Key: "Region"} + MachineTypeProperty := &golang.Property{Key: "Machine Type"} + MachineFamilyProperty := &golang.Property{Key: "Machine Family"} + CPUProperty := &golang.Property{Key: " CPU"} + MemoryProperty := &golang.Property{Key: " MemoryMB"} - MachineTypeProperty := &golang.Property{ - Key: "Machine Type", - Current: i.Wastage.Rightsizing.Current.MachineType, - } - MachineFamilyProperty := &golang.Property{ - Key: "Machine Family", - Current: i.Wastage.Rightsizing.Current.MachineFamily, - } - CPUProperty := &golang.Property{ - Key: " CPU", - Current: fmt.Sprintf("%d", i.Wastage.Rightsizing.Current.Cpu), - Average: utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Cpu.Avg)), - Max: utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Cpu.Max)), - } + if i.Wastage != nil { + RegionProperty.Current = i.Wastage.Rightsizing.Current.Region + MachineTypeProperty.Current = i.Wastage.Rightsizing.Current.MachineType + MachineFamilyProperty.Current = i.Wastage.Rightsizing.Current.MachineFamily - memoryProperty := &golang.Property{ - Key: " MemoryMB", - Current: fmt.Sprintf("%d MB", i.Wastage.Rightsizing.Current.MemoryMb), - Average: utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Memory.Avg)), - Max: utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Memory.Max)), - } + CPUProperty.Current = fmt.Sprintf("%d", i.Wastage.Rightsizing.Current.Cpu) + CPUProperty.Average = utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Cpu.Avg)) + CPUProperty.Max = utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Cpu.Max)) - row.Values["project_id"] = &golang.ChartRowItem{ - Value: i.ProjectId, - } + MemoryProperty.Current = fmt.Sprintf("%d MB", i.Wastage.Rightsizing.Current.MemoryMb) + MemoryProperty.Average = utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Memory.Avg)) + MemoryProperty.Max = utils.Percentage(PWrapperDouble(i.Wastage.Rightsizing.Memory.Max)) - row.Values["current_cost"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost), - } + row.Values["current_cost"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost), + } - if i.Wastage.Rightsizing.Recommended != nil { - row.Values["right_sized_cost"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Recommended.Cost), + row.Values["current_cost"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost), } - row.Values["savings"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost - i.Wastage.Rightsizing.Recommended.Cost), + + if i.Wastage.Rightsizing.Recommended != nil { + row.Values["right_sized_cost"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Recommended.Cost), + } + row.Values["savings"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(i.Wastage.Rightsizing.Current.Cost - i.Wastage.Rightsizing.Recommended.Cost), + } + RegionProperty.Recommended = i.Wastage.Rightsizing.Recommended.Region + MachineTypeProperty.Recommended = i.Wastage.Rightsizing.Recommended.MachineType + CPUProperty.Recommended = fmt.Sprintf("%d", i.Wastage.Rightsizing.Recommended.Cpu) + MemoryProperty.Recommended = fmt.Sprintf("%d MB", i.Wastage.Rightsizing.Recommended.MemoryMb) } - RegionProperty.Recommended = i.Wastage.Rightsizing.Recommended.Region - MachineTypeProperty.Recommended = i.Wastage.Rightsizing.Recommended.MachineType - CPUProperty.Recommended = fmt.Sprintf("%d", i.Wastage.Rightsizing.Recommended.Cpu) - memoryProperty.Recommended = fmt.Sprintf("%d MB", i.Wastage.Rightsizing.Recommended.MemoryMb) } - props := make(map[string]*golang.Properties) properties := &golang.Properties{} @@ -110,7 +102,7 @@ func (i ComputeInstanceItem) ComputeInstanceDevice() (*golang.ChartRow, map[stri Key: "Compute", }) properties.Properties = append(properties.Properties, CPUProperty) - properties.Properties = append(properties.Properties, memoryProperty) + properties.Properties = append(properties.Properties, MemoryProperty) props[i.Id] = properties @@ -123,8 +115,6 @@ func (i ComputeInstanceItem) ComputeDiskDevice() ([]*golang.ChartRow, map[string for _, d := range i.Disks { key := strconv.FormatUint(d.Id, 10) - disk := i.Wastage.VolumesRightsizing[key] - row := golang.ChartRow{ RowId: key, Values: make(map[string]*golang.ChartRowItem), @@ -144,62 +134,55 @@ func (i ComputeInstanceItem) ComputeDiskDevice() ([]*golang.ChartRow, map[string Value: "Compute Disk", } - row.Values["current_cost"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(disk.Current.Cost), - } - - RegionProperty := &golang.Property{ - Key: "Region", - Current: disk.Current.Region, - } - - DiskTypeProperty := &golang.Property{ - Key: "Disk Type", - Current: disk.Current.DiskType, - } - DiskSizeProperty := &golang.Property{ - Key: "Disk Size", - Current: fmt.Sprintf("%d GB", disk.Current.DiskSize), - } - DiskReadIopsProperty := &golang.Property{ - Key: " Read IOPS Expectation", - Current: fmt.Sprintf("%d", disk.Current.ReadIopsLimit), - Average: utils.PFloat64ToString(PWrapperDouble(disk.ReadIops.Avg)), - Max: utils.PFloat64ToString(PWrapperDouble(disk.ReadIops.Max)), - } - DiskWriteIopsProperty := &golang.Property{ - Key: " Write IOPS Expectation", - Current: fmt.Sprintf("%d", disk.Current.WriteIopsLimit), - Average: utils.PFloat64ToString(PWrapperDouble(disk.WriteIops.Avg)), - Max: utils.PFloat64ToString(PWrapperDouble(disk.WriteIops.Max)), - } - DiskReadThroughputProperty := &golang.Property{ - Key: " Read Throughput Expectation", - Current: fmt.Sprintf("%.2f Mb", disk.Current.ReadThroughputLimit), - Average: fmt.Sprintf("%s Mb", utils.PFloat64ToString(PWrapperDouble(disk.ReadThroughput.Avg))), - Max: fmt.Sprintf("%s Mb", utils.PFloat64ToString(PWrapperDouble(disk.ReadThroughput.Max))), - } - DiskWriteThroughputProperty := &golang.Property{ - Key: " Write Throughput Expectation", - Current: fmt.Sprintf("%.2f Mb", disk.Current.WriteThroughputLimit), - Average: fmt.Sprintf("%s Mb", utils.PFloat64ToString(PWrapperDouble(disk.WriteThroughput.Avg))), - Max: fmt.Sprintf("%s Mb", utils.PFloat64ToString(PWrapperDouble(disk.WriteThroughput.Max))), - } - - if disk.Recommended != nil { - row.Values["right_sized_cost"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(disk.Recommended.Cost), + RegionProperty := &golang.Property{Key: "Region"} + DiskTypeProperty := &golang.Property{Key: "Disk Type"} + DiskSizeProperty := &golang.Property{Key: "Disk Size"} + DiskReadIopsProperty := &golang.Property{Key: " Read IOPS Expectation"} + DiskWriteIopsProperty := &golang.Property{Key: " Write IOPS Expectation"} + DiskReadThroughputProperty := &golang.Property{Key: " Read Throughput Expectation"} + DiskWriteThroughputProperty := &golang.Property{Key: " Write Throughput Expectation"} + + if i.Wastage != nil { + disk := i.Wastage.VolumesRightsizing[key] + row.Values["current_cost"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(disk.Current.Cost), } - row.Values["savings"] = &golang.ChartRowItem{ - Value: utils.FormatPriceFloat(disk.Current.Cost - disk.Recommended.Cost), + + RegionProperty.Current = disk.Current.Region + DiskTypeProperty.Current = disk.Current.DiskType + DiskSizeProperty.Current = fmt.Sprintf("%d GB", disk.Current.DiskSize) + + DiskReadIopsProperty.Current = fmt.Sprintf("%d", disk.Current.ReadIopsLimit) + DiskReadIopsProperty.Average = utils.PFloat64ToString(PWrapperDouble(disk.ReadIops.Avg)) + DiskReadIopsProperty.Max = utils.PFloat64ToString(PWrapperDouble(disk.ReadIops.Max)) + + DiskWriteIopsProperty.Current = fmt.Sprintf("%d", disk.Current.WriteIopsLimit) + DiskWriteIopsProperty.Average = utils.PFloat64ToString(PWrapperDouble(disk.WriteIops.Avg)) + DiskWriteIopsProperty.Max = utils.PFloat64ToString(PWrapperDouble(disk.WriteIops.Max)) + + DiskReadThroughputProperty.Current = fmt.Sprintf("%.2f Mb", disk.Current.ReadThroughputLimit) + DiskReadThroughputProperty.Average = utils.PFloat64ToString(PWrapperDouble(disk.ReadThroughput.Avg)) + DiskReadThroughputProperty.Max = utils.PFloat64ToString(PWrapperDouble(disk.ReadThroughput.Max)) + + DiskWriteThroughputProperty.Current = fmt.Sprintf("%.2f Mb", disk.Current.WriteThroughputLimit) + DiskWriteThroughputProperty.Average = utils.PFloat64ToString(PWrapperDouble(disk.WriteThroughput.Avg)) + DiskWriteThroughputProperty.Max = utils.PFloat64ToString(PWrapperDouble(disk.WriteThroughput.Max)) + + if disk.Recommended != nil { + row.Values["right_sized_cost"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(disk.Recommended.Cost), + } + row.Values["savings"] = &golang.ChartRowItem{ + Value: utils.FormatPriceFloat(disk.Current.Cost - disk.Recommended.Cost), + } + RegionProperty.Recommended = disk.Recommended.Region + DiskTypeProperty.Recommended = disk.Recommended.DiskType + DiskReadIopsProperty.Recommended = fmt.Sprintf("%d", disk.Recommended.ReadIopsLimit) + DiskWriteIopsProperty.Recommended = fmt.Sprintf("%d", disk.Recommended.WriteIopsLimit) + DiskReadThroughputProperty.Recommended = fmt.Sprintf("%.2f Mb", disk.Recommended.ReadThroughputLimit) + DiskWriteThroughputProperty.Recommended = fmt.Sprintf("%.2f Mb", disk.Recommended.WriteThroughputLimit) + DiskSizeProperty.Recommended = fmt.Sprintf("%d GB", disk.Recommended.DiskSize) } - RegionProperty.Recommended = disk.Recommended.Region - DiskTypeProperty.Recommended = disk.Recommended.DiskType - DiskReadIopsProperty.Recommended = fmt.Sprintf("%d", disk.Recommended.ReadIopsLimit) - DiskWriteIopsProperty.Recommended = fmt.Sprintf("%d", disk.Recommended.WriteIopsLimit) - DiskReadThroughputProperty.Recommended = fmt.Sprintf("%.2f Mb", disk.Recommended.ReadThroughputLimit) - DiskWriteThroughputProperty.Recommended = fmt.Sprintf("%.2f Mb", disk.Recommended.WriteThroughputLimit) - DiskSizeProperty.Recommended = fmt.Sprintf("%d GB", disk.Recommended.DiskSize) } properties := &golang.Properties{} @@ -252,7 +235,7 @@ func (i ComputeInstanceItem) ToOptimizationItem() *golang.ChartOptimizationItem status = "press enter to load" } else if i.OptimizationLoading { status = "loading" - } else if i.Wastage.Rightsizing.Recommended != nil { + } else if i.Wastage != nil && i.Wastage.Rightsizing.Recommended != nil { totalSaving := 0.0 totalCurrentCost := 0.0 totalSaving += i.Wastage.Rightsizing.Current.Cost - i.Wastage.Rightsizing.Recommended.Cost @@ -296,12 +279,14 @@ func (i ComputeInstanceItem) ToOptimizationItem() *golang.ChartOptimizationItem DevicesChartRows: deviceRows, DevicesProperties: deviceProps, Preferences: i.Preferences, - Description: i.Wastage.Rightsizing.Description, Loading: i.OptimizationLoading, Skipped: i.Skipped, SkipReason: wrapperspb.String(i.SkipReason), LazyLoadingEnabled: i.LazyLoadingEnabled, } + if i.Wastage != nil && i.Wastage.Rightsizing != nil { + coi.Description = i.Wastage.Rightsizing.Description + } return coi } diff --git a/plugin/processor/compute_instance/job_compute_instance_list.go b/plugin/processor/compute_instance/job_compute_instance_list.go index 2b57b73..0eeec07 100644 --- a/plugin/processor/compute_instance/job_compute_instance_list.go +++ b/plugin/processor/compute_instance/job_compute_instance_list.go @@ -2,12 +2,12 @@ package compute_instance import ( "context" + "github.com/kaytu-io/kaytu/pkg/plugin/sdk" "google.golang.org/api/compute/v1" "log" "strconv" "strings" - "github.com/kaytu-io/plugin-gcp/plugin/preferences" util "github.com/kaytu-io/plugin-gcp/utils" ) @@ -21,20 +21,18 @@ func NewListComputeInstancesJob(processor *ComputeInstanceProcessor) *ListComput } } -func (job *ListComputeInstancesJob) Id() string { - return "list_compute_instances" -} - -func (job *ListComputeInstancesJob) Description() string { - return "List all compute instances in current project" - +func (job *ListComputeInstancesJob) Properties() sdk.JobProperties { + return sdk.JobProperties{ + ID: "list_compute_instances", + Description: "List all compute instances in current project", + MaxRetry: 0, + } } func (job *ListComputeInstancesJob) Run(ctx context.Context) error { - log.Println("Running list compute instance job") - instances, err := job.processor.provider.GetAllInstances() + instances, err := job.processor.provider.GetAllInstances(ctx) if err != nil { return err } @@ -50,7 +48,7 @@ func (job *ListComputeInstancesJob) Run(ctx context.Context) error { zoneURLParts := strings.Split(*instance.Zone, "/") instanceZone := zoneURLParts[len(zoneURLParts)-1] - diskDetails, err := job.processor.provider.GetDiskDetails(instanceZone, diskName) + diskDetails, err := job.processor.provider.GetDiskDetails(ctx, instanceZone, diskName) if err != nil { return err } @@ -65,7 +63,7 @@ func (job *ListComputeInstancesJob) Run(ctx context.Context) error { Region: util.TrimmedString(*instance.Zone, "/"), Platform: instance.GetCpuPlatform(), OptimizationLoading: true, - Preferences: preferences.DefaultComputeEnginePreferences, + Preferences: job.processor.defaultPreferences, Skipped: false, LazyLoadingEnabled: false, SkipReason: "NA", @@ -86,7 +84,7 @@ func (job *ListComputeInstancesJob) Run(ctx context.Context) error { job.processor.publishOptimizationItem(oi.ToOptimizationItem()) job.processor.UpdateSummary(oi.Id) - job.processor.jobQueue.Push(NewGetComputeInstanceMetricsJob(job.processor, instance, disks)) + job.processor.jobQueue.Push(NewGetComputeInstanceMetricsJob(job.processor, oi.Id)) } return nil diff --git a/plugin/processor/compute_instance/job_get_compute_instance_metrics.go b/plugin/processor/compute_instance/job_get_compute_instance_metrics.go index db8dbd3..1f3a9f2 100644 --- a/plugin/processor/compute_instance/job_get_compute_instance_metrics.go +++ b/plugin/processor/compute_instance/job_get_compute_instance_metrics.go @@ -3,44 +3,42 @@ package compute_instance import ( "context" "fmt" + "github.com/kaytu-io/kaytu/pkg/plugin/sdk" golang2 "github.com/kaytu-io/plugin-gcp/plugin/proto/src/golang/gcp" - "google.golang.org/api/compute/v1" "log" "strconv" "time" - "cloud.google.com/go/compute/apiv1/computepb" "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" - "github.com/kaytu-io/plugin-gcp/plugin/preferences" - util "github.com/kaytu-io/plugin-gcp/utils" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" ) type GetComputeInstanceMetricsJob struct { processor *ComputeInstanceProcessor - instance *computepb.Instance - disks []compute.Disk + itemId string } -func NewGetComputeInstanceMetricsJob(processor *ComputeInstanceProcessor, instance *computepb.Instance, disks []compute.Disk) *GetComputeInstanceMetricsJob { +func NewGetComputeInstanceMetricsJob(processor *ComputeInstanceProcessor, itemId string) *GetComputeInstanceMetricsJob { return &GetComputeInstanceMetricsJob{ processor: processor, - instance: instance, - disks: disks, + itemId: itemId, } } -func (job *GetComputeInstanceMetricsJob) Id() string { - return fmt.Sprintf("get_compute_instance_metrics_%d", job.instance.GetId()) -} - -func (job *GetComputeInstanceMetricsJob) Description() string { - return fmt.Sprintf("Get metrics for compute instance: %d", job.instance.GetId()) - +func (job *GetComputeInstanceMetricsJob) Properties() sdk.JobProperties { + return sdk.JobProperties{ + ID: fmt.Sprintf("get_compute_instance_metrics_%s", job.itemId), + Description: fmt.Sprintf("Get metrics for compute instance: %s", job.itemId), + MaxRetry: 0, + } } func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { + item, ok := job.processor.items.Get(job.itemId) + if !ok { + return fmt.Errorf("item not found %s", job.itemId) + } endTime := time.Now() // end time of requested time series startTime := endTime.Add(-24 * 1 * time.Hour) // start time of requested time series @@ -49,7 +47,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s"`, "compute.googleapis.com/instance/cpu/utilization", // fully qualified name of the metric - fmt.Sprint(job.instance.GetId()), // compute instance ID + fmt.Sprint(item.Instance.GetId()), // compute instance ID ), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), @@ -63,7 +61,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - cpumetric, err := job.processor.metricProvider.GetMetric(cpuRequest) + cpumetric, err := job.processor.metricProvider.GetMetric(ctx, cpuRequest) if err != nil { return err } @@ -72,7 +70,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s"`, "compute.googleapis.com/instance/memory/balloon/ram_used", - fmt.Sprint(job.instance.GetId()), + fmt.Sprint(item.Instance.GetId()), ), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), @@ -86,13 +84,13 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - memoryMetric, err := job.processor.metricProvider.GetMetric(memoryRequest) + memoryMetric, err := job.processor.metricProvider.GetMetric(ctx, memoryRequest) if err != nil { return err } disksMetrics := make(map[string]map[string][]*golang2.DataPoint) - for _, disk := range job.disks { + for _, disk := range item.Disks { id := strconv.FormatUint(disk.Id, 10) disksMetrics[id] = make(map[string][]*golang2.DataPoint) @@ -100,7 +98,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s" AND metric.labels.device_name="%s"`, "compute.googleapis.com/instance/disk/read_ops_count", - fmt.Sprint(job.instance.GetId()), disk.Name), + fmt.Sprint(item.Instance.GetId()), disk.Name), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), StartTime: timestamppb.New(startTime), @@ -113,7 +111,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - diskReadIopsMetrics, err := job.processor.metricProvider.GetMetric(diskReadIopsRequest) + diskReadIopsMetrics, err := job.processor.metricProvider.GetMetric(ctx, diskReadIopsRequest) if err != nil { return err } @@ -124,7 +122,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s" AND metric.labels.device_name="%s"`, "compute.googleapis.com/instance/disk/write_ops_count", - fmt.Sprint(job.instance.GetId()), disk.Name), + fmt.Sprint(item.Instance.GetId()), disk.Name), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), StartTime: timestamppb.New(startTime), @@ -137,7 +135,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - diskWriteIopsMetrics, err := job.processor.metricProvider.GetMetric(diskWriteIopsRequest) + diskWriteIopsMetrics, err := job.processor.metricProvider.GetMetric(ctx, diskWriteIopsRequest) if err != nil { return err } @@ -148,7 +146,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s" AND metric.labels.device_name="%s"`, "compute.googleapis.com/instance/disk/read_bytes_count", - fmt.Sprint(job.instance.GetId()), disk.Name), + fmt.Sprint(item.Instance.GetId()), disk.Name), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), StartTime: timestamppb.New(startTime), @@ -161,7 +159,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - diskReadThroughputMetrics, err := job.processor.metricProvider.GetMetric(diskReadThroughputRequest) + diskReadThroughputMetrics, err := job.processor.metricProvider.GetMetric(ctx, diskReadThroughputRequest) if err != nil { return err } @@ -172,7 +170,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { fmt.Sprintf( `metric.type="%s" AND resource.labels.instance_id="%s" AND metric.labels.device_name="%s"`, "compute.googleapis.com/instance/disk/write_bytes_count", - fmt.Sprint(job.instance.GetId()), disk.Name), + fmt.Sprint(item.Instance.GetId()), disk.Name), &monitoringpb.TimeInterval{ EndTime: timestamppb.New(endTime), StartTime: timestamppb.New(startTime), @@ -185,7 +183,7 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { }, ) - diskWriteThroughputMetrics, err := job.processor.metricProvider.GetMetric(diskWriteThroughputRequest) + diskWriteThroughputMetrics, err := job.processor.metricProvider.GetMetric(ctx, diskWriteThroughputRequest) if err != nil { return err } @@ -198,35 +196,24 @@ func (job *GetComputeInstanceMetricsJob) Run(ctx context.Context) error { instanceMetrics["cpuUtilization"] = cpumetric instanceMetrics["memoryUtilization"] = memoryMetric - oi := ComputeInstanceItem{ - ProjectId: job.processor.provider.ProjectID, - Name: *job.instance.Name, - Id: strconv.FormatUint(job.instance.GetId(), 10), - MachineType: util.TrimmedString(*job.instance.MachineType, "/"), - Region: util.TrimmedString(*job.instance.Zone, "/"), - Platform: job.instance.GetCpuPlatform(), - OptimizationLoading: true, - Preferences: preferences.DefaultComputeEnginePreferences, - Skipped: false, - LazyLoadingEnabled: false, - SkipReason: "NA", - Instance: job.instance, - Disks: job.disks, - Metrics: instanceMetrics, - DisksMetrics: disksMetrics, - } + item.OptimizationLoading = true + item.Skipped = false + item.SkipReason = "N/A" + item.LazyLoadingEnabled = false + item.Metrics = instanceMetrics + item.DisksMetrics = disksMetrics - for d, v := range oi.DisksMetrics { + for d, v := range item.DisksMetrics { for k, v := range v { log.Printf("%s %s : %d", d, k, len(v)) } } - job.processor.items.Set(oi.Id, oi) - job.processor.publishOptimizationItem(oi.ToOptimizationItem()) + job.processor.items.Set(item.Id, item) + job.processor.publishOptimizationItem(item.ToOptimizationItem()) + job.processor.UpdateSummary(item.Id) - job.processor.jobQueue.Push(NewOptimizeComputeInstancesJob(job.processor, oi)) - job.processor.UpdateSummary(oi.Id) + job.processor.jobQueue.Push(NewOptimizeComputeInstancesJob(job.processor, item.Id)) return nil diff --git a/plugin/processor/compute_instance/job_optimize_compute_instance.go b/plugin/processor/compute_instance/job_optimize_compute_instance.go index 4756451..00fc3e9 100644 --- a/plugin/processor/compute_instance/job_optimize_compute_instance.go +++ b/plugin/processor/compute_instance/job_optimize_compute_instance.go @@ -3,6 +3,7 @@ package compute_instance import ( "context" "fmt" + "github.com/kaytu-io/kaytu/pkg/plugin/sdk" "github.com/kaytu-io/plugin-gcp/plugin/processor/shared" golang2 "github.com/kaytu-io/plugin-gcp/plugin/proto/src/golang/gcp" "google.golang.org/grpc/metadata" @@ -18,28 +19,32 @@ import ( type OptimizeComputeInstancesJob struct { processor *ComputeInstanceProcessor - item ComputeInstanceItem + itemId string } -func NewOptimizeComputeInstancesJob(processor *ComputeInstanceProcessor, item ComputeInstanceItem) *OptimizeComputeInstancesJob { +func NewOptimizeComputeInstancesJob(processor *ComputeInstanceProcessor, itemId string) *OptimizeComputeInstancesJob { return &OptimizeComputeInstancesJob{ processor: processor, - item: item, + itemId: itemId, } } -func (job *OptimizeComputeInstancesJob) Id() string { - return fmt.Sprintf("optimize_compute_isntance_%s", job.item.Id) -} - -func (job *OptimizeComputeInstancesJob) Description() string { - return fmt.Sprintf("Optimizing %s", job.item.Id) - +func (job *OptimizeComputeInstancesJob) Properties() sdk.JobProperties { + return sdk.JobProperties{ + ID: fmt.Sprintf("optimize_compute_isntance_%s", job.itemId), + Description: fmt.Sprintf("Optimizing %s", job.itemId), + MaxRetry: 3, + } } func (job *OptimizeComputeInstancesJob) Run(ctx context.Context) error { - if job.item.LazyLoadingEnabled { - job.processor.jobQueue.Push(NewGetComputeInstanceMetricsJob(job.processor, job.item.Instance, job.item.Disks)) + item, ok := job.processor.items.Get(job.itemId) + if !ok { + return fmt.Errorf("item not found %s", job.itemId) + } + + if item.LazyLoadingEnabled { + job.processor.jobQueue.Push(NewGetComputeInstanceMetricsJob(job.processor, job.itemId)) return nil } @@ -47,7 +52,7 @@ func (job *OptimizeComputeInstancesJob) Run(ctx context.Context) error { var disks []*golang2.GcpComputeDisk diskFilled := make(map[string]float64) - for _, disk := range job.item.Disks { + for _, disk := range item.Disks { id := strconv.FormatUint(disk.Id, 10) typeURLParts := strings.Split(disk.Type, "/") diskType := typeURLParts[len(typeURLParts)-1] @@ -68,7 +73,7 @@ func (job *OptimizeComputeInstancesJob) Run(ctx context.Context) error { } preferencesMap := map[string]*wrapperspb.StringValue{} - for k, v := range preferences.Export(job.item.Preferences) { + for k, v := range preferences.Export(item.Preferences) { preferencesMap[k] = nil if v != nil { preferencesMap[k] = wrapperspb.String(*v) @@ -80,14 +85,14 @@ func (job *OptimizeComputeInstancesJob) Run(ctx context.Context) error { defer cancel() metrics := make(map[string]*golang2.Metric) - for k, v := range job.item.Metrics { + for k, v := range item.Metrics { metrics[k] = &golang2.Metric{ Data: v, } } diskMetrics := make(map[string]*golang2.DiskMetrics) - for disk, m := range job.item.DisksMetrics { + for disk, m := range item.DisksMetrics { diskM := make(map[string]*golang2.Metric) for k, v := range m { diskM[k] = &golang2.Metric{ @@ -104,43 +109,30 @@ func (job *OptimizeComputeInstancesJob) Run(ctx context.Context) error { CliVersion: wrapperspb.String(version.VERSION), Identification: job.processor.provider.Identify(), Instance: &golang2.GcpComputeInstance{ - Id: utils.HashString(job.item.Id), - Zone: job.item.Region, - MachineType: job.item.MachineType, + Id: utils.HashString(item.Id), + Zone: item.Region, + MachineType: item.MachineType, }, Disks: disks, Preferences: preferencesMap, Metrics: metrics, DisksMetrics: diskMetrics, Loading: false, - Region: job.item.Region, + Region: item.Region, }) if err != nil { return err } - job.item = ComputeInstanceItem{ - ProjectId: job.item.ProjectId, - Name: job.item.Name, - Id: job.item.Id, - MachineType: job.item.MachineType, - Region: job.item.Region, - Platform: job.item.Platform, - OptimizationLoading: false, - Preferences: job.item.Preferences, - Skipped: false, - LazyLoadingEnabled: false, - SkipReason: "NA", - Metrics: job.item.Metrics, - DisksMetrics: job.item.DisksMetrics, - Instance: job.item.Instance, - Disks: job.item.Disks, - Wastage: *response, - } + item.OptimizationLoading = false + item.Skipped = false + item.SkipReason = "N/A" + item.LazyLoadingEnabled = false + item.Wastage = response - job.processor.items.Set(job.item.Id, job.item) - job.processor.publishOptimizationItem(job.item.ToOptimizationItem()) - job.processor.UpdateSummary(job.item.Id) + job.processor.items.Set(job.itemId, item) + job.processor.publishOptimizationItem(item.ToOptimizationItem()) + job.processor.UpdateSummary(item.Id) return nil } diff --git a/plugin/service.go b/plugin/service.go index f13a3ea..c0694a7 100644 --- a/plugin/service.go +++ b/plugin/service.go @@ -28,7 +28,7 @@ func NewPlugin() *GCPPlugin { return &GCPPlugin{} } -func (p *GCPPlugin) GetConfig() golang.RegisterConfig { +func (p *GCPPlugin) GetConfig(_ context.Context) golang.RegisterConfig { return golang.RegisterConfig{ Name: "kaytu-io/plugin-gcp", Version: version.VERSION, @@ -126,12 +126,12 @@ func (p *GCPPlugin) GetConfig() golang.RegisterConfig { } } -func (p *GCPPlugin) SetStream(stream *sdk.StreamController) { +func (p *GCPPlugin) SetStream(_ context.Context, stream *sdk.StreamController) { p.stream = stream } // StartProcess implements sdk.Processor. -func (p *GCPPlugin) StartProcess(cmd string, flags map[string]string, kaytuAccessToken string, jobQueue *sdk.JobQueue) error { +func (p *GCPPlugin) StartProcess(ctx context.Context, cmd string, flags map[string]string, kaytuAccessToken string, preferences []*golang.PreferenceItem, jobQueue *sdk.JobQueue) error { // scope used from https://developers.google.com/identity/protocols/oauth2/scopes#compute gcpProvider := gcp.NewCompute( @@ -148,12 +148,12 @@ func (p *GCPPlugin) StartProcess(cmd string, flags map[string]string, kaytuAcces log.Println("Initializing clients") - err := gcpProvider.InitializeClient(context.Background()) + err := gcpProvider.InitializeClient(ctx) if err != nil { return err } - err = metricClient.InitializeClient(context.Background()) + err = metricClient.InitializeClient(ctx) if err != nil { return err } @@ -218,6 +218,7 @@ func (p *GCPPlugin) StartProcess(cmd string, flags map[string]string, kaytuAcces kaytuAccessToken, jobQueue, client, + preferences, ) } else { return fmt.Errorf("invalid command: %s", cmd) @@ -230,7 +231,7 @@ func (p *GCPPlugin) StartProcess(cmd string, flags map[string]string, kaytuAcces return nil } -func (p *GCPPlugin) ReEvaluate(evaluate *golang.ReEvaluate) { +func (p *GCPPlugin) ReEvaluate(_ context.Context, evaluate *golang.ReEvaluate) { p.processor.ReEvaluate(evaluate.Id, evaluate.Preferences) } diff --git a/utils/concurrent_map.go b/utils/concurrent_map.go deleted file mode 100644 index 418cfd0..0000000 --- a/utils/concurrent_map.go +++ /dev/null @@ -1,37 +0,0 @@ -package util - -import ( - "sync" -) - -type ConcurrentMap[K comparable, V any] struct { - data sync.Map -} - -func NewMap[K comparable, V any]() ConcurrentMap[K, V] { - return ConcurrentMap[K, V]{ - data: sync.Map{}, - } -} - -func (cm *ConcurrentMap[K, V]) Set(key K, value V) { - cm.data.Store(key, value) -} - -func (cm *ConcurrentMap[K, V]) Delete(key K) { - cm.data.Delete(key) -} - -func (cm *ConcurrentMap[K, V]) Get(key K) (V, bool) { - v, ok := cm.data.Load(key) - if !ok { - return *new(V), false - } - return v.(V), true -} - -func (cm *ConcurrentMap[K, V]) Range(f func(key K, value V) bool) { - cm.data.Range(func(key, value any) bool { - return f(key.(K), value.(V)) - }) -}