From f2ee70cd77bd6d28cc781a951ae45434023a828b Mon Sep 17 00:00:00 2001 From: Michael Shen Date: Wed, 29 May 2024 11:01:29 -0400 Subject: [PATCH] Refactor frontend to use cobra Signed-off-by: Michael Shen --- frontend/cmd/cmd.go | 125 ++++++++++++++++++ frontend/deploy/aro-hcp-frontend.yml | 2 +- frontend/go.mod | 15 +++ frontend/go.sum | 71 ++++++++++ frontend/main.go | 73 +--------- frontend/{ => pkg/config}/logger.go | 2 +- frontend/{ => pkg/database}/database.go | 11 +- frontend/{ => pkg/database}/document.go | 2 +- frontend/{ => pkg/frontend}/cache.go | 2 +- frontend/{ => pkg/frontend}/const.go | 4 +- frontend/{ => pkg/frontend}/context.go | 2 +- frontend/{ => pkg/frontend}/frontend.go | 35 ++--- frontend/{ => pkg/frontend}/genuuid.go | 2 +- frontend/{ => pkg/frontend}/metrics.go | 11 +- frontend/{ => pkg/frontend}/middleware.go | 2 +- .../{ => pkg/frontend}/middleware_body.go | 2 +- .../frontend}/middleware_body_test.go | 2 +- .../{ => pkg/frontend}/middleware_logging.go | 7 +- .../frontend}/middleware_logging_test.go | 5 +- .../frontend}/middleware_lowercase.go | 2 +- .../frontend}/middleware_lowercase_test.go | 2 +- .../{ => pkg/frontend}/middleware_panic.go | 5 +- .../frontend}/middleware_systemdata.go | 5 +- .../frontend}/middleware_systemdata_test.go | 2 +- .../frontend}/middleware_validateapi.go | 2 +- .../frontend}/middleware_validatestatic.go | 2 +- .../middleware_validatestatic_test.go | 2 +- .../middleware_validatesubscription.go | 2 +- .../middleware_validatesubscription_test.go | 2 +- go.work.sum | 39 +++++- internal/go.mod | 4 +- internal/go.sum | 12 +- internal/metrics/metrics.go | 10 -- 33 files changed, 324 insertions(+), 142 deletions(-) create mode 100644 frontend/cmd/cmd.go rename frontend/{ => pkg/config}/logger.go (93%) rename frontend/{ => pkg/database}/database.go (95%) rename frontend/{ => pkg/database}/document.go (98%) rename frontend/{ => pkg/frontend}/cache.go (98%) rename frontend/{ => pkg/frontend}/const.go (92%) rename frontend/{ => pkg/frontend}/context.go (99%) rename frontend/{ => pkg/frontend}/frontend.go (96%) rename frontend/{ => pkg/frontend}/genuuid.go (95%) rename frontend/{ => pkg/frontend}/metrics.go (92%) rename frontend/{ => pkg/frontend}/middleware.go (99%) rename frontend/{ => pkg/frontend}/middleware_body.go (98%) rename frontend/{ => pkg/frontend}/middleware_body_test.go (99%) rename frontend/{ => pkg/frontend}/middleware_logging.go (96%) rename frontend/{ => pkg/frontend}/middleware_logging_test.go (98%) rename frontend/{ => pkg/frontend}/middleware_lowercase.go (95%) rename frontend/{ => pkg/frontend}/middleware_lowercase_test.go (97%) rename frontend/{ => pkg/frontend}/middleware_panic.go (83%) rename frontend/{ => pkg/frontend}/middleware_systemdata.go (88%) rename frontend/{ => pkg/frontend}/middleware_systemdata_test.go (99%) rename frontend/{ => pkg/frontend}/middleware_validateapi.go (98%) rename frontend/{ => pkg/frontend}/middleware_validatestatic.go (98%) rename frontend/{ => pkg/frontend}/middleware_validatestatic_test.go (99%) rename frontend/{ => pkg/frontend}/middleware_validatesubscription.go (99%) rename frontend/{ => pkg/frontend}/middleware_validatesubscription_test.go (99%) delete mode 100644 internal/metrics/metrics.go diff --git a/frontend/cmd/cmd.go b/frontend/cmd/cmd.go new file mode 100644 index 000000000..0150128b5 --- /dev/null +++ b/frontend/cmd/cmd.go @@ -0,0 +1,125 @@ +package cmd + +import ( + "context" + "fmt" + "net" + "os" + "os/signal" + "runtime/debug" + "syscall" + + sdk "github.com/openshift-online/ocm-sdk-go" + "github.com/spf13/cobra" + + "github.com/Azure/ARO-HCP/frontend/pkg/config" + "github.com/Azure/ARO-HCP/frontend/pkg/database" + "github.com/Azure/ARO-HCP/frontend/pkg/frontend" +) + +type FrontendOpts struct { + clustersServiceURL string + insecure bool + + region string + port int + + databaseName string + databaseURL string +} + +func NewRootCmd() *cobra.Command { + opts := &FrontendOpts{} + rootCmd := &cobra.Command{ + Use: "aro-hcp-frontend", + Args: cobra.NoArgs, + Short: "Serve the ARO HCP Frontend", + Long: `Serve the ARO HCP Frontend + + This command runs the ARO HCP Frontend. It communicates with Clusters Service and a CosmosDB + + # Run ARO HCP Frontend locally to connect to a local Clusters Service at http://localhost:8000 + ./aro-hcp-frontend --database-name ${DB_NAME} --database-url ${DB_URL} --region ${REGION} \ + --clusters-service-url "http://localhost:8000" +`, + RunE: func(cmd *cobra.Command, args []string) error { + return opts.Run() + }, + } + + rootCmd.Flags().StringVar(&opts.databaseName, "database-name", os.Getenv("DB_NAME"), "database name") + rootCmd.Flags().StringVar(&opts.databaseURL, "database-url", os.Getenv("DB_URL"), "database url") + rootCmd.Flags().StringVar(&opts.region, "region", os.Getenv("REGION"), "Azure region") + rootCmd.Flags().IntVar(&opts.port, "port", 8443, "port to listen on") + + rootCmd.Flags().StringVar(&opts.clustersServiceURL, "clusters-service-url", "https://api.openshift.com", "URL of the OCM API gateway.") + rootCmd.Flags().BoolVar(&opts.insecure, "insecure", false, "Skip validating TLS for clusters-service.") + + return rootCmd +} + +func (opts *FrontendOpts) Run() error { + version := "unknown" + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + version = setting.Value + break + } + } + } + + logger := config.DefaultLogger() + logger.Info(fmt.Sprintf("%s (%s) started", frontend.ProgramName, version)) + + // Init prometheus emitter + prometheusEmitter := frontend.NewPrometheusEmitter() + + // Configure database configuration and client + dbConfig := database.NewDatabaseConfig(opts.databaseName, opts.databaseURL) + dbClient, err := database.NewDatabaseClient(dbConfig) + if err != nil { + return fmt.Errorf("creating the database client failed: %v", err) + } + + listener, err := net.Listen("tcp4", fmt.Sprintf(":%d", opts.port)) + if err != nil { + return err + } + + logger.Info(fmt.Sprintf("Application running in region: %s", opts.region)) + + // Initialize Clusters Service Client + conn, err := sdk.NewUnauthenticatedConnectionBuilder(). + URL(opts.clustersServiceURL). + Insecure(opts.insecure). + Build() + if err != nil { + return err + } + + f := frontend.NewFrontend(logger, listener, prometheusEmitter, dbClient, opts.region, conn) + + // Verify the Async DB is available and accessible + logger.Info("Testing DB Access") + result, err := dbClient.DBConnectionTest(context.Background()) + if err != nil { + logger.Error(fmt.Sprintf("Database test failed to fetch properties: %v", err)) + } else { + logger.Info(fmt.Sprintf("Database check completed - %s", result)) + } + + stop := make(chan struct{}) + signalChannel := make(chan os.Signal, 1) + signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM) + go f.Run(context.Background(), stop) + + sig := <-signalChannel + logger.Info(fmt.Sprintf("caught %s signal", sig)) + close(stop) + + f.Join() + logger.Info(fmt.Sprintf("%s (%s) stopped", frontend.ProgramName, version)) + + return nil +} diff --git a/frontend/deploy/aro-hcp-frontend.yml b/frontend/deploy/aro-hcp-frontend.yml index 73c718ac0..a42a28117 100644 --- a/frontend/deploy/aro-hcp-frontend.yml +++ b/frontend/deploy/aro-hcp-frontend.yml @@ -63,7 +63,7 @@ objects: containers: - name: aro-hcp-frontend image: ${ARO_HCP_FRONTEND_IMAGE} - imagePullPolicy: IfNotPresent + imagePullPolicy: Always env: - name: DB_NAME value: ${DB_NAME} diff --git a/frontend/go.mod b/frontend/go.mod index 62e4e9fdb..2e391d4f8 100644 --- a/frontend/go.mod +++ b/frontend/go.mod @@ -12,6 +12,7 @@ require ( github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.19.0 github.com/segmentio/ksuid v1.0.4 + github.com/spf13/cobra v1.8.0 golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 ) @@ -20,7 +21,9 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect + github.com/aymerick/douceur v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/go-logr/logr v1.4.1 // indirect @@ -28,25 +31,37 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt/v4 v4.4.1 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect + github.com/golang/glog v1.0.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/gorilla/css v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect + github.com/microcosm-cc/bluemonday v1.0.18 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/openshift-online/ocm-sdk-go v0.1.421 github.com/openshift/api v0.0.0-20240429104249-ac9356ba1784 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect + github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect + github.com/spf13/pflag v1.0.5 // indirect golang.org/x/crypto v0.22.0 // indirect golang.org/x/net v0.24.0 // indirect + golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.30.0 // indirect k8s.io/apimachinery v0.30.0 // indirect k8s.io/klog/v2 v2.120.1 // indirect diff --git a/frontend/go.sum b/frontend/go.sum index ab74c3a26..aa25ce055 100644 --- a/frontend/go.sum +++ b/frontend/go.sum @@ -10,13 +10,21 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 h1:rTfKOCZGy5ViVrlA74ZPE99 github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= +github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= +github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= +github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= +github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= +github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= @@ -29,18 +37,53 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ= +github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 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/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= +github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ= +github.com/itchyny/gojq v0.12.7/go.mod h1:ZdvNHVlzPgUf8pgjnuDTmGfHA/21KoutQUJ3An/xNuw= +github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= +github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= +github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= +github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= +github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -53,15 +96,25 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/microcosm-cc/bluemonday v1.0.18 h1:6HcxvXDAi3ARt3slx6nTesbvorIc3QeTzBNRvWktHBo= +github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= +github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.31.0 h1:54UJxxj6cPInHS3a35wm6BK/F9nHYueZ1NVujHDrnXE= +github.com/onsi/gomega v1.31.0/go.mod h1:DW9aCi7U6Yi40wNVAvT6kzFnEVEI5n3DloYBiKiT6zk= +github.com/openshift-online/ocm-sdk-go v0.1.421 h1:x4zUDN+32IW98RXhccMKanjODy6HehxwDR68t2MhFPc= +github.com/openshift-online/ocm-sdk-go v0.1.421/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y= github.com/openshift/api v0.0.0-20240429104249-ac9356ba1784 h1:SmOZFMxuAH4d1Cj7dOftVyo4Wg/mEC4pwz6QIJJsAkc= github.com/openshift/api v0.0.0-20240429104249-ac9356ba1784/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= +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_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= @@ -74,8 +127,13 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= 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/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c= github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= +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= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -94,32 +152,45 @@ golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8/go.mod h1:/lliqkxwWAhPjf5oSO golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= +golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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-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-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 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.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/frontend/main.go b/frontend/main.go index 2ab6cc437..5b9867782 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -4,78 +4,17 @@ package main // Licensed under the Apache License 2.0. import ( - "context" "fmt" - "net" + "log" "os" - "os/signal" - "runtime/debug" - "syscall" -) -const ProgramName = "ARO HCP Frontend" + "github.com/Azure/ARO-HCP/frontend/cmd" + "github.com/Azure/ARO-HCP/frontend/pkg/frontend" +) func main() { - version := "unknown" - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - if setting.Key == "vcs.revision" { - version = setting.Value - break - } - } - } - logger := DefaultLogger() - - logger.Info(fmt.Sprintf("%s (%s) started", ProgramName, version)) - - // Fetch the region from the env variable - region := os.Getenv("REGION") - if region == "" { - logger.Error("REGION env variable is not set.") - } - logger.Info(fmt.Sprintf("Application running in region: %s", region)) - - ctx := context.Background() - stop := make(chan struct{}) - - signalChannel := make(chan os.Signal, 1) - signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM) - - listener, err := net.Listen("tcp4", ":8443") - if err != nil { - logger.Error(err.Error()) + if err := cmd.NewRootCmd().Execute(); err != nil { + log.Println(fmt.Errorf("%s error: %v", frontend.ProgramName, err)) os.Exit(1) } - - // Init prometheus emitter - prometheusEmitter := NewPrometheusEmitter() - - // Configure database configuration and client - dbConfig := NewDatabaseConfig() - - dbClient, err := NewDatabaseClient(dbConfig) - if err != nil { - logger.Error(fmt.Sprintf("Creating the database client failed: %v", err)) - } - - frontend := NewFrontend(logger, listener, prometheusEmitter, dbClient, region) - - // Verify the Async DB is available and accessible - logger.Info("Testing DB Access") - result, err := frontend.dbClient.DBConnectionTest(ctx) - if err != nil { - logger.Error(fmt.Sprintf("Database test failed to fetch properties: %v", err)) - } else { - logger.Info(fmt.Sprintf("Database check completed - %s", result)) - } - - go frontend.Run(ctx, stop) - - sig := <-signalChannel - logger.Info(fmt.Sprintf("caught %s signal", sig)) - close(stop) - frontend.Join() - - logger.Info(fmt.Sprintf("%s (%s) stopped", ProgramName, version)) } diff --git a/frontend/logger.go b/frontend/pkg/config/logger.go similarity index 93% rename from frontend/logger.go rename to frontend/pkg/config/logger.go index 9c5e242b4..4e3fc4511 100644 --- a/frontend/logger.go +++ b/frontend/pkg/config/logger.go @@ -1,4 +1,4 @@ -package main +package config import ( "log/slog" diff --git a/frontend/database.go b/frontend/pkg/database/database.go similarity index 95% rename from frontend/database.go rename to frontend/pkg/database/database.go index 9e8431f92..12277cb55 100644 --- a/frontend/database.go +++ b/frontend/pkg/database/database.go @@ -1,10 +1,9 @@ -package main +package database import ( "context" "encoding/json" "errors" - "os" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos" @@ -33,17 +32,17 @@ type DBConfig struct { } // NewDatabaseConfig configures database configuration values for access -func NewDatabaseConfig() *DBConfig { +func NewDatabaseConfig(dbName, dbURL string) *DBConfig { opt := &azidentity.DefaultAzureCredentialOptions{} c := &DBConfig{ - DBName: os.Getenv("DB_NAME"), - DBUrl: os.Getenv("DB_URL"), + DBName: dbName, + DBUrl: dbURL, ClientOptions: opt, } return c } -// NewDatabaseClient instanstiates a Cosmos DatabaseClient targeting Frontends async DB +// NewDatabaseClient instantiates a Cosmos DatabaseClient targeting Frontends async DB func NewDatabaseClient(config *DBConfig) (*DBClient, error) { cred, err := azidentity.NewDefaultAzureCredential(config.ClientOptions) if err != nil { diff --git a/frontend/document.go b/frontend/pkg/database/document.go similarity index 98% rename from frontend/document.go rename to frontend/pkg/database/document.go index 665d5b790..ff981eb73 100644 --- a/frontend/document.go +++ b/frontend/pkg/database/document.go @@ -1,4 +1,4 @@ -package main +package database import "github.com/Azure/ARO-HCP/internal/api/arm" diff --git a/frontend/cache.go b/frontend/pkg/frontend/cache.go similarity index 98% rename from frontend/cache.go rename to frontend/pkg/frontend/cache.go index 55bd2f8e3..a22fa710e 100644 --- a/frontend/cache.go +++ b/frontend/pkg/frontend/cache.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/const.go b/frontend/pkg/frontend/const.go similarity index 92% rename from frontend/const.go rename to frontend/pkg/frontend/const.go index d5ee2713f..aa375f86c 100644 --- a/frontend/const.go +++ b/frontend/pkg/frontend/const.go @@ -1,9 +1,11 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. const ( + ProgramName = "ARO HCP Frontend" + // APIVersionKey is the request parameter name for the API version. APIVersionKey = "api-version" diff --git a/frontend/context.go b/frontend/pkg/frontend/context.go similarity index 99% rename from frontend/context.go rename to frontend/pkg/frontend/context.go index c04d58f02..ccb4bb577 100644 --- a/frontend/context.go +++ b/frontend/pkg/frontend/context.go @@ -1,4 +1,4 @@ -package main +package frontend import ( "context" diff --git a/frontend/frontend.go b/frontend/pkg/frontend/frontend.go similarity index 96% rename from frontend/frontend.go rename to frontend/pkg/frontend/frontend.go index a424d1ac6..04f637e37 100644 --- a/frontend/frontend.go +++ b/frontend/pkg/frontend/frontend.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. @@ -16,13 +16,13 @@ import ( "strings" "sync/atomic" - "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/google/uuid" + sdk "github.com/openshift-online/ocm-sdk-go" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/Azure/ARO-HCP/frontend/pkg/database" "github.com/Azure/ARO-HCP/internal/api" "github.com/Azure/ARO-HCP/internal/api/arm" - "github.com/Azure/ARO-HCP/internal/metrics" ) const ( @@ -36,14 +36,15 @@ const ( ) type Frontend struct { + conn *sdk.Connection logger *slog.Logger listener net.Listener server http.Server cache Cache - dbClient DBClient + dbClient database.DBClient ready atomic.Value done chan struct{} - metrics metrics.Emitter + metrics Emitter region string } @@ -54,8 +55,9 @@ func MuxPattern(method string, segments ...string) string { return fmt.Sprintf("%s /%s", method, strings.ToLower(path.Join(segments...))) } -func NewFrontend(logger *slog.Logger, listener net.Listener, emitter metrics.Emitter, dbClient *DBClient, region string) *Frontend { +func NewFrontend(logger *slog.Logger, listener net.Listener, emitter Emitter, dbClient *database.DBClient, region string, conn *sdk.Connection) *Frontend { f := &Frontend{ + conn: conn, logger: logger, listener: listener, metrics: emitter, @@ -330,13 +332,14 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request cluster = api.NewDefaultHCPOpenShiftCluster() versionedRequestCluster.Normalize(cluster) + f.cache.SetCluster(resourceID, cluster) - var doc *HCPOpenShiftClusterDocument + var doc *database.HCPOpenShiftClusterDocument doc, err = f.dbClient.GetClusterDoc(ctx, resourceID, subscriptionID) if err != nil { - if errors.Is(err, ErrNotFound) { + if errors.Is(err, database.ErrNotFound) { f.logger.Info(fmt.Sprintf("existing document not found for cluster - creating one for %s", resourceID)) - doc = &HCPOpenShiftClusterDocument{ + doc = &database.HCPOpenShiftClusterDocument{ ID: uuid.New().String(), Key: resourceID, ClusterID: NewUID(), @@ -355,8 +358,6 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request } f.logger.Info(fmt.Sprintf("document created for %s", resourceID)) - f.cache.SetCluster(resourceID, cluster) - resp, err := json.Marshal(versionedRequestCluster) if err != nil { f.logger.Error(err.Error()) @@ -401,7 +402,7 @@ func (f *Frontend) ArmResourceDelete(writer http.ResponseWriter, request *http.R err = f.dbClient.DeleteClusterDoc(ctx, resourceID, subscriptionID) if err != nil { - if errors.Is(err, ErrNotFound) { + if errors.Is(err, database.ErrNotFound) { f.logger.Info(fmt.Sprintf("cluster document cannot be deleted -- document not found for %s", resourceID)) writer.WriteHeader(http.StatusNoContent) return @@ -437,7 +438,7 @@ func (f *Frontend) ArmSubscriptionGet(writer http.ResponseWriter, request *http. doc, err := f.dbClient.GetSubscriptionDoc(ctx, subscriptionID) if err != nil { - if errors.Is(err, ErrNotFound) { + if errors.Is(err, database.ErrNotFound) { f.logger.Error(fmt.Sprintf("document not found for subscription %s", subscriptionID)) writer.WriteHeader(http.StatusNotFound) return @@ -490,12 +491,12 @@ func (f *Frontend) ArmSubscriptionPut(writer http.ResponseWriter, request *http. "state": string(subscription.State), }) - var doc *SubscriptionDocument + var doc *database.SubscriptionDocument doc, err = f.dbClient.GetSubscriptionDoc(ctx, subscriptionID) if err != nil { - if errors.Is(err, ErrNotFound) { + if errors.Is(err, database.ErrNotFound) { f.logger.Info(fmt.Sprintf("existing document not found for subscription - creating one for %s", subscriptionID)) - doc = &SubscriptionDocument{ + doc = &database.SubscriptionDocument{ ID: uuid.New().String(), PartitionKey: subscriptionID, Subscription: &subscription, diff --git a/frontend/genuuid.go b/frontend/pkg/frontend/genuuid.go similarity index 95% rename from frontend/genuuid.go rename to frontend/pkg/frontend/genuuid.go index 7da7d00a8..5c8519bb3 100644 --- a/frontend/genuuid.go +++ b/frontend/pkg/frontend/genuuid.go @@ -1,4 +1,4 @@ -package main +package frontend import ( "encoding/base32" diff --git a/frontend/metrics.go b/frontend/pkg/frontend/metrics.go similarity index 92% rename from frontend/metrics.go rename to frontend/pkg/frontend/metrics.go index f82b8c192..d3388beec 100644 --- a/frontend/metrics.go +++ b/frontend/pkg/frontend/metrics.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. @@ -12,9 +12,14 @@ import ( "golang.org/x/exp/maps" "github.com/Azure/ARO-HCP/internal/api/arm" - "github.com/Azure/ARO-HCP/internal/metrics" ) +// Emitter emits different types of metrics +type Emitter interface { + EmitCounter(metricName string, value float64, labels map[string]string) + EmitGauge(metricName string, value float64, labels map[string]string) +} + type PrometheusEmitter struct { gauges map[string]*prometheus.GaugeVec counters map[string]*prometheus.CounterVec @@ -50,7 +55,7 @@ func (pe *PrometheusEmitter) EmitCounter(name string, value float64, labels map[ } type MetricsMiddleware struct { - metrics.Emitter + Emitter cache *Cache } diff --git a/frontend/middleware.go b/frontend/pkg/frontend/middleware.go similarity index 99% rename from frontend/middleware.go rename to frontend/pkg/frontend/middleware.go index 71bebf9a9..751c4b9e5 100644 --- a/frontend/middleware.go +++ b/frontend/pkg/frontend/middleware.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_body.go b/frontend/pkg/frontend/middleware_body.go similarity index 98% rename from frontend/middleware_body.go rename to frontend/pkg/frontend/middleware_body.go index c8292df86..85b0cc285 100644 --- a/frontend/middleware_body.go +++ b/frontend/pkg/frontend/middleware_body.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_body_test.go b/frontend/pkg/frontend/middleware_body_test.go similarity index 99% rename from frontend/middleware_body_test.go rename to frontend/pkg/frontend/middleware_body_test.go index 4d90807e9..b4f3ef16a 100644 --- a/frontend/middleware_body_test.go +++ b/frontend/pkg/frontend/middleware_body_test.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_logging.go b/frontend/pkg/frontend/middleware_logging.go similarity index 96% rename from frontend/middleware_logging.go rename to frontend/pkg/frontend/middleware_logging.go index 951041e7a..f23352398 100644 --- a/frontend/middleware_logging.go +++ b/frontend/pkg/frontend/middleware_logging.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/Azure/ARO-HCP/frontend/pkg/config" "github.com/Azure/ARO-HCP/internal/api" "github.com/Azure/ARO-HCP/internal/api/arm" ) @@ -52,7 +53,7 @@ func MiddlewareLogging(w http.ResponseWriter, r *http.Request, next http.Handler logger, err := LoggerFromContext(r.Context()) if err != nil { - DefaultLogger().Error(err.Error()) + config.DefaultLogger().Error(err.Error()) arm.WriteInternalServerError(w) return } @@ -87,7 +88,7 @@ func MiddlewareLoggingPostMux(w http.ResponseWriter, r *http.Request, next http. logger, err := LoggerFromContext(ctx) if err != nil { - DefaultLogger().Error(err.Error()) + config.DefaultLogger().Error(err.Error()) arm.WriteInternalServerError(w) return } diff --git a/frontend/middleware_logging_test.go b/frontend/pkg/frontend/middleware_logging_test.go similarity index 98% rename from frontend/middleware_logging_test.go rename to frontend/pkg/frontend/middleware_logging_test.go index f69f6fad3..f8ca5484f 100644 --- a/frontend/middleware_logging_test.go +++ b/frontend/pkg/frontend/middleware_logging_test.go @@ -1,4 +1,4 @@ -package main +package frontend import ( "fmt" @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" + "github.com/Azure/ARO-HCP/frontend/pkg/config" "github.com/Azure/ARO-HCP/internal/api" "github.com/Azure/ARO-HCP/internal/api/arm" ) @@ -44,7 +45,7 @@ func TestMiddlewareLoggingPostMux(t *testing.T) { request.Header = tt.header // we assume the request carries a logger, we set it explicitly to not fail - ctx := ContextWithLogger(request.Context(), DefaultLogger()) + ctx := ContextWithLogger(request.Context(), config.DefaultLogger()) request = request.WithContext(ctx) next := func(w http.ResponseWriter, r *http.Request) { diff --git a/frontend/middleware_lowercase.go b/frontend/pkg/frontend/middleware_lowercase.go similarity index 95% rename from frontend/middleware_lowercase.go rename to frontend/pkg/frontend/middleware_lowercase.go index 039fcb45f..74c818410 100644 --- a/frontend/middleware_lowercase.go +++ b/frontend/pkg/frontend/middleware_lowercase.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_lowercase_test.go b/frontend/pkg/frontend/middleware_lowercase_test.go similarity index 97% rename from frontend/middleware_lowercase_test.go rename to frontend/pkg/frontend/middleware_lowercase_test.go index bfccb2d54..284557e00 100644 --- a/frontend/middleware_lowercase_test.go +++ b/frontend/pkg/frontend/middleware_lowercase_test.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_panic.go b/frontend/pkg/frontend/middleware_panic.go similarity index 83% rename from frontend/middleware_panic.go rename to frontend/pkg/frontend/middleware_panic.go index 5f91f1e8a..e31908384 100644 --- a/frontend/middleware_panic.go +++ b/frontend/pkg/frontend/middleware_panic.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. @@ -8,6 +8,7 @@ import ( "net/http" "runtime/debug" + "github.com/Azure/ARO-HCP/frontend/pkg/config" "github.com/Azure/ARO-HCP/internal/api/arm" ) @@ -16,7 +17,7 @@ func MiddlewarePanic(w http.ResponseWriter, r *http.Request, next http.HandlerFu if e := recover(); e != nil { logger, err := LoggerFromContext(r.Context()) if err != nil { - logger = DefaultLogger() + logger = config.DefaultLogger() } logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack()))) diff --git a/frontend/middleware_systemdata.go b/frontend/pkg/frontend/middleware_systemdata.go similarity index 88% rename from frontend/middleware_systemdata.go rename to frontend/pkg/frontend/middleware_systemdata.go index 4ce003279..384934617 100644 --- a/frontend/middleware_systemdata.go +++ b/frontend/pkg/frontend/middleware_systemdata.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. @@ -8,6 +8,7 @@ import ( "fmt" "net/http" + "github.com/Azure/ARO-HCP/frontend/pkg/config" "github.com/Azure/ARO-HCP/internal/api/arm" ) @@ -23,7 +24,7 @@ func MiddlewareSystemData(w http.ResponseWriter, r *http.Request, next http.Hand } else { logger, err := LoggerFromContext(r.Context()) if err != nil { - DefaultLogger().Error(err.Error()) + config.DefaultLogger().Error(err.Error()) arm.WriteInternalServerError(w) return } diff --git a/frontend/middleware_systemdata_test.go b/frontend/pkg/frontend/middleware_systemdata_test.go similarity index 99% rename from frontend/middleware_systemdata_test.go rename to frontend/pkg/frontend/middleware_systemdata_test.go index 9cb401838..2b1451062 100644 --- a/frontend/middleware_systemdata_test.go +++ b/frontend/pkg/frontend/middleware_systemdata_test.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_validateapi.go b/frontend/pkg/frontend/middleware_validateapi.go similarity index 98% rename from frontend/middleware_validateapi.go rename to frontend/pkg/frontend/middleware_validateapi.go index 26ee96fc1..3ae46d3ba 100644 --- a/frontend/middleware_validateapi.go +++ b/frontend/pkg/frontend/middleware_validateapi.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_validatestatic.go b/frontend/pkg/frontend/middleware_validatestatic.go similarity index 98% rename from frontend/middleware_validatestatic.go rename to frontend/pkg/frontend/middleware_validatestatic.go index a50bd8594..c3a82f4b5 100644 --- a/frontend/middleware_validatestatic.go +++ b/frontend/pkg/frontend/middleware_validatestatic.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_validatestatic_test.go b/frontend/pkg/frontend/middleware_validatestatic_test.go similarity index 99% rename from frontend/middleware_validatestatic_test.go rename to frontend/pkg/frontend/middleware_validatestatic_test.go index 58c9094b7..d4ad079a1 100644 --- a/frontend/middleware_validatestatic_test.go +++ b/frontend/pkg/frontend/middleware_validatestatic_test.go @@ -1,4 +1,4 @@ -package main +package frontend import ( "encoding/json" diff --git a/frontend/middleware_validatesubscription.go b/frontend/pkg/frontend/middleware_validatesubscription.go similarity index 99% rename from frontend/middleware_validatesubscription.go rename to frontend/pkg/frontend/middleware_validatesubscription.go index 53875632d..390252165 100644 --- a/frontend/middleware_validatesubscription.go +++ b/frontend/pkg/frontend/middleware_validatesubscription.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/frontend/middleware_validatesubscription_test.go b/frontend/pkg/frontend/middleware_validatesubscription_test.go similarity index 99% rename from frontend/middleware_validatesubscription_test.go rename to frontend/pkg/frontend/middleware_validatesubscription_test.go index 882fc9a48..c90f140d5 100644 --- a/frontend/middleware_validatesubscription_test.go +++ b/frontend/pkg/frontend/middleware_validatesubscription_test.go @@ -1,4 +1,4 @@ -package main +package frontend // Copyright (c) Microsoft Corporation. // Licensed under the Apache License 2.0. diff --git a/go.work.sum b/go.work.sum index 7d870e7cf..2e12e5226 100644 --- a/go.work.sum +++ b/go.work.sum @@ -2,16 +2,24 @@ github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjH github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= +github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= +github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= 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/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= +github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY= +github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw= github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= +github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA= github.com/fxamacker/cbor/v2 v2.6.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= @@ -32,6 +40,28 @@ github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvR github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= +github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= +github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ= +github.com/itchyny/gojq v0.12.7/go.mod h1:ZdvNHVlzPgUf8pgjnuDTmGfHA/21KoutQUJ3An/xNuw= +github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= +github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= +github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= +github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= +github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= +github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= @@ -44,14 +74,20 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= 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/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ= +github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU= github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= +github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= @@ -65,6 +101,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -90,7 +127,5 @@ golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= diff --git a/internal/go.mod b/internal/go.mod index ecca7b2f8..d017db950 100644 --- a/internal/go.mod +++ b/internal/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.22.2 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 github.com/go-playground/validator/v10 v10.19.0 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 @@ -13,7 +13,7 @@ require ( ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-playground/locales v0.14.1 // indirect diff --git a/internal/go.sum b/internal/go.sum index 51cfa935b..3c71abdd7 100644 --- a/internal/go.sum +++ b/internal/go.sum @@ -1,7 +1,5 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 h1:n1DH8TPV4qqPTje2RcUBYwtrTWlabVp4n46+74X2pn4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0/go.mod h1:HDcZnuGbiyppErN6lB+idp4CKhjbc8gwjto6OPpyggM= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 h1:LqbJ/WzJUwBf8UiaSzgX7aMclParm9/5Vgp+TY51uBQ= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2/go.mod h1:yInRyqWXAuaPrgI7p70+lDDgh3mlBohis29jGMISnmc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.7.0 h1:rTfKOCZGy5ViVrlA74ZPE99a+SgoEE2K/yg3RyW9dFA= 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= @@ -46,14 +44,12 @@ github.com/openshift/api v0.0.0-20240429104249-ac9356ba1784 h1:SmOZFMxuAH4d1Cj7d github.com/openshift/api v0.0.0-20240429104249-ac9356ba1784/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= 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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go deleted file mode 100644 index 12686b1fa..000000000 --- a/internal/metrics/metrics.go +++ /dev/null @@ -1,10 +0,0 @@ -package metrics - -// Copyright (c) Microsoft Corporation. -// Licensed under the Apache License 2.0. - -// Emitter emits different types of metrics -type Emitter interface { - EmitCounter(metricName string, value float64, labels map[string]string) - EmitGauge(metricName string, value float64, labels map[string]string) -}