Skip to content

Commit

Permalink
Merge pull request #24 from ultravioletrs/NOISSUE-updateMF
Browse files Browse the repository at this point in the history
NOISSUE - Update Mainflux Dependency
  • Loading branch information
darkodraskovic authored Jul 24, 2023
2 parents 6cecedd + 8505dee commit bb88a71
Show file tree
Hide file tree
Showing 226 changed files with 23,385 additions and 10,273 deletions.
4 changes: 2 additions & 2 deletions agent/api/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
)

// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(tracer opentracing.Tracer, svc agent.Service) http.Handler {
func MakeHandler(tracer opentracing.Tracer, svc agent.Service, instanceID string) http.Handler {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(encodeError),
}
Expand All @@ -50,7 +50,7 @@ func MakeHandler(tracer opentracing.Tracer, svc agent.Service) http.Handler {
opts...,
))

r.GetFunc("/version", mainflux.Health("things"))
r.GetFunc("/version", mainflux.Health("things", instanceID))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
28 changes: 18 additions & 10 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
"os/signal"
"syscall"

"github.com/mainflux/mainflux/logger"
mflog "github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/pkg/uuid"
opentracing "github.com/opentracing/opentracing-go"
jconfig "github.com/uber/jaeger-client-go/config"
agent "github.com/ultravioletrs/agent/agent"
"github.com/ultravioletrs/agent/agent/api"
agentgrpc "github.com/ultravioletrs/agent/agent/api/grpc"
agenthttpapi "github.com/ultravioletrs/agent/agent/api/http"
"github.com/ultravioletrs/agent/internal"
"github.com/ultravioletrs/agent/internal/env"
"google.golang.org/grpc"

opentracing "github.com/opentracing/opentracing-go"
jconfig "github.com/uber/jaeger-client-go/config"
)

const svcName = "agent"
Expand All @@ -34,6 +34,7 @@ type config struct {
Secret string `env:"AGENT_SECRET" envDefault:"secret"`
AgentGRPCURL string `env:"AGENT_GRPC_URL" envDefault:"localhost:7002"`
JaegerURL string `env:"AGENT_JAEGER_URL" envDefault:""`
InstanceID string `env:"AGENT_INSTANCE_ID" envDefault:""`
}

func main() {
Expand All @@ -42,19 +43,26 @@ func main() {
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := logger.New(os.Stdout, cfg.LogLevel)
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf(err.Error())
}

if cfg.InstanceID == "" {
cfg.InstanceID, err = uuid.New().ID()
if err != nil {
log.Fatalf("Failed to generate instanceID: %s", err)
}
}

agentTracer, agentCloser := initJaeger("agent", cfg.JaegerURL, logger)
defer agentCloser.Close()

svc := newService(cfg.Secret, logger)
errs := make(chan error, 2)

go startgRPCServer(cfg, &svc, logger, errs)
go startHTTPServer(agenthttpapi.MakeHandler(agentTracer, svc), cfg.HTTPPort, cfg, logger, errs)
go startHTTPServer(agenthttpapi.MakeHandler(agentTracer, svc, cfg.InstanceID), cfg.HTTPPort, cfg, logger, errs)

go func() {
c := make(chan os.Signal, 1)
Expand All @@ -66,7 +74,7 @@ func main() {
logger.Error(fmt.Sprintf("Agent service terminated: %s", err))
}

func initJaeger(svcName, url string, logger logger.Logger) (opentracing.Tracer, io.Closer) {
func initJaeger(svcName, url string, logger mflog.Logger) (opentracing.Tracer, io.Closer) {
if url == "" {
return opentracing.NoopTracer{}, ioutil.NopCloser(nil)
}
Expand All @@ -90,7 +98,7 @@ func initJaeger(svcName, url string, logger logger.Logger) (opentracing.Tracer,
return tracer, closer
}

func newService(secret string, logger logger.Logger) agent.Service {
func newService(secret string, logger mflog.Logger) agent.Service {
svc := agent.New(secret)

svc = api.LoggingMiddleware(svc, logger)
Expand All @@ -100,7 +108,7 @@ func newService(secret string, logger logger.Logger) agent.Service {
return svc
}

func startHTTPServer(handler http.Handler, port string, cfg config, logger logger.Logger, errs chan error) {
func startHTTPServer(handler http.Handler, port string, cfg config, logger mflog.Logger, errs chan error) {
p := fmt.Sprintf(":%s", port)
if cfg.ServerCert != "" || cfg.ServerKey != "" {
logger.Info(fmt.Sprintf("Agent service started using https on port %s with cert %s key %s",
Expand All @@ -112,7 +120,7 @@ func startHTTPServer(handler http.Handler, port string, cfg config, logger logge
errs <- http.ListenAndServe(p, handler)
}

func startgRPCServer(cfg config, svc *agent.Service, logger logger.Logger, errs chan error) {
func startgRPCServer(cfg config, svc *agent.Service, logger mflog.Logger, errs chan error) {
// Create a gRPC server object
tracer := opentracing.GlobalTracer()
server := grpc.NewServer()
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/caarlos0/env/v7 v7.1.0
github.com/go-kit/kit v0.12.0
github.com/go-zoo/bone v1.3.0
github.com/mainflux/mainflux v0.0.0-20221221180352-57e3c25d3de3
github.com/mainflux/mainflux v0.0.0-20230722123816-70f53c2f979d
github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cobra v1.6.1
github.com/prometheus/client_golang v1.16.0
github.com/spf13/cobra v1.7.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
google.golang.org/grpc v1.56.1
google.golang.org/protobuf v1.31.0
Expand All @@ -19,21 +19,21 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
)
Loading

0 comments on commit bb88a71

Please sign in to comment.