Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions App.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package main

import (
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/common-lib/constants"
"github.com/devtron-labs/common-lib/middlewares"
"github.com/devtron-labs/kubelink/api/router"
client "github.com/devtron-labs/kubelink/grpc"
"github.com/devtron-labs/kubelink/pkg/k8sInformer"
"github.com/devtron-labs/kubelink/pkg/service"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"go.uber.org/zap"
Expand All @@ -23,20 +25,27 @@ import (
)

type App struct {
Logger *zap.SugaredLogger
ServerImpl *service.ApplicationServiceServerImpl
router *router.RouterImpl
k8sInformer k8sInformer.K8sInformer
Logger *zap.SugaredLogger
ServerImpl *service.ApplicationServiceServerImpl
router *router.RouterImpl
k8sInformer k8sInformer.K8sInformer
LoggerConfig *LoggerConfig
}

func NewApp(Logger *zap.SugaredLogger, ServerImpl *service.ApplicationServiceServerImpl,
router *router.RouterImpl, k8sInformer k8sInformer.K8sInformer) *App {
return &App{
router *router.RouterImpl, k8sInformer k8sInformer.K8sInformer) (*App, error) {
app := &App{
Logger: Logger,
ServerImpl: ServerImpl,
router: router,
k8sInformer: k8sInformer,
}
cfg, err := GetLoggerConfig()
if err != nil {
return nil, err
}
app.LoggerConfig = cfg
return app, err
}

func (app *App) Start() {
Expand All @@ -61,9 +70,13 @@ func (app *App) Start() {
}),
grpc.ChainStreamInterceptor(
grpc_prometheus.StreamServerInterceptor,
logging.StreamServerInterceptor(middlewares.InterceptorLogger(app.LoggerConfig.EnableLogger, app.Logger),
logging.WithLogOnEvents(logging.PayloadReceived)),
recovery.StreamServerInterceptor(recoveryOption)), // panic interceptor, should be at last
grpc.ChainUnaryInterceptor(
grpc_prometheus.UnaryServerInterceptor,
logging.UnaryServerInterceptor(middlewares.InterceptorLogger(app.LoggerConfig.EnableLogger, app.Logger),
logging.WithLogOnEvents(logging.PayloadReceived)),
recovery.UnaryServerInterceptor(recoveryOption)), // panic interceptor, should be at last
}
app.router.InitRouter()
Expand All @@ -88,3 +101,13 @@ func (app *App) Start() {
}

}

type LoggerConfig struct {
EnableLogger bool `env:"FEATURE_LOGGER_MIDDLEWARE_ENABLE" envDefault:"false"`
}

func GetLoggerConfig() (*LoggerConfig, error) {
cfg := &LoggerConfig{}
err := env.Parse(cfg)
return cfg, err
}
37 changes: 19 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
//github.com/argoproj/gitops-engine v0.7.1-0.20231013183858-f15cf615b814
github.com/aws/aws-sdk-go v1.44.285
github.com/caarlos0/env v3.5.0+incompatible
github.com/devtron-labs/common-lib v0.0.16-0.20240318063710-69cb957d019a
github.com/devtron-labs/common-lib v0.0.16-0.20240418060324-b414ea7c74a3
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible
github.com/go-pg/pg v6.15.1+incompatible
Expand All @@ -17,8 +17,8 @@ require (
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.21.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.58.3
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.61.1
google.golang.org/protobuf v1.33.0
helm.sh/helm/v3 v3.14.3
k8s.io/api v0.29.0
Expand All @@ -34,7 +34,7 @@ require (
require (
github.com/davecgh/go-spew v1.1.1
github.com/devtron-labs/authenticator v0.4.31
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3
)

Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand All @@ -85,7 +85,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand Down Expand Up @@ -146,23 +146,24 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading