From 892015a60fb28adbb06994e4e8bea0c48b90e90b Mon Sep 17 00:00:00 2001 From: Ian Ngethe Muchiri <100555904+ianmuchyri@users.noreply.github.com> Date: Fri, 7 Jul 2023 12:14:55 +0300 Subject: [PATCH] NOISSUE - Add instance ID (#1776) * update or to sync with clients branch Signed-off-by: ianmuchyri * Add empty lines Signed-off-by: ianmuchyri * update inline constant Signed-off-by: ianmuchyri * rebase pr to sync with master branch Signed-off-by: ianmuchyri * update pr to sync with updated master #1849 Signed-off-by: ianmuchyri --------- Signed-off-by: ianmuchyri --- api/openapi/users.yml | 1 - bootstrap/api/endpoint_test.go | 5 ++-- bootstrap/api/transport.go | 4 +-- bootstrap/redis/producer/streams_test.go | 3 ++- bootstrap/service_test.go | 3 ++- certs/api/transport.go | 4 +-- certs/service_test.go | 3 ++- cmd/bootstrap/main.go | 14 ++++++++-- cmd/cassandra-reader/main.go | 12 ++++++++- cmd/cassandra-writer/main.go | 14 ++++++++-- cmd/certs/main.go | 12 ++++++++- cmd/coap/main.go | 14 ++++++++-- cmd/http/main.go | 14 ++++++++-- cmd/influxdb-reader/main.go | 12 ++++++++- cmd/influxdb-writer/main.go | 14 ++++++++-- cmd/lora/main.go | 14 ++++++++-- cmd/mongodb-reader/main.go | 12 ++++++++- cmd/mongodb-writer/main.go | 14 ++++++++-- cmd/mqtt/main.go | 12 ++++++++- cmd/opcua/main.go | 14 ++++++++-- cmd/postgres-reader/main.go | 13 +++++++++- cmd/postgres-writer/main.go | 14 ++++++++-- cmd/provision/main.go | 13 +++++++++- cmd/smpp-notifier/main.go | 26 +++++++++++++------ cmd/smtp-notifier/main.go | 26 +++++++++++++------ cmd/things/main.go | 14 ++++++++-- cmd/timescale-reader/main.go | 16 +++++++++--- cmd/timescale-writer/main.go | 24 ++++++++++++----- cmd/twins/main.go | 13 ++++++++-- cmd/users/main.go | 13 ++++++++-- cmd/ws/main.go | 22 +++++++++++----- coap/api/transport.go | 4 +-- consumers/notifiers/api/endpoint_test.go | 3 ++- consumers/notifiers/api/transport.go | 4 +-- consumers/writers/api/transport.go | 4 +-- docker/.env | 26 ++++++++++++++++++- docker/addons/bootstrap/docker-compose.yml | 1 + .../cassandra-reader/docker-compose.yml | 1 + .../cassandra-writer/docker-compose.yml | 1 + docker/addons/certs/docker-compose.yml | 1 + .../addons/influxdb-reader/docker-compose.yml | 1 + .../addons/influxdb-writer/docker-compose.yml | 1 + docker/addons/lora-adapter/docker-compose.yml | 1 + .../addons/mongodb-reader/docker-compose.yml | 1 + .../addons/mongodb-writer/docker-compose.yml | 1 + .../addons/opcua-adapter/docker-compose.yml | 1 + .../addons/postgres-reader/docker-compose.yml | 1 + .../addons/postgres-writer/docker-compose.yml | 1 + docker/addons/provision/docker-compose.yml | 1 + .../addons/smpp-notifier/docker-compose.yml | 1 + .../addons/smtp-notifier/docker-compose.yml | 1 + .../timescale-reader/docker-compose.yml | 1 + .../timescale-writer/docker-compose.yml | 1 + docker/addons/twins/docker-compose.yml | 1 + docker/docker-compose.yml | 4 +++ health.go | 6 ++++- http/api/endpoint_test.go | 4 ++- http/api/transport.go | 4 +-- internal/clients/jaeger/provider.go | 7 +++-- lora/api/api.go | 4 +-- opcua/api/transport.go | 4 +-- pkg/sdk/go/certs_test.go | 4 ++- pkg/sdk/go/consumers_test.go | 6 ++--- pkg/sdk/go/message_test.go | 2 +- pkg/sdk/go/things_test.go | 2 +- pkg/sdk/go/users_test.go | 2 +- provision/api/transport.go | 4 +-- readers/api/endpoint_test.go | 3 ++- readers/api/transport.go | 4 +-- things/clients/api/transport.go | 4 +-- twins/api/http/endpoint_twins_test.go | 3 ++- twins/api/http/transport.go | 4 +-- users/clients/api/transport.go | 4 +-- ws/api/endpoint_test.go | 11 ++++---- ws/api/transport.go | 4 +-- 75 files changed, 421 insertions(+), 117 deletions(-) diff --git a/api/openapi/users.yml b/api/openapi/users.yml index 40d123600a..df1dde2c87 100644 --- a/api/openapi/users.yml +++ b/api/openapi/users.yml @@ -1967,4 +1967,3 @@ components: security: - bearerAuth: [] - refreshAuth: [] - \ No newline at end of file diff --git a/bootstrap/api/endpoint_test.go b/bootstrap/api/endpoint_test.go index 97e428a254..e6ec027b69 100644 --- a/bootstrap/api/endpoint_test.go +++ b/bootstrap/api/endpoint_test.go @@ -51,6 +51,7 @@ const ( addExternalKey = "external-key" addName = "name" addContent = "config" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var ( @@ -201,7 +202,7 @@ func newThingsService(auth upolicies.AuthServiceClient) (clients.Service, groups func newThingsServer(csvc clients.Service, gsvc groups.Service, psvc tpolicies.Service) *httptest.Server { logger := mflog.NewMock() mux := bone.New() - capi.MakeHandler(csvc, mux, logger) + capi.MakeHandler(csvc, mux, logger, instanceID) gapi.MakeHandler(gsvc, mux, logger) papi.MakeHandler(csvc, psvc, mux, logger) return httptest.NewServer(mux) @@ -209,7 +210,7 @@ func newThingsServer(csvc clients.Service, gsvc groups.Service, psvc tpolicies.S func newBootstrapServer(svc bootstrap.Service) *httptest.Server { logger := mflog.NewMock() - mux := bsapi.MakeHandler(svc, bootstrap.NewConfigReader(encKey), logger) + mux := bsapi.MakeHandler(svc, bootstrap.NewConfigReader(encKey), logger, instanceID) return httptest.NewServer(mux) } diff --git a/bootstrap/api/transport.go b/bootstrap/api/transport.go index bbc3dd8e13..66c52b0668 100644 --- a/bootstrap/api/transport.go +++ b/bootstrap/api/transport.go @@ -34,7 +34,7 @@ var ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mflog.Logger) http.Handler { +func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mflog.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), } @@ -100,7 +100,7 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mf encodeResponse, opts...)) - r.GetFunc("/health", mainflux.Health("bootstrap")) + r.GetFunc("/health", mainflux.Health("bootstrap", instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/bootstrap/redis/producer/streams_test.go b/bootstrap/redis/producer/streams_test.go index e939eafc48..1ce76ff303 100644 --- a/bootstrap/redis/producer/streams_test.go +++ b/bootstrap/redis/producer/streams_test.go @@ -51,6 +51,7 @@ const ( thingStateChange = thingPrefix + "state_change" thingBootstrap = thingPrefix + "bootstrap" thingUpdateConnections = thingPrefix + "update_connections" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var ( @@ -101,7 +102,7 @@ func newThingsService(auth upolicies.AuthServiceClient) (clients.Service, groups func newThingsServer(csvc clients.Service, gsvc groups.Service, psvc tpolicies.Service) *httptest.Server { logger := logger.NewMock() mux := bone.New() - capi.MakeHandler(csvc, mux, logger) + capi.MakeHandler(csvc, mux, logger, instanceID) gapi.MakeHandler(gsvc, mux, logger) papi.MakeHandler(csvc, psvc, mux, logger) return httptest.NewServer(mux) diff --git a/bootstrap/service_test.go b/bootstrap/service_test.go index a428ba211c..1ca1e915cb 100644 --- a/bootstrap/service_test.go +++ b/bootstrap/service_test.go @@ -42,6 +42,7 @@ const ( email = "test@example.com" unknown = "unknown" channelsNum = 3 + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var ( @@ -92,7 +93,7 @@ func newThingsService(auth upolicies.AuthServiceClient) (clients.Service, groups func newThingsServer(csvc clients.Service, gsvc groups.Service, psvc tpolicies.Service) *httptest.Server { logger := mflog.NewMock() mux := bone.New() - capi.MakeHandler(csvc, mux, logger) + capi.MakeHandler(csvc, mux, logger, instanceID) gapi.MakeHandler(gsvc, mux, logger) papi.MakeHandler(csvc, psvc, mux, logger) return httptest.NewServer(mux) diff --git a/certs/api/transport.go b/certs/api/transport.go index f304a9734a..79deecb6f5 100644 --- a/certs/api/transport.go +++ b/certs/api/transport.go @@ -27,7 +27,7 @@ const ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc certs.Service, logger logger.Logger) http.Handler { +func MakeHandler(svc certs.Service, logger logger.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), } @@ -63,7 +63,7 @@ func MakeHandler(svc certs.Service, logger logger.Logger) http.Handler { )) r.Handle("/metrics", promhttp.Handler()) - r.GetFunc("/health", mainflux.Health("certs")) + r.GetFunc("/health", mainflux.Health("certs", instanceID)) return r } diff --git a/certs/service_test.go b/certs/service_test.go index 4ec889aa4e..55cade01cb 100644 --- a/certs/service_test.go +++ b/certs/service_test.go @@ -43,6 +43,7 @@ const ( caPath = "../docker/ssl/certs/ca.crt" caKeyPath = "../docker/ssl/certs/ca.key" cfgSignHoursValid = "24h" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) func newService(tokens map[string]string) (certs.Service, error) { @@ -367,6 +368,6 @@ func TestViewCert(t *testing.T) { func newThingsServer(svc clients.Service) *httptest.Server { logger := logger.NewMock() mux := bone.New() - httpapi.MakeHandler(svc, mux, logger) + httpapi.MakeHandler(svc, mux, logger, instanceID) return httptest.NewServer(mux) } diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 384262ac51..5607a0bf2d 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -29,6 +29,7 @@ import ( httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" mfsdk "github.com/mainflux/mainflux/pkg/sdk/go" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/users/policies" "golang.org/x/sync/errgroup" @@ -54,6 +55,7 @@ type config struct { ThingsURL string `env:"MF_THINGS_URL" envDefault:"http://localhost:9000"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_BOOTSTRAP_INSTANCE_ID" envDefault:""` } func main() { @@ -70,6 +72,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + // Create new postgres client dbConfig := pgClient.Config{Name: defDB} @@ -94,7 +104,7 @@ func main() { defer authHandler.Close() logger.Info("Successfully connected to auth grpc server " + authHandler.Secure()) - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) } @@ -113,7 +123,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/cassandra-reader/main.go b/cmd/cassandra-reader/main.go index dc9de4a453..bdfc0f8230 100644 --- a/cmd/cassandra-reader/main.go +++ b/cmd/cassandra-reader/main.go @@ -21,6 +21,7 @@ import ( "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/readers" "github.com/mainflux/mainflux/readers/api" "github.com/mainflux/mainflux/readers/cassandra" @@ -37,6 +38,7 @@ const ( type config struct { LogLevel string `env:"MF_CASSANDRA_READER_LOG_LEVEL" envDefault:"info"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_CASSANDRA_READER_INSTANCE_ID" envDefault:""` } func main() { @@ -55,6 +57,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + // Create new thing grpc client tc, tcHandler, err := thingsClient.Setup(envPrefix) if err != nil { @@ -88,7 +98,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/cassandra-writer/main.go b/cmd/cassandra-writer/main.go index b607ea72b6..d82601fda3 100644 --- a/cmd/cassandra-writer/main.go +++ b/cmd/cassandra-writer/main.go @@ -26,6 +26,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -42,6 +43,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_CASSANDRA_WRITER_INSTANCE_ID" envDefault:""` } func main() { @@ -59,6 +61,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + // Create new to cassandra client csdSession, err := cassandraClient.SetupDB(envPrefix, cassandra.Table) if err != nil { @@ -66,7 +76,7 @@ func main() { } defer csdSession.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -100,7 +110,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 9cc83184be..511adb0b81 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -29,6 +29,7 @@ import ( authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth" pgClient "github.com/mainflux/mainflux/internal/clients/postgres" mfsdk "github.com/mainflux/mainflux/pkg/sdk/go" + "github.com/mainflux/mainflux/pkg/uuid" ) const ( @@ -44,6 +45,7 @@ type config struct { CertsURL string `env:"MF_SDK_CERTS_URL" envDefault:"http://localhost"` ThingsURL string `env:"MF_THINGS_URL" envDefault:"http://things:9000"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_CERTS_INSTANCE_ID" envDefault:""` // Sign and issue certificates without 3rd party PKI SignCAPath string `env:"MF_CERTS_SIGN_CA_PATH" envDefault:"ca.crt"` @@ -73,6 +75,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + if cfg.PkiHost == "" { logger.Fatal("No host specified for PKI engine") } @@ -102,7 +112,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/coap/main.go b/cmd/coap/main.go index 1bf86463a7..9476949a45 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -25,6 +25,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" pstracing "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -42,6 +43,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_COAP_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -58,6 +60,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + tc, tcHandler, err := thingsClient.Setup(envPrefix) if err != nil { logger.Fatal(err.Error()) @@ -65,7 +75,7 @@ func main() { defer tcHandler.Close() logger.Info("Successfully connected to things grpc server " + tcHandler.Secure()) - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -96,7 +106,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(instanceID), logger) coapServerConfig := server.Config{Port: defSvcCoapPort} if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixCoap, AltPrefix: envPrefix}); err != nil { diff --git a/cmd/http/main.go b/cmd/http/main.go index f3b1fcaa94..97fa3b918c 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -25,6 +25,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging" "github.com/mainflux/mainflux/pkg/messaging/brokers" pstracing "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/things/policies" "go.opentelemetry.io/otel/trace" @@ -43,6 +44,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_HTTP_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -59,6 +61,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + tc, tcHandler, err := thingsClient.Setup(envPrefix) if err != nil { logger.Fatal(err.Error()) @@ -66,7 +76,7 @@ func main() { defer tcHandler.Close() logger.Info("Successfully connected to things grpc server " + tcHandler.Secure()) - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -90,7 +100,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/influxdb-reader/main.go b/cmd/influxdb-reader/main.go index ea4322b0e8..71b3a9c4f4 100644 --- a/cmd/influxdb-reader/main.go +++ b/cmd/influxdb-reader/main.go @@ -22,6 +22,7 @@ import ( "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/readers" "github.com/mainflux/mainflux/readers/api" "github.com/mainflux/mainflux/readers/influxdb" @@ -39,6 +40,7 @@ const ( type config struct { LogLevel string `env:"MF_INFLUX_READER_LOG_LEVEL" envDefault:"info"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_INFLUX_READER_INSTANCE_ID" envDefault:""` } func main() { @@ -55,6 +57,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + tc, tcHandler, err := thingsClient.Setup(envPrefix) if err != nil { logger.Fatal(err.Error()) @@ -92,7 +102,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/influxdb-writer/main.go b/cmd/influxdb-writer/main.go index 025234189e..16e6872d53 100644 --- a/cmd/influxdb-writer/main.go +++ b/cmd/influxdb-writer/main.go @@ -23,6 +23,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -40,6 +41,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_INFLUX_WRITER_INSTANCE_ID" envDefault:""` } func main() { @@ -56,7 +58,15 @@ func main() { log.Fatalf("failed to init logger: %s", err) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -110,7 +120,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/lora/main.go b/cmd/lora/main.go index 7ffa7d15f0..1bd07e438b 100644 --- a/cmd/lora/main.go +++ b/cmd/lora/main.go @@ -26,6 +26,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger" @@ -57,6 +58,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_LORA_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -73,13 +75,21 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + rmConn, err := redisClient.Setup(envPrefixRouteMap) if err != nil { logger.Fatal(fmt.Sprintf("failed to setup route map redis client : %s", err)) } defer rmConn.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -114,7 +124,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/mongodb-reader/main.go b/cmd/mongodb-reader/main.go index d91c962222..85233eec52 100644 --- a/cmd/mongodb-reader/main.go +++ b/cmd/mongodb-reader/main.go @@ -20,6 +20,7 @@ import ( "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/readers" "github.com/mainflux/mainflux/readers/api" "github.com/mainflux/mainflux/readers/mongodb" @@ -38,6 +39,7 @@ const ( type config struct { LogLevel string `env:"MF_MONGO_READER_LOG_LEVEL" envDefault:"info"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_MONGO_READER_INSTANCE_ID" envDefault:""` } func main() { @@ -54,6 +56,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + db, err := mongoClient.Setup(envPrefixDB) if err != nil { logger.Fatal(fmt.Sprintf("failed to setup mongo database : %s", err)) @@ -79,7 +89,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/mongodb-writer/main.go b/cmd/mongodb-writer/main.go index 49357ca97c..ed7cca0de6 100644 --- a/cmd/mongodb-writer/main.go +++ b/cmd/mongodb-writer/main.go @@ -24,6 +24,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "go.mongodb.org/mongo-driver/mongo" "golang.org/x/sync/errgroup" ) @@ -42,6 +43,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_MONGO_WRITER_INSTANCE_ID" envDefault:""` } func main() { @@ -58,7 +60,15 @@ func main() { log.Fatalf("failed to init logger: %s", err) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -91,7 +101,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/mqtt/main.go b/cmd/mqtt/main.go index f7ee56e6df..62540ac1e2 100644 --- a/cmd/mqtt/main.go +++ b/cmd/mqtt/main.go @@ -29,6 +29,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging/brokers" mqttpub "github.com/mainflux/mainflux/pkg/messaging/mqtt" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" mp "github.com/mainflux/mproxy/pkg/mqtt" "github.com/mainflux/mproxy/pkg/session" ws "github.com/mainflux/mproxy/pkg/websocket" @@ -57,6 +58,7 @@ type config struct { JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_MQTT_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -73,6 +75,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + if cfg.MqttTargetHealthCheck != "" { notify := func(e error, next time.Duration) { logger.Info(fmt.Sprintf("Broker not ready: %s, next try in %s", e.Error(), next)) @@ -84,7 +94,7 @@ func main() { } } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } diff --git a/cmd/opcua/main.go b/cmd/opcua/main.go index 17bef1ebdc..48a9cde364 100644 --- a/cmd/opcua/main.go +++ b/cmd/opcua/main.go @@ -27,6 +27,7 @@ import ( "github.com/mainflux/mainflux/opcua/redis" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -49,6 +50,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_OPCUA_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -70,6 +72,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + rmConn, err := redisClient.Setup(envPrefixRouteMap) if err != nil { logger.Fatal(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err)) @@ -86,7 +96,7 @@ func main() { } defer esConn.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -116,7 +126,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, httpCancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, httpCancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, httpCancel) diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index 3e8c0e0e8a..de2d66de92 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -21,6 +21,7 @@ import ( "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/readers" "github.com/mainflux/mainflux/readers/api" "github.com/mainflux/mainflux/readers/postgres" @@ -38,6 +39,7 @@ const ( type config struct { LogLevel string `env:"MF_POSTGRES_READER_LOG_LEVEL" envDefault:"info"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_POSTGRES_READER_INSTANCE_ID" envDefault:""` } func main() { @@ -58,6 +60,15 @@ func main() { if err != nil { logger.Fatal(err.Error()) } + + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + defer tcHandler.Close() logger.Info("Successfully connected to things grpc server " + tcHandler.Secure()) @@ -84,7 +95,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/postgres-writer/main.go b/cmd/postgres-writer/main.go index 4c8ce4f695..98451a8c75 100644 --- a/cmd/postgres-writer/main.go +++ b/cmd/postgres-writer/main.go @@ -25,6 +25,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -42,6 +43,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_POSTGRES_WRITER_INSTANCE_ID" envDefault:""` } func main() { @@ -58,7 +60,15 @@ func main() { log.Fatalf("failed to init logger: %s", err) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -93,7 +103,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/provision/main.go b/cmd/provision/main.go index eda90527b6..8325b06164 100644 --- a/cmd/provision/main.go +++ b/cmd/provision/main.go @@ -22,6 +22,7 @@ import ( "github.com/mainflux/mainflux/pkg/errors" mfgroups "github.com/mainflux/mainflux/pkg/groups" mfSDK "github.com/mainflux/mainflux/pkg/sdk/go" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/provision" "github.com/mainflux/mainflux/provision/api" "golang.org/x/sync/errgroup" @@ -50,6 +51,7 @@ const ( defBSContent = "" defCertsHoursValid = "2400h" defSendTelemetry = "true" + defInstanceID = "" envConfigFile = "MF_PROVISION_CONFIG_FILE" envLogLevel = "MF_PROVISION_LOG_LEVEL" @@ -71,6 +73,7 @@ const ( envBSContent = "MF_PROVISION_BS_CONTENT" envCertsHoursValid = "MF_PROVISION_CERTS_HOURS_VALID" envSendTelemetry = "MF_SEND_TELEMETRY" + envInstanceID = "MF_PROVISION_INSTANCE_ID" contentType = "application/json" ) @@ -99,6 +102,14 @@ func main() { log.Fatalf(err.Error()) } + instanceID := mainflux.Env(envInstanceID, defInstanceID) + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + if cfgFromFile, err := loadConfigFromFile(cfg.File); err != nil { logger.Warn(fmt.Sprintf("Continue with settings from env, failed to load from: %s: %s", cfg.File, err)) } else { @@ -122,7 +133,7 @@ func main() { svc = api.NewLoggingMiddleware(svc, logger) httpServerConfig := server.Config{Host: "", Port: cfg.Server.HTTPPort, KeyFile: cfg.Server.ServerKey, CertFile: cfg.Server.ServerCert} - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/smpp-notifier/main.go b/cmd/smpp-notifier/main.go index dbcab70ddf..f78d727ab3 100644 --- a/cmd/smpp-notifier/main.go +++ b/cmd/smpp-notifier/main.go @@ -34,6 +34,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging/brokers" pstracing "github.com/mainflux/mainflux/pkg/messaging/tracing" "github.com/mainflux/mainflux/pkg/ulid" + "github.com/mainflux/mainflux/pkg/uuid" ) const ( @@ -45,12 +46,13 @@ const ( ) type config struct { - LogLevel string `env:"MF_SMPP_NOTIFIER_LOG_LEVEL" envDefault:"info"` - From string `env:"MF_SMPP_NOTIFIER_FROM_ADDR" envDefault:""` - ConfigPath string `env:"MF_SMPP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"` - BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` - JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` - SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + LogLevel string `env:"MF_SMPP_NOTIFIER_LOG_LEVEL" envDefault:"info"` + From string `env:"MF_SMPP_NOTIFIER_FROM_ADDR" envDefault:""` + ConfigPath string `env:"MF_SMPP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"` + BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` + JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` + SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_SMPP_NOTIFIER_INSTANCE_ID" envDefault:""` } func main() { @@ -67,6 +69,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + dbConfig := pgClient.Config{Name: defDB} db, err := pgClient.SetupWithConfig(envPrefix, *notifierPg.Migration(), dbConfig) if err != nil { @@ -79,7 +89,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to load SMPP configuration from environment : %s", err)) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -113,7 +123,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/smtp-notifier/main.go b/cmd/smtp-notifier/main.go index d912989bb2..0ad9fc5d58 100644 --- a/cmd/smtp-notifier/main.go +++ b/cmd/smtp-notifier/main.go @@ -32,6 +32,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging/brokers" pstracing "github.com/mainflux/mainflux/pkg/messaging/tracing" "github.com/mainflux/mainflux/pkg/ulid" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/users/policies" "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" @@ -46,12 +47,13 @@ const ( ) type config struct { - LogLevel string `env:"MF_SMTP_NOTIFIER_LOG_LEVEL" envDefault:"info"` - ConfigPath string `env:"MF_SMTP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"` - From string `env:"MF_SMTP_NOTIFIER_FROM_ADDR" envDefault:""` - BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` - JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` - SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + LogLevel string `env:"MF_SMTP_NOTIFIER_LOG_LEVEL" envDefault:"info"` + ConfigPath string `env:"MF_SMTP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"` + From string `env:"MF_SMTP_NOTIFIER_FROM_ADDR" envDefault:""` + BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` + JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` + SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_SMTP_NOTIFIER_INSTANCE_ID" envDefault:""` } func main() { @@ -68,6 +70,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + dbConfig := pgClient.Config{Name: defDB} db, err := pgClient.SetupWithConfig(envPrefix, *notifierPg.Migration(), dbConfig) if err != nil { @@ -80,7 +90,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to load email configuration : %s", err)) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) } @@ -115,7 +125,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/things/main.go b/cmd/things/main.go index 4c15d122b6..e6b068a143 100644 --- a/cmd/things/main.go +++ b/cmd/things/main.go @@ -73,6 +73,7 @@ type config struct { JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` CacheKeyDuration string `env:"MF_THINGS_CACHE_KEY_DURATION" envDefault:"10m"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_THINGS_INSTANCE_ID" envDefault:""` } func main() { @@ -89,6 +90,15 @@ func main() { if err != nil { log.Fatalf("failed to init logger: %s", err) } + + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + // Create new database for things dbConfig := pgClient.Config{Name: defDB} db, err := pgClient.SetupWithConfig(envPrefix, *thingsPg.Migration(), dbConfig) @@ -97,7 +107,7 @@ func main() { } defer db.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -145,7 +155,7 @@ func main() { } mux := bone.New() hsp := httpserver.New(ctx, cancel, "things-policies", httpServerConfig, httpapi.MakeHandler(csvc, psvc, mux, logger), logger) - hsc := httpserver.New(ctx, cancel, "things-clients", httpServerConfig, capi.MakeHandler(csvc, mux, logger), logger) + hsc := httpserver.New(ctx, cancel, "things-clients", httpServerConfig, capi.MakeHandler(csvc, mux, logger, instanceID), logger) hsg := httpserver.New(ctx, cancel, "things-groups", httpServerConfig, gapi.MakeHandler(gsvc, mux, logger), logger) registerThingsServiceServer := func(srv *grpc.Server) { diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index 419e4e5d05..731d6b5156 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -21,6 +21,7 @@ import ( "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" mflog "github.com/mainflux/mainflux/logger" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/readers" "github.com/mainflux/mainflux/readers/api" "github.com/mainflux/mainflux/readers/timescale" @@ -36,8 +37,9 @@ const ( ) type config struct { - LogLevel string `env:"MF_TIMESCALE_READER_LOG_LEVEL" envDefault:"info"` - SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + LogLevel string `env:"MF_TIMESCALE_READER_LOG_LEVEL" envDefault:"info"` + SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_TIMESCALE_READER_INSTANCE_ID" envDefault:""` } func main() { @@ -54,6 +56,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + dbConfig := pgClient.Config{Name: defDB} if err := dbConfig.LoadEnv(envPrefix); err != nil { logger.Fatal(err.Error()) @@ -84,7 +94,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/timescale-writer/main.go b/cmd/timescale-writer/main.go index ad6111449d..3cd781f840 100644 --- a/cmd/timescale-writer/main.go +++ b/cmd/timescale-writer/main.go @@ -26,6 +26,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/messaging/brokers" "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "golang.org/x/sync/errgroup" ) @@ -38,11 +39,12 @@ const ( ) type config struct { - LogLevel string `env:"MF_TIMESCALE_WRITER_LOG_LEVEL" envDefault:"info"` - ConfigPath string `env:"MF_TIMESCALE_WRITER_CONFIG_PATH" envDefault:"/config.toml"` - BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` - JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` - SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + LogLevel string `env:"MF_TIMESCALE_WRITER_LOG_LEVEL" envDefault:"info"` + ConfigPath string `env:"MF_TIMESCALE_WRITER_CONFIG_PATH" envDefault:"/config.toml"` + BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` + JaegerURL string `env:"MF_JAEGER_URL" envDefault:"localhost:6831"` + SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_TIMESCALE_WRITER_INSTANCE_ID" envDefault:""` } func main() { @@ -59,6 +61,14 @@ func main() { log.Fatal(err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + dbConfig := pgClient.Config{Name: defDB} db, err := pgClient.SetupWithConfig(envPrefix, *timescale.Migration(), dbConfig) if err != nil { @@ -66,7 +76,7 @@ func main() { } defer db.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err)) } @@ -94,7 +104,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/twins/main.go b/cmd/twins/main.go index 6117a1a326..e92831816e 100644 --- a/cmd/twins/main.go +++ b/cmd/twins/main.go @@ -56,6 +56,7 @@ type config struct { BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_TWINS_INSTANCE_ID" envDefault:""` } func main() { @@ -72,6 +73,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + cacheClient, err := redisClient.Setup(envPrefixCache) if err != nil { logger.Fatal(err.Error()) @@ -83,7 +92,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to setup postgres database : %s", err)) } - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) } @@ -121,7 +130,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, twapi.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, twapi.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/cmd/users/main.go b/cmd/users/main.go index 1c2855f94b..dce3259946 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -74,6 +74,7 @@ type config struct { ResetURL string `env:"MF_TOKEN_RESET_ENDPOINT" envDefault:"/reset-request"` JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_USERS_INSTANCE_ID" envDefault:""` PassRegex *regexp.Regexp } @@ -96,6 +97,14 @@ func main() { logger.Fatal(fmt.Sprintf("failed to init logger: %s", err.Error())) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + ec := email.Config{} if err := env.Parse(&ec); err != nil { logger.Fatal(fmt.Sprintf("failed to load email configuration : %s", err.Error())) @@ -108,7 +117,7 @@ func main() { } defer db.Close() - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) } @@ -126,7 +135,7 @@ func main() { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err.Error())) } mux := bone.New() - hsc := httpserver.New(ctx, cancel, svcName, httpServerConfig, capi.MakeHandler(csvc, mux, logger), logger) + hsc := httpserver.New(ctx, cancel, svcName, httpServerConfig, capi.MakeHandler(csvc, mux, logger, instanceID), logger) hsg := httpserver.New(ctx, cancel, svcName, httpServerConfig, gapi.MakeHandler(gsvc, mux, logger), logger) hsp := httpserver.New(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(psvc, mux, logger), logger) diff --git a/cmd/ws/main.go b/cmd/ws/main.go index cb92ee66c0..9678052c52 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -25,6 +25,7 @@ import ( "github.com/mainflux/mainflux/pkg/messaging" "github.com/mainflux/mainflux/pkg/messaging/brokers" pstracing "github.com/mainflux/mainflux/pkg/messaging/tracing" + "github.com/mainflux/mainflux/pkg/uuid" "github.com/mainflux/mainflux/things/policies" adapter "github.com/mainflux/mainflux/ws" "github.com/mainflux/mainflux/ws/api" @@ -39,10 +40,11 @@ const ( ) type config struct { - LogLevel string `env:"MF_WS_ADAPTER_LOG_LEVEL" envDefault:"info"` - BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` - JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` - SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + LogLevel string `env:"MF_WS_ADAPTER_LOG_LEVEL" envDefault:"info"` + BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"` + JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` + SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` + InstanceID string `env:"MF_WS_ADAPTER_INSTANCE_ID" envDefault:""` } func main() { @@ -59,6 +61,14 @@ func main() { log.Fatalf("failed to init logger: %s", err) } + instanceID := cfg.InstanceID + if instanceID == "" { + instanceID, err = uuid.New().ID() + if err != nil { + log.Fatalf("Failed to generate instanceID: %s", err) + } + } + tc, tcHandler, err := thingsClient.Setup(envPrefix) if err != nil { logger.Fatal(err.Error()) @@ -66,7 +76,7 @@ func main() { defer internal.Close(logger, tcHandler) logger.Info("Successfully connected to things grpc server " + tcHandler.Secure()) - tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL) + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) if err != nil { logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) } @@ -90,7 +100,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } - hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger), logger) + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, mainflux.Version, logger, cancel) diff --git a/coap/api/transport.go b/coap/api/transport.go index 4bcebdc087..830bfd4e05 100644 --- a/coap/api/transport.go +++ b/coap/api/transport.go @@ -50,9 +50,9 @@ var ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler() http.Handler { +func MakeHandler(instanceID string) http.Handler { b := bone.New() - b.GetFunc("/health", mainflux.Health(protocol)) + b.GetFunc("/health", mainflux.Health(protocol, instanceID)) b.Handle("/metrics", promhttp.Handler()) return b diff --git a/consumers/notifiers/api/endpoint_test.go b/consumers/notifiers/api/endpoint_test.go index 51240d2c5a..350e1eac8a 100644 --- a/consumers/notifiers/api/endpoint_test.go +++ b/consumers/notifiers/api/endpoint_test.go @@ -31,6 +31,7 @@ const ( token = "token" wrongValue = "wrong_value" topic = "topic" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var ( @@ -74,7 +75,7 @@ func newService(tokens map[string]string) notifiers.Service { func newServer(svc notifiers.Service) *httptest.Server { logger := logger.NewMock() - mux := httpapi.MakeHandler(svc, logger) + mux := httpapi.MakeHandler(svc, logger, instanceID) return httptest.NewServer(mux) } diff --git a/consumers/notifiers/api/transport.go b/consumers/notifiers/api/transport.go index ebbb5c45ca..6b90a033ee 100644 --- a/consumers/notifiers/api/transport.go +++ b/consumers/notifiers/api/transport.go @@ -31,7 +31,7 @@ const ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc notifiers.Service, logger logger.Logger) http.Handler { +func MakeHandler(svc notifiers.Service, logger logger.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), } @@ -66,7 +66,7 @@ func MakeHandler(svc notifiers.Service, logger logger.Logger) http.Handler { opts..., )) - mux.GetFunc("/health", mainflux.Health("notifier")) + mux.GetFunc("/health", mainflux.Health("notifier", instanceID)) mux.Handle("/metrics", promhttp.Handler()) return mux diff --git a/consumers/writers/api/transport.go b/consumers/writers/api/transport.go index 1230726a78..45cd791a03 100644 --- a/consumers/writers/api/transport.go +++ b/consumers/writers/api/transport.go @@ -12,9 +12,9 @@ import ( ) // MakeHandler returns a HTTP API handler with health check and metrics. -func MakeHandler(svcName string) http.Handler { +func MakeHandler(svcName, instanceID string) http.Handler { r := bone.New() - r.GetFunc("/health", mainflux.Health(svcName)) + r.GetFunc("/health", mainflux.Health(svcName, instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/docker/.env b/docker/.env index af4e40b34e..34216459ae 100644 --- a/docker/.env +++ b/docker/.env @@ -58,7 +58,8 @@ MF_USERS_REFRESH_TOKEN_DURATION=24h MF_USERS_ADMIN_EMAIL=admin@example.com MF_USERS_ADMIN_PASSWORD=12345678 MF_USERS_RESET_PWD_TEMPLATE=users.tmpl -MF_USERS_PASS_REGEX=^.{8,}$ +MF_USERS_PASS_REGEX=^.{8,}$$ +MF_USERS_INSTANCE_ID= ### Email utility MF_EMAIL_HOST=smtp.mailtrap.io @@ -68,6 +69,7 @@ MF_EMAIL_PASSWORD=2b0d302e775b1e MF_EMAIL_FROM_ADDRESS=from@example.com MF_EMAIL_FROM_NAME=Example MF_EMAIL_TEMPLATE=smtp-notifier.tmpl +MF_EMAIL_INSTANCE_ID= ### Token utility MF_TOKEN_RESET_ENDPOINT=/reset-request @@ -94,9 +96,11 @@ MF_THINGS_CACHE_DB= MF_THINGS_ES_URL=es-redis:${MF_REDIS_TCP_PORT} MF_THINGS_ES_PASS= MF_THINGS_ES_DB= +MF_THINGS_INSTANCE_ID= ### HTTP MF_HTTP_ADAPTER_PORT=8008 +MF_HTTP_ADAPTER_INSTANCE_ID= ### MQTT MF_MQTT_ADAPTER_LOG_LEVEL=debug @@ -106,6 +110,7 @@ MF_MQTT_ADAPTER_WS_PORT=8080 MF_MQTT_BROKER_WS_PORT=8080 MF_MQTT_ADAPTER_ES_DB=0 MF_MQTT_ADAPTER_ES_PASS= +MF_MQTT_ADAPTER_INSTANCE_ID= ### VERNEMQ MF_DOCKER_VERNEMQ_ALLOW_ANONYMOUS=on @@ -114,10 +119,12 @@ MF_DOCKER_VERNEMQ_LOG__CONSOLE__LEVEL=error ### CoAP MF_COAP_ADAPTER_LOG_LEVEL=debug MF_COAP_ADAPTER_PORT=5683 +MF_COAP_ADAPTER_INSTANCE_ID= ### WS MF_WS_ADAPTER_LOG_LEVEL=debug MF_WS_ADAPTER_PORT=8186 +MF_WS_ADAPTER_INSTANCE_ID= ### Call home MF_SEND_TELEMETRY=true @@ -131,6 +138,7 @@ MF_BOOTSTRAP_DB_USER=mainflux MF_BOOTSTRAP_DB_PASS=mainflux MF_BOOTSTRAP_DB=bootstrap MF_BOOTSTRAP_DB_SSL_MODE=disable +MF_BOOTSTRAP_INSTANCE_ID= ### Provision MF_PROVISION_CONFIG_FILE=/configs/config.toml @@ -153,6 +161,7 @@ MF_PROVISION_BS_AUTO_WHITELIST=true MF_PROVISION_BS_CONTENT= MF_PROVISION_CERTS_HOURS_VALID=2400h MF_PROVISION_CERTS_RSA_BITS=2048 +MF_PROVISION_INSTANCE_ID= # Certs MF_CERTS_LOG_LEVEL=debug @@ -176,6 +185,7 @@ MF_CERTS_SIGN_CA_KEY_PATH=/etc/ssl/certs/ca.key MF_CERTS_SIGN_HOURS_VALID=2048h MF_CERTS_SIGN_RSA_BITS=2048 MF_CERTS_VAULT_HOST=http://vault:8200 +MF_CERTS_INSTANCE_ID= ### Vault @@ -206,6 +216,7 @@ MF_LORA_ADAPTER_HTTP_PORT=9017 MF_LORA_ADAPTER_ROUTE_MAP_URL=localhost:6379 MF_LORA_ADAPTER_ROUTE_MAP_PASS= MF_LORA_ADAPTER_ROUTE_MAP_DB=0 +MF_LORA_ADAPTER_INSTANCE_ID= ### OPC-UA MF_OPCUA_ADAPTER_HTTP_PORT=8188 @@ -218,6 +229,7 @@ MF_OPCUA_ADAPTER_ROUTE_MAP_URL=localhost:6379 MF_OPCUA_ADAPTER_ROUTE_MAP_PASS= MF_OPCUA_ADAPTER_ROUTE_MAP_DB=0 MF_OPCUA_ADAPTER_EVENT_CONSUMER=opcua +MF_OPCUA_ADAPTER_INSTANCE_ID= ### Cassandra Writer MF_CASSANDRA_WRITER_LOG_LEVEL=debug @@ -234,6 +246,7 @@ MF_CASSANDRA_READER_DB_CLUSTER=mainflux-cassandra MF_CASSANDRA_READER_DB_KEYSPACE=mainflux MF_CASSANDRA_READER_SERVER_CERT= MF_CASSANDRA_READER_SERVER_KEY= +MF_CASSANDRA_WRITER_INSANCE_ID= ### InfluxDB MF_INFLUXDB_PORT=8086 @@ -254,6 +267,7 @@ MF_INFLUX_WRITER_LOG_LEVEL=debug MF_INFLUX_WRITER_PORT=9006 MF_INFLUX_WRITER_BATCH_SIZE=5000 MF_INFLUX_WRITER_BATCH_TIMEOUT=5 +MF_INFLUX_WRITER_INSTANCE_ID= ### InfluxDB Reader MF_INFLUX_READER_LOG_LEVEL=debug @@ -261,12 +275,14 @@ MF_INFLUX_READER_PORT=9005 MF_INFLUX_READER_SERVER_KEY= MF_INFLUX_READER_SERVER_CERT= MF_INFLUXDB_DB=mainflux +MF_INFLUX_READER_INSTANCE_ID= ### MongoDB Writer MF_MONGO_WRITER_LOG_LEVEL=debug MF_MONGO_WRITER_PORT=9008 MF_MONGO_WRITER_DB=mainflux MF_MONGO_WRITER_DB_PORT=27017 +MF_MONGO_WRITER_INSTANCE_ID= ### MongoDB Reader MF_MONGO_READER_LOG_LEVEL=debug @@ -275,6 +291,7 @@ MF_MONGO_READER_DB=mainflux MF_MONGO_READER_DB_PORT=27017 MF_MONGO_READER_SERVER_CERT= MF_MONGO_READER_SERVER_KEY= +MF_MONGO_READER_INSTANCE_ID= ### Postgres Writer MF_POSTGRES_WRITER_LOG_LEVEL=debug @@ -287,6 +304,7 @@ MF_POSTGRES_WRITER_DB_SSL_MODE=disable MF_POSTGRES_WRITER_DB_SSL_CERT="" MF_POSTGRES_WRITER_DB_SSL_KEY="" MF_POSTGRES_WRITER_DB_SSL_ROOT_CERT="" +MF_POSTGRES_WRITER_INSTANCE_ID= ### Postgres Reader MF_POSTGRES_READER_LOG_LEVEL=debug @@ -301,6 +319,7 @@ MF_POSTGRES_READER_DB_SSL_MODE=disable MF_POSTGRES_READER_DB_SSL_CERT="" MF_POSTGRES_READER_DB_SSL_KEY="" MF_POSTGRES_READER_DB_SSL_ROOT_CERT="" +MF_POSTGRES_READER_INSTANCE_ID= ### Timescale Writer MF_TIMESCALE_WRITER_LOG_LEVEL=debug @@ -313,6 +332,7 @@ MF_TIMESCALE_WRITER_DB_SSL_MODE=disable MF_TIMESCALE_WRITER_DB_SSL_CERT="" MF_TIMESCALE_WRITER_DB_SSL_KEY="" MF_TIMESCALE_WRITER_DB_SSL_ROOT_CERT="" +MF_TIMESCALE_WRITER_INSTANCE_ID= ### Timescale Reader MF_TIMESCALE_READER_LOG_LEVEL=debug @@ -327,6 +347,7 @@ MF_TIMESCALE_READER_DB_SSL_MODE=disable MF_TIMESCALE_READER_DB_SSL_CERT="" MF_TIMESCALE_READER_DB_SSL_KEY="" MF_TIMESCALE_READER_DB_SSL_ROOT_CERT="" +MF_TIMESCALE_READER_INSTANCE_ID= ### Twins MF_TWINS_LOG_LEVEL=debug @@ -344,6 +365,7 @@ MF_TWINS_CHANNEL_ID= MF_TWINS_CACHE_URL=es-redis:6379 MF_TWINS_CACHE_PASS= MF_TWINS_CACHE_DB=0 +MF_TWINS_INSTANCE_ID= ### SMTP Notifier MF_SMTP_NOTIFIER_PORT=9015 @@ -354,6 +376,7 @@ MF_SMTP_NOTIFIER_DB_PASS=mainflux MF_SMTP_NOTIFIER_DB=subscriptions MF_SMTP_NOTIFIER_TEMPLATE=smtp-notifier.tmpl MF_SMTP_NOTIFIER_FROM_ADDR=from@example.com +MF_SMTP_NOTIFIER_INSTANCE_ID= ### SMPP Notifier MF_SMPP_NOTIFIER_PORT=9014 @@ -372,6 +395,7 @@ MF_SMPP_SRC_ADDR_TON=5 MF_SMPP_SRC_ADDR_NPI=0 MF_SMPP_DST_ADDR_TON=1 MF_SMPP_DST_ADDR_NPI=1 +MF_SMPP_NOTIFIER_INSTANCE_ID= ### GRAFANA and PROMETHEUS MF_PROMETHEUS_PORT=9090 diff --git a/docker/addons/bootstrap/docker-compose.yml b/docker/addons/bootstrap/docker-compose.yml index 0ff88e454e..ce507b801b 100644 --- a/docker/addons/bootstrap/docker-compose.yml +++ b/docker/addons/bootstrap/docker-compose.yml @@ -53,5 +53,6 @@ services: MF_AUTH_GRPC_TIMMEOUT: ${MF_USERS_GRPC_TIMEOUT} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_BOOTSTRAP_INSTANCE_ID: ${MF_BOOTSTRAP_INSTANCE_ID} networks: - docker_mainflux-base-net diff --git a/docker/addons/cassandra-reader/docker-compose.yml b/docker/addons/cassandra-reader/docker-compose.yml index 121cfede1a..d43dea162b 100644 --- a/docker/addons/cassandra-reader/docker-compose.yml +++ b/docker/addons/cassandra-reader/docker-compose.yml @@ -29,6 +29,7 @@ services: MF_AUTH_GRPC_URL: ${MF_USERS_GRPC_URL} MF_AUTH_GRPC_TIMEOUT : ${MF_USERS_GRPC_TIMEOUT} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_CASSANDRA_READER_INSTANCE_ID: ${MF_CASSANDRA_READER_INSTANCE_ID} ports: - ${MF_CASSANDRA_READER_PORT}:${MF_CASSANDRA_READER_PORT} networks: diff --git a/docker/addons/cassandra-writer/docker-compose.yml b/docker/addons/cassandra-writer/docker-compose.yml index 88888eb14e..ddd70b0299 100644 --- a/docker/addons/cassandra-writer/docker-compose.yml +++ b/docker/addons/cassandra-writer/docker-compose.yml @@ -42,6 +42,7 @@ services: MF_CASSANDRA_WRITER_DB_KEYSPACE: ${MF_CASSANDRA_WRITER_DB_KEYSPACE} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_CASSANDRA_WRITER_INSANCE_ID: ${MF_CASSANDRA_WRITER_INSANCE_ID} ports: - ${MF_CASSANDRA_WRITER_PORT}:${MF_CASSANDRA_WRITER_PORT} networks: diff --git a/docker/addons/certs/docker-compose.yml b/docker/addons/certs/docker-compose.yml index 37c04f73fe..e457e03364 100644 --- a/docker/addons/certs/docker-compose.yml +++ b/docker/addons/certs/docker-compose.yml @@ -70,6 +70,7 @@ services: MF_AUTH_GRPC_TIMEOUT: ${MF_USERS_GRPC_TIMEOUT} MF_CERTS_VAULT_HOST: ${MF_CERTS_VAULT_HOST} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_CERTS_INSTANCE_ID: ${MF_CERTS_INSTANCE_ID} volumes: - ../../ssl/certs/ca.key:/etc/ssl/certs/ca.key - ../../ssl/certs/ca.crt:/etc/ssl/certs/ca.crt diff --git a/docker/addons/influxdb-reader/docker-compose.yml b/docker/addons/influxdb-reader/docker-compose.yml index 8088d02e4a..b0e6a5da72 100644 --- a/docker/addons/influxdb-reader/docker-compose.yml +++ b/docker/addons/influxdb-reader/docker-compose.yml @@ -37,6 +37,7 @@ services: MF_AUTH_GRPC_URL: ${MF_USERS_GRPC_URL} MF_AUTH_GRPC_TIMEOUT : ${MF_USERS_GRPC_TIMEOUT} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_INFLUX_READER_INSTANCE_ID: ${MF_INFLUX_READER_INSTANCE_ID} ports: - ${MF_INFLUX_READER_PORT}:${MF_INFLUX_READER_PORT} networks: diff --git a/docker/addons/influxdb-writer/docker-compose.yml b/docker/addons/influxdb-writer/docker-compose.yml index 747eefc54a..de264e5ee3 100644 --- a/docker/addons/influxdb-writer/docker-compose.yml +++ b/docker/addons/influxdb-writer/docker-compose.yml @@ -56,6 +56,7 @@ services: MF_INFLUXDB_ADMIN_PASSWORD: ${MF_INFLUXDB_ADMIN_PASSWORD} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_INFLUX_WRITER_INSTANCE_ID: ${MF_INFLUX_WRITER_INSTANCE_ID} ports: - ${MF_INFLUX_WRITER_PORT}:${MF_INFLUX_WRITER_PORT} networks: diff --git a/docker/addons/lora-adapter/docker-compose.yml b/docker/addons/lora-adapter/docker-compose.yml index f003a91764..83b1e0924c 100644 --- a/docker/addons/lora-adapter/docker-compose.yml +++ b/docker/addons/lora-adapter/docker-compose.yml @@ -36,6 +36,7 @@ services: MF_LORA_ADAPTER_HTTP_PORT: ${MF_LORA_ADAPTER_HTTP_PORT} MF_BROKER_URL: ${MF_BROKER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_LORA_ADAPTER_INSTANCE_ID: ${MF_LORA_ADAPTER_INSTANCE_ID} ports: - ${MF_LORA_ADAPTER_HTTP_PORT}:${MF_LORA_ADAPTER_HTTP_PORT} networks: diff --git a/docker/addons/mongodb-reader/docker-compose.yml b/docker/addons/mongodb-reader/docker-compose.yml index 3de39eb8a8..db1ba3b9f2 100644 --- a/docker/addons/mongodb-reader/docker-compose.yml +++ b/docker/addons/mongodb-reader/docker-compose.yml @@ -31,6 +31,7 @@ services: MF_AUTH_GRPC_URL: ${MF_USERS_GRPC_URL} MF_AUTH_GRPC_TIMEOUT : ${MF_USERS_GRPC_TIMEOUT} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_MONGO_READER_INSTANCE_ID: ${MF_MONGO_READER_INSTANCE_ID} ports: - ${MF_MONGO_READER_PORT}:${MF_MONGO_READER_PORT} networks: diff --git a/docker/addons/mongodb-writer/docker-compose.yml b/docker/addons/mongodb-writer/docker-compose.yml index c67ac13b16..8347e9bec7 100644 --- a/docker/addons/mongodb-writer/docker-compose.yml +++ b/docker/addons/mongodb-writer/docker-compose.yml @@ -48,6 +48,7 @@ services: MF_MONGO_WRITER_DB_PORT: ${MF_MONGO_WRITER_DB_PORT} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_MONGO_WRITER_INSTANCE_ID: ${MF_MONGO_WRITER_INSTANCE_ID} ports: - ${MF_MONGO_WRITER_PORT}:${MF_MONGO_WRITER_PORT} networks: diff --git a/docker/addons/opcua-adapter/docker-compose.yml b/docker/addons/opcua-adapter/docker-compose.yml index faa8571f3b..8e2c37ba4b 100644 --- a/docker/addons/opcua-adapter/docker-compose.yml +++ b/docker/addons/opcua-adapter/docker-compose.yml @@ -46,6 +46,7 @@ services: MF_THINGS_ES_DB: ${MF_THINGS_ES_DB} MF_OPCUA_ADAPTER_EVENT_CONSUMER: ${MF_OPCUA_ADAPTER_EVENT_CONSUMER} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_OPCUA_ADAPTER_INSTANCE_ID: ${MF_OPCUA_ADAPTER_INSTANCE_ID} ports: - ${MF_OPCUA_ADAPTER_HTTP_PORT}:${MF_OPCUA_ADAPTER_HTTP_PORT} networks: diff --git a/docker/addons/postgres-reader/docker-compose.yml b/docker/addons/postgres-reader/docker-compose.yml index 19b682fe68..51ddf57ac7 100644 --- a/docker/addons/postgres-reader/docker-compose.yml +++ b/docker/addons/postgres-reader/docker-compose.yml @@ -37,6 +37,7 @@ services: MF_AUTH_GRPC_URL: ${MF_USERS_GRPC_URL} MF_AUTH_GRPC_TIMEOUT : ${MF_USERS_GRPC_TIMEOUT} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_POSTGRES_READER_INSTANCE_ID: ${MF_POSTGRES_READER_INSTANCE_ID} ports: - ${MF_POSTGRES_READER_PORT}:${MF_POSTGRES_READER_PORT} networks: diff --git a/docker/addons/postgres-writer/docker-compose.yml b/docker/addons/postgres-writer/docker-compose.yml index ea5e11eec9..888ef333c9 100644 --- a/docker/addons/postgres-writer/docker-compose.yml +++ b/docker/addons/postgres-writer/docker-compose.yml @@ -52,6 +52,7 @@ services: MF_POSTGRES_WRITER_DB_SSL_ROOT_CERT: ${MF_POSTGRES_WRITER_DB_SSL_ROOT_CERT} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_POSTGRES_WRITER_INSTANCE_ID: ${MF_POSTGRES_WRITER_INSTANCE_ID} ports: - ${MF_POSTGRES_WRITER_PORT}:${MF_POSTGRES_WRITER_PORT} networks: diff --git a/docker/addons/provision/docker-compose.yml b/docker/addons/provision/docker-compose.yml index 274cd7829a..b09df6dfcc 100644 --- a/docker/addons/provision/docker-compose.yml +++ b/docker/addons/provision/docker-compose.yml @@ -43,6 +43,7 @@ services: MF_PROVISION_CERTS_RSA_BITS: ${MF_PROVISION_CERTS_RSA_BITS} MF_PROVISION_CERTS_HOURS_VALID: ${MF_PROVISION_CERTS_HOURS_VALID} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_PROVISION_INSTANCE_ID: ${MF_PROVISION_INSTANCE_ID} volumes: - ./configs:/configs - ../../ssl/certs/ca.key:/etc/ssl/certs/ca.key diff --git a/docker/addons/smpp-notifier/docker-compose.yml b/docker/addons/smpp-notifier/docker-compose.yml index c962a3ee7c..205ca82660 100644 --- a/docker/addons/smpp-notifier/docker-compose.yml +++ b/docker/addons/smpp-notifier/docker-compose.yml @@ -57,6 +57,7 @@ services: MF_SMPP_DST_ADDR_TON: ${MF_SMPP_DST_ADDR_TON} MF_SMPP_DST_ADDR_NPI: ${MF_SMPP_DST_ADDR_NPI} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_SMPP_NOTIFIER_INSTANCE_ID: ${MF_SMPP_NOTIFIER_INSTANCE_ID} ports: - ${MF_SMPP_NOTIFIER_PORT}:${MF_SMPP_NOTIFIER_PORT} networks: diff --git a/docker/addons/smtp-notifier/docker-compose.yml b/docker/addons/smtp-notifier/docker-compose.yml index cd7971d8bc..6b0ba00365 100644 --- a/docker/addons/smtp-notifier/docker-compose.yml +++ b/docker/addons/smtp-notifier/docker-compose.yml @@ -57,6 +57,7 @@ services: MF_SMTP_NOTIFIER_TEMPLATE: ${MF_SMTP_NOTIFIER_TEMPLATE} MF_SMTP_NOTIFIER_FROM_ADDR: ${MF_SMTP_NOTIFIER_FROM_ADDR} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_SMTP_NOTIFIER_INSTANCE_ID: ${MF_SMTP_NOTIFIER_INSTANCE_ID} ports: - ${MF_SMTP_NOTIFIER_PORT}:${MF_SMTP_NOTIFIER_PORT} networks: diff --git a/docker/addons/timescale-reader/docker-compose.yml b/docker/addons/timescale-reader/docker-compose.yml index e65fdf3196..1ec044124d 100644 --- a/docker/addons/timescale-reader/docker-compose.yml +++ b/docker/addons/timescale-reader/docker-compose.yml @@ -37,6 +37,7 @@ services: MF_AUTH_GRPC_URL: ${MF_USERS_GRPC_URL} MF_AUTH_GRPC_TIMEOUT : ${MF_USERS_GRPC_TIMEOUT} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_TIMESCALE_READER_INSTANCE_ID: ${MF_TIMESCALE_READER_INSTANCE_ID} ports: - ${MF_TIMESCALE_READER_PORT}:${MF_TIMESCALE_READER_PORT} networks: diff --git a/docker/addons/timescale-writer/docker-compose.yml b/docker/addons/timescale-writer/docker-compose.yml index bbc23e5ad5..9d5a2f1e62 100644 --- a/docker/addons/timescale-writer/docker-compose.yml +++ b/docker/addons/timescale-writer/docker-compose.yml @@ -52,6 +52,7 @@ services: MF_TIMESCALE_WRITER_DB_SSL_ROOT_CERT: ${MF_TIMESCALE_WRITER_DB_SSL_ROOT_CERT} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_TIMESCALE_WRITER_INSTANCE_ID: ${MF_TIMESCALE_WRITER_INSTANCE_ID} ports: - ${MF_TIMESCALE_WRITER_PORT}:${MF_TIMESCALE_WRITER_PORT} networks: diff --git a/docker/addons/twins/docker-compose.yml b/docker/addons/twins/docker-compose.yml index 2f4f55a65c..785c2ab0dd 100644 --- a/docker/addons/twins/docker-compose.yml +++ b/docker/addons/twins/docker-compose.yml @@ -52,6 +52,7 @@ services: MF_THINGS_STANDALONE_ID: ${MF_THINGS_STANDALONE_ID} MF_THINGS_STANDALONE_TOKEN: ${MF_THINGS_STANDALONE_TOKEN} MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} + MF_TWINS_INSTANCE_ID: ${MF_TWINS_INSTANCE_ID} ports: - ${MF_TWINS_HTTP_PORT}:${MF_TWINS_HTTP_PORT} networks: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 01271784b8..50fba3dc77 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -216,6 +216,7 @@ services: MF_MQTT_ADAPTER_MQTT_TARGET_HEALTH_CHECK: http://vernemq:8888/health MF_MQTT_ADAPTER_WS_TARGET_HOST: vernemq MF_MQTT_ADAPTER_WS_TARGET_PORT: ${MF_MQTT_BROKER_WS_PORT} + MF_MQTT_ADAPTER_INSTANCE_ID: ${MF_MQTT_ADAPTER_INSTANCE_ID} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_THINGS_AUTH_GRPC_URL: ${MF_THINGS_AUTH_GRPC_URL} MF_THINGS_AUTH_GRPC_TIMEOUT: ${MF_THINGS_AUTH_GRPC_TIMEOUT} @@ -234,6 +235,7 @@ services: environment: MF_HTTP_ADAPTER_LOG_LEVEL: debug MF_HTTP_ADAPTER_PORT: ${MF_HTTP_ADAPTER_PORT} + MF_HTTP_ADAPTER_INSTANCE_ID: ${MF_HTTP_ADAPTER_INSTANCE_ID} MF_BROKER_URL: ${MF_BROKER_URL} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_THINGS_AUTH_GRPC_URL: ${MF_THINGS_AUTH_GRPC_URL} @@ -263,6 +265,7 @@ services: environment: MF_COAP_ADAPTER_LOG_LEVEL: ${MF_COAP_ADAPTER_LOG_LEVEL} MF_COAP_ADAPTER_PORT: ${MF_COAP_ADAPTER_PORT} + MF_COAP_ADAPTER_INSTANCE_ID: ${MF_COAP_ADAPTER_INSTANCE_ID} MF_BROKER_URL: ${MF_BROKER_URL} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_THINGS_AUTH_GRPC_URL: ${MF_THINGS_AUTH_GRPC_URL} @@ -284,6 +287,7 @@ services: environment: MF_WS_ADAPTER_LOG_LEVEL: ${MF_WS_ADAPTER_LOG_LEVEL} MF_WS_ADAPTER_PORT: ${MF_WS_ADAPTER_PORT} + MF_WS_ADAPTER_INSTANCE_ID: ${MF_WS_ADAPTER_INSTANCE_ID} MF_BROKER_URL: ${MF_BROKER_URL} MF_JAEGER_URL: ${MF_JAEGER_URL} MF_THINGS_AUTH_GRPC_URL: ${MF_THINGS_AUTH_GRPC_URL} diff --git a/health.go b/health.go index c91e5cf7bd..da50259c57 100644 --- a/health.go +++ b/health.go @@ -46,10 +46,13 @@ type HealthInfo struct { // BuildTime contains service build time. BuildTime string `json:"build_time"` + + // InstanceID contains the ID of the current service instance + InstanceID string `json:"instance_id"` } // Health exposes an HTTP handler for retrieving service health. -func Health(service string) http.HandlerFunc { +func Health(service, instanceID string) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Add(contentType, contentTypeJSON) if r.Method != http.MethodGet && r.Method != http.MethodHead { @@ -63,6 +66,7 @@ func Health(service string) http.HandlerFunc { Commit: Commit, Description: service + description, BuildTime: BuildTime, + InstanceID: instanceID, } w.WriteHeader(http.StatusOK) diff --git a/http/api/endpoint_test.go b/http/api/endpoint_test.go index 3cfff29502..36e7738aed 100644 --- a/http/api/endpoint_test.go +++ b/http/api/endpoint_test.go @@ -19,13 +19,15 @@ import ( "github.com/stretchr/testify/assert" ) +const instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" + func newService(cc policies.ThingsServiceClient) adapter.Service { pub := mocks.NewPublisher() return adapter.New(pub, cc) } func newHTTPServer(svc adapter.Service) *httptest.Server { - mux := api.MakeHandler(svc) + mux := api.MakeHandler(svc, instanceID) return httptest.NewServer(mux) } diff --git a/http/api/transport.go b/http/api/transport.go index d73d49858c..c5b814a0db 100644 --- a/http/api/transport.go +++ b/http/api/transport.go @@ -41,7 +41,7 @@ var ( var channelPartRegExp = regexp.MustCompile(`^/channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc adapter.Service) http.Handler { +func MakeHandler(svc adapter.Service, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(encodeError), } @@ -61,7 +61,7 @@ func MakeHandler(svc adapter.Service) http.Handler { opts..., )) - r.GetFunc("/health", mainflux.Health("http")) + r.GetFunc("/health", mainflux.Health("http", instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/internal/clients/jaeger/provider.go b/internal/clients/jaeger/provider.go index 58fe1aff01..42ff6c0418 100644 --- a/internal/clients/jaeger/provider.go +++ b/internal/clients/jaeger/provider.go @@ -22,7 +22,7 @@ var ( ) // NewProvider initializes Jaeger TraceProvider. -func NewProvider(svcName, url string) (*tracesdk.TracerProvider, error) { +func NewProvider(svcName, url, instanceID string) (*tracesdk.TracerProvider, error) { if url == "" { return nil, errNoURL } @@ -36,7 +36,10 @@ func NewProvider(svcName, url string) (*tracesdk.TracerProvider, error) { return nil, err } - attributes := []attribute.KeyValue{semconv.ServiceNameKey.String(svcName)} + attributes := []attribute.KeyValue{ + semconv.ServiceNameKey.String(svcName), + attribute.String("InstanceID", instanceID), + } hostAttr, err := resource.New(context.TODO(), resource.WithHost(), resource.WithOSDescription(), resource.WithContainer()) if err != nil { diff --git a/lora/api/api.go b/lora/api/api.go index c6082677df..620d1d50a6 100644 --- a/lora/api/api.go +++ b/lora/api/api.go @@ -12,9 +12,9 @@ import ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler() http.Handler { +func MakeHandler(instanceID string) http.Handler { r := bone.New() - r.GetFunc("/health", mainflux.Health("lora-adapter")) + r.GetFunc("/health", mainflux.Health("lora-adapter", instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/opcua/api/transport.go b/opcua/api/transport.go index bfa3b6a2a3..50dbcf1f3d 100644 --- a/opcua/api/transport.go +++ b/opcua/api/transport.go @@ -28,7 +28,7 @@ const ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc opcua.Service, logger mflog.Logger) http.Handler { +func MakeHandler(svc opcua.Service, logger mflog.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), } @@ -42,7 +42,7 @@ func MakeHandler(svc opcua.Service, logger mflog.Logger) http.Handler { opts..., )) - r.GetFunc("/health", mainflux.Health("opcua-adapter")) + r.GetFunc("/health", mainflux.Health("opcua-adapter", instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/pkg/sdk/go/certs_test.go b/pkg/sdk/go/certs_test.go index 498641d68e..6a3a462945 100644 --- a/pkg/sdk/go/certs_test.go +++ b/pkg/sdk/go/certs_test.go @@ -29,6 +29,8 @@ import ( upolicies "github.com/mainflux/mainflux/users/policies" ) +const instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" + var ( thingsNum = 1 thingKey = "thingKey" @@ -88,7 +90,7 @@ func newCertService() (certs.Service, error) { func newCertServer(svc certs.Service) *httptest.Server { logger := logger.NewMock() - mux := httpapi.MakeHandler(svc, logger) + mux := httpapi.MakeHandler(svc, logger, instanceID) return httptest.NewServer(mux) } diff --git a/pkg/sdk/go/consumers_test.go b/pkg/sdk/go/consumers_test.go index c0a549bda9..2f9d5097fc 100644 --- a/pkg/sdk/go/consumers_test.go +++ b/pkg/sdk/go/consumers_test.go @@ -41,14 +41,14 @@ func newSubscriptionService() notifiers.Service { notifier := mocks.NewNotifier() idp := uuid.NewMock() from := "exampleFrom" - + return notifiers.New(auth, repo, idp, notifier, from) } func newSubscriptionServer(svc notifiers.Service) *httptest.Server { logger := logger.NewMock() - mux := httpapi.MakeHandler(svc, logger) - + mux := httpapi.MakeHandler(svc, logger, instanceID) + return httptest.NewServer(mux) } diff --git a/pkg/sdk/go/message_test.go b/pkg/sdk/go/message_test.go index 10dffbbd11..3cad9c6207 100644 --- a/pkg/sdk/go/message_test.go +++ b/pkg/sdk/go/message_test.go @@ -28,7 +28,7 @@ func newMessageService(cc policies.ThingsServiceClient) adapter.Service { } func newMessageServer(svc adapter.Service) *httptest.Server { - mux := api.MakeHandler(svc) + mux := api.MakeHandler(svc, instanceID) return httptest.NewServer(mux) } diff --git a/pkg/sdk/go/things_test.go b/pkg/sdk/go/things_test.go index beefff8d2d..aa40919e12 100644 --- a/pkg/sdk/go/things_test.go +++ b/pkg/sdk/go/things_test.go @@ -37,7 +37,7 @@ var ( func newThingsServer(svc clients.Service, psvc policies.Service) *httptest.Server { logger := mflog.NewMock() mux := bone.New() - api.MakeHandler(svc, mux, logger) + api.MakeHandler(svc, mux, logger, instanceID) papi.MakeHandler(svc, psvc, mux, logger) return httptest.NewServer(mux) } diff --git a/pkg/sdk/go/users_test.go b/pkg/sdk/go/users_test.go index 186b08e4ad..aa51d6287f 100644 --- a/pkg/sdk/go/users_test.go +++ b/pkg/sdk/go/users_test.go @@ -30,7 +30,7 @@ var id = generateUUID(&testing.T{}) func newClientServer(svc clients.Service) *httptest.Server { logger := mflog.NewMock() mux := bone.New() - api.MakeHandler(svc, mux, logger) + api.MakeHandler(svc, mux, logger, instanceID) return httptest.NewServer(mux) } diff --git a/provision/api/transport.go b/provision/api/transport.go index 97a3b3a047..f358808509 100644 --- a/provision/api/transport.go +++ b/provision/api/transport.go @@ -20,7 +20,7 @@ const ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc provision.Service, logger logger.Logger) http.Handler { +func MakeHandler(svc provision.Service, logger logger.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), @@ -43,7 +43,7 @@ func MakeHandler(svc provision.Service, logger logger.Logger) http.Handler { )) r.Handle("/metrics", promhttp.Handler()) - r.GetFunc("/health", mainflux.Health("provision")) + r.GetFunc("/health", mainflux.Health("provision", instanceID)) return r } diff --git a/readers/api/endpoint_test.go b/readers/api/endpoint_test.go index f166282a7f..d66b95b78b 100644 --- a/readers/api/endpoint_test.go +++ b/readers/api/endpoint_test.go @@ -36,6 +36,7 @@ const ( mqttProt = "mqtt" httpProt = "http" msgName = "temperature" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var ( @@ -49,7 +50,7 @@ var ( ) func newServer(repo readers.MessageRepository, tc tpolicies.ThingsServiceClient, ac upolicies.AuthServiceClient) *httptest.Server { - mux := api.MakeHandler(repo, tc, ac, svcName) + mux := api.MakeHandler(repo, tc, ac, svcName, instanceID) return httptest.NewServer(mux) } diff --git a/readers/api/transport.go b/readers/api/transport.go index 43f5ba93d5..599ddfd1ee 100644 --- a/readers/api/transport.go +++ b/readers/api/transport.go @@ -48,7 +48,7 @@ var ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc readers.MessageRepository, tc tpolicies.ThingsServiceClient, ac upolicies.AuthServiceClient, svcName string) http.Handler { +func MakeHandler(svc readers.MessageRepository, tc tpolicies.ThingsServiceClient, ac upolicies.AuthServiceClient, svcName, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(encodeError), @@ -62,7 +62,7 @@ func MakeHandler(svc readers.MessageRepository, tc tpolicies.ThingsServiceClient opts..., )) - mux.GetFunc("/health", mainflux.Health(svcName)) + mux.GetFunc("/health", mainflux.Health(svcName, instanceID)) mux.Handle("/metrics", promhttp.Handler()) return mux diff --git a/things/clients/api/transport.go b/things/clients/api/transport.go index 76a3143c74..87f61a0e52 100644 --- a/things/clients/api/transport.go +++ b/things/clients/api/transport.go @@ -23,7 +23,7 @@ import ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger) http.Handler { +func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)), } @@ -105,7 +105,7 @@ func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger) http.H opts..., )) - mux.GetFunc("/health", mainflux.Health("things")) + mux.GetFunc("/health", mainflux.Health("things", instanceID)) mux.Handle("/metrics", promhttp.Handler()) return mux } diff --git a/twins/api/http/endpoint_twins_test.go b/twins/api/http/endpoint_twins_test.go index fbd673951e..0ccaf5b16b 100644 --- a/twins/api/http/endpoint_twins_test.go +++ b/twins/api/http/endpoint_twins_test.go @@ -31,6 +31,7 @@ const ( wrongValue = "wrong_value" wrongID = 0 maxNameSize = 1024 + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var invalidName = strings.Repeat("m", maxNameSize+1) @@ -84,7 +85,7 @@ func (tr testRequest) make() (*http.Response, error) { func newServer(svc twins.Service) *httptest.Server { logger := logger.NewMock() - mux := httpapi.MakeHandler(svc, logger) + mux := httpapi.MakeHandler(svc, logger, instanceID) return httptest.NewServer(mux) } diff --git a/twins/api/http/transport.go b/twins/api/http/transport.go index 55df78b625..870a438f1c 100644 --- a/twins/api/http/transport.go +++ b/twins/api/http/transport.go @@ -31,7 +31,7 @@ const ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc twins.Service, logger logger.Logger) http.Handler { +func MakeHandler(svc twins.Service, logger logger.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)), } @@ -80,7 +80,7 @@ func MakeHandler(svc twins.Service, logger logger.Logger) http.Handler { opts..., )) - r.GetFunc("/health", mainflux.Health("twins")) + r.GetFunc("/health", mainflux.Health("twins", instanceID)) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/users/clients/api/transport.go b/users/clients/api/transport.go index a4b4396a8e..847fd86314 100644 --- a/users/clients/api/transport.go +++ b/users/clients/api/transport.go @@ -23,7 +23,7 @@ import ( ) // MakeHandler returns a HTTP handler for API endpoints. -func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger) http.Handler { +func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger, instanceID string) http.Handler { opts := []kithttp.ServerOption{ kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)), } @@ -140,7 +140,7 @@ func MakeHandler(svc clients.Service, mux *bone.Mux, logger mflog.Logger) http.H opts..., )) - mux.GetFunc("/health", mainflux.Health("users")) + mux.GetFunc("/health", mainflux.Health("users", instanceID)) mux.Handle("/metrics", promhttp.Handler()) return mux diff --git a/ws/api/endpoint_test.go b/ws/api/endpoint_test.go index 112331f02d..f51125e720 100644 --- a/ws/api/endpoint_test.go +++ b/ws/api/endpoint_test.go @@ -23,10 +23,11 @@ import ( ) const ( - chanID = "30315311-56ba-484d-b500-c1e08305511f" - id = "1" - thingKey = "c02ff576-ccd5-40f6-ba5f-c85377aad529" - protocol = "ws" + chanID = "30315311-56ba-484d-b500-c1e08305511f" + id = "1" + thingKey = "c02ff576-ccd5-40f6-ba5f-c85377aad529" + protocol = "ws" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" ) var msg = []byte(`[{"n":"current","t":-1,"v":1.6}]`) @@ -38,7 +39,7 @@ func newService(cc policies.ThingsServiceClient) (ws.Service, mocks.MockPubSub) func newHTTPServer(svc ws.Service) *httptest.Server { logger := mflog.NewMock() - mux := api.MakeHandler(svc, logger) + mux := api.MakeHandler(svc, logger, instanceID) return httptest.NewServer(mux) } diff --git a/ws/api/transport.go b/ws/api/transport.go index 7c7c88839f..3fa963e9f0 100644 --- a/ws/api/transport.go +++ b/ws/api/transport.go @@ -35,13 +35,13 @@ var ( ) // MakeHandler returns http handler with handshake endpoint. -func MakeHandler(svc ws.Service, l mflog.Logger) http.Handler { +func MakeHandler(svc ws.Service, l mflog.Logger, instanceID string) http.Handler { logger = l mux := bone.New() mux.GetFunc("/channels/:chanID/messages", handshake(svc)) mux.GetFunc("/channels/:chanID/messages/*", handshake(svc)) - mux.GetFunc("/version", mainflux.Health(protocol)) + mux.GetFunc("/version", mainflux.Health(protocol, instanceID)) mux.Handle("/metrics", promhttp.Handler()) return mux