From 5dd9704f790f0ee8c12bc0488390ee5c54e788fa Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Sat, 27 Jul 2024 18:11:40 -0400 Subject: [PATCH] make Prometheus default; left and right helpers * Prometheus is now default for local playground as well Signed-off-by: Alex Aizman --- ais/backend/awsinv.go | 2 +- ais/backend/azure.go | 2 +- ais/prxauth.go | 2 +- cmd/authn/mgr.go | 6 +++--- cmn/bck.go | 4 ++-- cmn/cos/strings.go | 20 ++++++++++---------- cmn/objlist_utils.go | 6 +++--- deploy/dev/local/deploy.sh | 9 +++++---- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/ais/backend/awsinv.go b/ais/backend/awsinv.go index 12db5178b4..9a1ae6594c 100644 --- a/ais/backend/awsinv.go +++ b/ais/backend/awsinv.go @@ -119,7 +119,7 @@ func (s3bp *s3bp) initInventory(cloudBck *cmn.Bck, svc *s3.Client, ctx *core.Lso if csv.oname == "" { what := prefix if ctx.ID == "" { - what = cos.Either(ctx.Name, aiss3.InvName) + what = cos.Left(ctx.Name, aiss3.InvName) } return nil, csv, manifest, http.StatusNotFound, cos.NewErrNotFound(cloudBck, invTag+":"+what) } diff --git a/ais/backend/azure.go b/ais/backend/azure.go index c3e00ddbeb..d936180bb6 100644 --- a/ais/backend/azure.go +++ b/ais/backend/azure.go @@ -76,7 +76,7 @@ var ( var _ core.Backend = (*azbp)(nil) func azProto() string { - return cos.Rather(azDefaultProto, os.Getenv(azProtoEnvVar)) + return cos.Right(azDefaultProto, os.Getenv(azProtoEnvVar)) } func azAccName() string { return os.Getenv(azAccNameEnvVar) } diff --git a/ais/prxauth.go b/ais/prxauth.go index 88ac24be62..176094b84a 100644 --- a/ais/prxauth.go +++ b/ais/prxauth.go @@ -48,7 +48,7 @@ func newAuthManager(config *cmn.Config) *authManager { tkList: make(tkList), revokedTokens: make(map[string]bool), // TODO: preallocate version: 1, - secret: cos.Rather(config.Auth.Secret, os.Getenv(env.AuthN.SecretKey)), // environment override + secret: cos.Right(config.Auth.Secret, os.Getenv(env.AuthN.SecretKey)), // environment override } } diff --git a/cmd/authn/mgr.go b/cmd/authn/mgr.go index cf0cd40e26..139b740dc4 100644 --- a/cmd/authn/mgr.go +++ b/cmd/authn/mgr.go @@ -207,7 +207,7 @@ func (m *mgr) roleList() ([]*authn.Role, error) { // are not returned to a caller as it is not crucial. func (m *mgr) createRolesForCluster(clu *authn.CluACL) { for _, pr := range predefinedRoles { - suffix := cos.Either(clu.Alias, clu.ID) + suffix := cos.Left(clu.Alias, clu.ID) uid := pr.prefix + "-" + suffix rInfo := &authn.Role{} if err := m.db.Get(rolesCollection, uid, rInfo); err == nil { @@ -501,8 +501,8 @@ func initializeDB(driver kvdb.Driver) error { } // environment override - userName := cos.Rather(adminUserID, os.Getenv(env.AuthN.AdminUsername)) - password := cos.Rather(adminUserPass, os.Getenv(env.AuthN.AdminPassword)) + userName := cos.Right(adminUserID, os.Getenv(env.AuthN.AdminUsername)) + password := cos.Right(adminUserPass, os.Getenv(env.AuthN.AdminPassword)) // Create the admin user su := &authn.User{ diff --git a/cmn/bck.go b/cmn/bck.go index 56e700d911..f77c51947b 100644 --- a/cmn/bck.go +++ b/cmn/bck.go @@ -512,8 +512,8 @@ func (qbck QueryBcks) Equal(bck *Bck) bool { return Bck(qbck).Equal(bck) } // NOTE: a named bucket with no provider is assumed to be ais:// func (qbck QueryBcks) Contains(other *Bck) bool { if qbck.Name != "" { - other.Provider = cos.Rather(apc.AIS, other.Provider) - qbck.Provider = cos.Rather(other.Provider, qbck.Provider) //nolint:revive // if not set we match the expected + other.Provider = cos.Right(apc.AIS, other.Provider) + qbck.Provider = cos.Right(other.Provider, qbck.Provider) //nolint:revive // if not set we match the expected return qbck.Equal(other) } ok := qbck.Provider == other.Provider || qbck.Provider == "" diff --git a/cmn/cos/strings.go b/cmn/cos/strings.go index cc20d6b04a..b56fb81d02 100644 --- a/cmn/cos/strings.go +++ b/cmn/cos/strings.go @@ -36,20 +36,20 @@ func TrimLastB(s string, b byte) string { return s } -// return non-empty -func Either(lhs, rhs string) string { - if lhs != "" { - return lhs +// left if non-empty; otherwise right +func Left(left, right string) string { + if left != "" { + return left } - return rhs + return right } -// rightmost override if non-empty -func Rather(lhs /*e.g., default value*/, rhs string) string { - if rhs != "" { - return rhs +// right if non-empty; otherwise left +func Right(left, right string) string { + if right != "" { + return right } - return lhs + return left } // (common use) diff --git a/cmn/objlist_utils.go b/cmn/objlist_utils.go index 72af7545f5..d03b813b03 100644 --- a/cmn/objlist_utils.go +++ b/cmn/objlist_utils.go @@ -183,11 +183,11 @@ func MergeLso(lists []*LsoRes, lsmsg *apc.LsoMsg, maxSize int) *LsoRes { } // merge existing w/ new props if !entry.IsPresent() && en.IsPresent() { - en.Version = cos.Either(en.Version, entry.Version) + en.Version = cos.Left(en.Version, entry.Version) tmp[en.Name] = en } else { - entry.Location = cos.Either(entry.Location, en.Location) - entry.Version = cos.Either(entry.Version, en.Version) + entry.Location = cos.Left(entry.Location, en.Location) + entry.Version = cos.Left(entry.Version, en.Version) } } } diff --git a/deploy/dev/local/deploy.sh b/deploy/dev/local/deploy.sh index 75b6ab733e..e05fd9435f 100755 --- a/deploy/dev/local/deploy.sh +++ b/deploy/dev/local/deploy.sh @@ -15,8 +15,8 @@ # and so on. This rule holds for all AIS "applications" except `aisnode` itself. # See https://github.com/NVIDIA/aistore/tree/main/cmn/fname for the most updated locations. # -# NOTE: build tag `statsd` is the Local Playground's default; to enable Prometheus, -# remove `statsd` from the "... TAGS=statsd make ..." command below. +# NOTE: Prometheus is the Local Playground's default; use TAGS to specify `statsd` and/or +# any other non-default build tag. # ############################################ @@ -171,10 +171,11 @@ parse_backend_providers create_loopbacks -## NOTE: build tag `statsd` in the make command; +## NOTE: to enable StatsD instead of Prometheus, use build tag `statsd` in the make command, as follows: +## TAGS=statsd make ... ## see docs/metrics.md and docs/prometheus.md for more information. ## -if ! AIS_BACKEND_PROVIDERS=${AIS_BACKEND_PROVIDERS} TAGS=statsd make --no-print-directory -C ${AISTORE_PATH} node; then +if ! AIS_BACKEND_PROVIDERS=${AIS_BACKEND_PROVIDERS} make --no-print-directory -C ${AISTORE_PATH} node; then exit_error "failed to compile 'aisnode' binary" fi