Skip to content

Commit

Permalink
Added logs to HTTP(S) server flow, to log every request coming to con…
Browse files Browse the repository at this point in the history
…troller
  • Loading branch information
Utkarsh Shukla committed Dec 11, 2024
1 parent 657e26f commit 76077c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func main() {

// Now, add all the others defined by our config.
for _, service := range config.ServiceConfig.IncomingServices {
logger.Infow("Service name for which starting HTTP(S) server is", service.Name," Type is",service.ServiceType)
if service.UseHTTP {
go serviceconfig.RunHTTPServer(ctx, echoManager, agents, service)
} else {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/opsmx/oes-birger

go 1.21
go 1.23.4

require (
github.com/OpsMx/go-app-base v0.0.23
github.com/OpsMx/go-app-base v0.0.24
github.com/go-resty/resty/v2 v2.11.0
github.com/google/go-cmp v0.6.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
Expand Down
8 changes: 6 additions & 2 deletions internal/serviceconfig/service_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type SearchSpec struct {
// currently will use certificates or JWT to identify the destination.
func RunHTTPSServer(ctx context.Context, em EchoManager, routes Destinations, tlsPath string, service IncomingServiceConfig) {
logger := logging.WithContext(ctx).Sugar()

logger.Infow("Entered RunHTTPSServer")
mux := http.NewServeMux()
mux.HandleFunc("/", secureAPIHandlerMaker(em, routes, service))

Expand Down Expand Up @@ -105,6 +105,8 @@ func addDefaults(ctx context.Context, server *http.Server) {

func fixedIdentityAPIHandlerMaker(em EchoManager, routes Destinations, service IncomingServiceConfig) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logger := logging.WithContext(r.Context()).Sugar()
logger.Infow("Entered fixedIdentityAPIHandlerMaker with request uri", r.URL.String())
ep := SearchSpec{
Destination: service.Destination,
ServiceType: service.ServiceType,
Expand Down Expand Up @@ -161,6 +163,8 @@ func extractEndpoint(r *http.Request) (agentIdentity string, endpointType string

func secureAPIHandlerMaker(em EchoManager, routes Destinations, service IncomingServiceConfig) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logger := logging.WithContext(r.Context()).Sugar()
logger.Infow("Entered secureAPIHandlerMaker with request uri", r.URL.String())
agentIdentity, endpointType, endpointName, err := extractEndpoint(r)
if err != nil {
r.Body.Close()
Expand All @@ -179,7 +183,7 @@ func secureAPIHandlerMaker(em EchoManager, routes Destinations, service Incoming
func runAPIHandler(em EchoManager, routes Destinations, ep SearchSpec, w http.ResponseWriter, r *http.Request) {
ctx := logging.NewContext(r.Context())
logger := logging.WithContext(ctx).Sugar()

logger.Infow("Entered runAPIHandler with request uri", r.URL.String())
session := routes.Search(ctx, ep)
if session == nil {
logger.Warnw("no such destination for service request", "destination", ep.Destination, "serviceName", ep.ServiceName, "serviceType", ep.ServiceType)
Expand Down

0 comments on commit 76077c1

Please sign in to comment.