-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding readiness routes to graphql-server and auth-server for readine…
…ss probes (#3495) * Adding probes Signed-off-by: rajdas98 <[email protected]> * fix auth server for readiness endpoint Signed-off-by: rajdas98 <[email protected]> * adding readiness route Signed-off-by: rajdas98 <[email protected]> * revertg Signed-off-by: rajdas98 <[email protected]> * revertg Signed-off-by: rajdas98 <[email protected]> * changes Signed-off-by: rajdas98 <[email protected]> * changes Signed-off-by: rajdas98 <[email protected]> * changes Signed-off-by: rajdas98 <[email protected]>
- Loading branch information
Showing
18 changed files
with
342 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
litmus-portal/authentication/api/handlers/rest/misc_handlers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package rest | ||
|
||
import ( | ||
"litmus/litmus-portal/authentication/pkg/entities" | ||
"litmus/litmus-portal/authentication/pkg/services" | ||
|
||
"github.com/gin-gonic/gin" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func contains(s []string, str string) bool { | ||
for _, v := range s { | ||
if v == str { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
type ReadinessAPIStatus struct { | ||
DataBase string `json:"database"` | ||
Collections string `json:"collections"` | ||
} | ||
|
||
// Status will request users list and return, if successful, | ||
// an http code 200 | ||
func Status(service services.ApplicationService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
_, err := service.GetUsers() | ||
if err != nil { | ||
log.Error(err) | ||
c.JSON(500, entities.APIStatus{"down"}) | ||
return | ||
} | ||
c.JSON(200, entities.APIStatus{"up"}) | ||
} | ||
} | ||
|
||
func Readiness(service services.ApplicationService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
var ( | ||
db_flag = "up" | ||
col_flag = "up" | ||
) | ||
|
||
dbs, err := service.ListDataBase() | ||
if !contains(dbs, "auth") { | ||
db_flag = "down" | ||
} | ||
|
||
if err != nil { | ||
log.Error(err) | ||
c.JSON(500, ReadinessAPIStatus{"down", "unknown"}) | ||
return | ||
} | ||
|
||
cols, err := service.ListCollection() | ||
if !contains(cols, "project") || !contains(cols, "users") { | ||
col_flag = "down" | ||
} | ||
|
||
if err != nil { | ||
log.Error(err) | ||
c.JSON(500, ReadinessAPIStatus{db_flag, "down"}) | ||
return | ||
} | ||
|
||
c.JSON(200, ReadinessAPIStatus{db_flag, col_flag}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package routes | ||
|
||
import ( | ||
"litmus/litmus-portal/authentication/api/handlers/rest" | ||
"litmus/litmus-portal/authentication/pkg/services" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func MiscRouter(router *gin.Engine, service services.ApplicationService) { | ||
router.GET("/status", rest.Status(service)) | ||
router.GET("/readiness", rest.Readiness(service)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package misc | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
//Repository holds the mongo database implementation of the Service | ||
type Repository interface { | ||
ListCollection() ([]string, error) | ||
ListDataBase() ([]string, error) | ||
} | ||
|
||
type repository struct { | ||
DataBase *mongo.Database | ||
Client *mongo.Client | ||
} | ||
|
||
func (r repository) ListCollection() ([]string, error) { | ||
var err error | ||
cols, err := r.DataBase.ListCollectionNames(context.Background(), bson.D{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cols, nil | ||
} | ||
|
||
func (r repository) ListDataBase() ([]string, error) { | ||
var err error | ||
dbs, err := r.Client.ListDatabaseNames(context.Background(), bson.D{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return dbs, nil | ||
} | ||
|
||
func NewRepo(db *mongo.Database, client *mongo.Client) Repository { | ||
return &repository{ | ||
DataBase: db, | ||
Client: client, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package services | ||
|
||
// Service creates a service for user authentication operations | ||
type miscService interface { | ||
ListCollection() ([]string, error) | ||
ListDataBase() ([]string, error) | ||
} | ||
|
||
func (a applicationService) ListCollection() ([]string, error) { | ||
return a.miscRepository.ListCollection() | ||
} | ||
|
||
func (a applicationService) ListDataBase() ([]string, error) { | ||
return a.miscRepository.ListDataBase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.