From 7ac9968bf4bfa88148951aa48f8ddf0a65a19ff5 Mon Sep 17 00:00:00 2001 From: Nithunikzz Date: Fri, 26 Apr 2024 11:08:52 +0530 Subject: [PATCH] Fix --- agent/container/pkg/clients/nats_client.go | 30 +++++++++---------- agent/git/pkg/clients/nats_client.go | 30 +++++++++---------- agent/kubviz/k8smetrics_agent.go | 34 +++++++++++----------- client/pkg/clients/clients.go | 30 +++++++++---------- 4 files changed, 62 insertions(+), 62 deletions(-) diff --git a/agent/container/pkg/clients/nats_client.go b/agent/container/pkg/clients/nats_client.go index 2c12d062..9a1bd7cd 100755 --- a/agent/container/pkg/clients/nats_client.go +++ b/agent/container/pkg/clients/nats_client.go @@ -49,30 +49,30 @@ func NewNATSContext(conf *config.Config) (*NATSContext, error) { //conn, err := nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) var conn *nats.Conn var err error - var mtlsConfig mtlsnats.MtlsConfig - - if mtlsConfig.IsEnabled { - tlsConfig, err := mtlsnats.GetTlsConfig() - if err != nil { - log.Println("Error while getting TLS config:", err) - return nil, err - } + //var mtlsConfig mtlsnats.MtlsConfig + tlsConfig, err := mtlsnats.GetTlsConfig() + if err != nil { + log.Println("error while getting tls config ", err) + time.Sleep(time.Minute * 30) + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), + //nats.Token(conf.NatsToken), nats.Secure(tlsConfig), ) if err != nil { - log.Fatal("Error while connecting with mTLS:", err) - } - } else { - conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) - if err != nil { - log.Println("Error while connecting with token:", err) - return nil, err + log.Fatal("error while connecting with mtls ", err) } } + // if conn == nil { + // conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) + // if err != nil { + // return nil, fmt.Errorf("error while connecting with token: %w", err) + // } + // } + ctx := &NATSContext{ conf: conf, conn: conn, diff --git a/agent/git/pkg/clients/nats_client.go b/agent/git/pkg/clients/nats_client.go index 378bb842..c2e89ba4 100644 --- a/agent/git/pkg/clients/nats_client.go +++ b/agent/git/pkg/clients/nats_client.go @@ -39,30 +39,30 @@ func NewNATSContext(conf *config.Config) (*NATSContext, error) { var conn *nats.Conn var err error - var mtlsConfig mtlsnats.MtlsConfig - - if mtlsConfig.IsEnabled { - tlsConfig, err := mtlsnats.GetTlsConfig() - if err != nil { - log.Println("Error while getting TLS config:", err) - return nil, err - } + //var mtlsConfig mtlsnats.MtlsConfig + tlsConfig, err := mtlsnats.GetTlsConfig() + if err != nil { + log.Println("error while getting tls config ", err) + time.Sleep(time.Minute * 30) + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), + //nats.Token(conf.NatsToken), nats.Secure(tlsConfig), ) if err != nil { - log.Fatal("Error while connecting with mTLS:", err) - } - } else { - conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) - if err != nil { - log.Println("Error while connecting with token:", err) - return nil, err + log.Fatal("error while connecting with mtls ", err) } } + // if conn == nil { + // conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) + // if err != nil { + // return nil, fmt.Errorf("error while connecting with token: %w", err) + // } + // } + ctx := &NATSContext{ conf: conf, conn: conn, diff --git a/agent/kubviz/k8smetrics_agent.go b/agent/kubviz/k8smetrics_agent.go index df460d44..a22d7c8a 100644 --- a/agent/kubviz/k8smetrics_agent.go +++ b/agent/kubviz/k8smetrics_agent.go @@ -77,30 +77,30 @@ func main() { clientset *kubernetes.Clientset ) - var mtlsConfig mtlsnats.MtlsConfig + //var mtlsConfig mtlsnats.MtlsConfig var nc *nats.Conn - if mtlsConfig.IsEnabled { - tlsConfig, err := mtlsnats.GetTlsConfig() - if err != nil { - log.Println("Error while getting TLS config:", err) - //return nil, err - } - - nc, err = nats.Connect(natsurl, - nats.Name("Github metrics"), + //if mtlsConfig.IsEnabled { + tlsConfig, err := mtlsnats.GetTlsConfig() + if err != nil { + log.Println("error while getting tls config ", err) + time.Sleep(time.Minute * 30) + } else { + nc, err = nats.Connect( + natsurl, + nats.Name("K8s Metrics"), + //nats.Token(token), nats.Secure(tlsConfig), ) if err != nil { - log.Fatal("Error while connecting with mTLS:", err) - } - } else { - nc, err = nats.Connect(natsurl, nats.Name("Github metrics"), nats.Token(token)) - if err != nil { - log.Println("Error while connecting with token:", err) - //return nil, err + log.Fatal("error while connecting with mtls ", err) } } + + // if nc == nil { + // nc, err = nats.Connect(natsurl, nats.Name("K8s Metrics"), nats.Token(token)) + // events.CheckErr(err) + // } js, err := nc.JetStream() events.CheckErr(err) err = events.CreateStream(js) diff --git a/client/pkg/clients/clients.go b/client/pkg/clients/clients.go index 00df5132..71ee56e2 100644 --- a/client/pkg/clients/clients.go +++ b/client/pkg/clients/clients.go @@ -26,30 +26,30 @@ func NewNATSContext(conf *config.Config, dbClient clickhouse.DBInterface) (*NATS var conn *nats.Conn var err error - var mtlsConfig mtlsnats.MtlsConfig - - if mtlsConfig.IsEnabled { - tlsConfig, err := mtlsnats.GetTlsConfig() - if err != nil { - log.Println("Error while getting TLS config:", err) - return nil, err - } + //var mtlsConfig mtlsnats.MtlsConfig + tlsConfig, err := mtlsnats.GetTlsConfig() + if err != nil { + log.Println("error while getting tls config ", err) + time.Sleep(time.Minute * 30) + } else { conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), + //nats.Token(conf.NatsToken), nats.Secure(tlsConfig), ) if err != nil { - log.Fatal("Error while connecting with mTLS:", err) - } - } else { - conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) - if err != nil { - log.Println("Error while connecting with token:", err) - return nil, err + log.Fatal("error while connecting with mtls ", err) } } + // if conn == nil { + // conn, err = nats.Connect(conf.NatsAddress, nats.Name("Github metrics"), nats.Token(conf.NatsToken)) + // if err != nil { + // return nil, fmt.Errorf("error while connecting with token: %w", err) + // } + // } + ctx := &NATSContext{ conf: conf, conn: conn,