Rename mfxkit to cocos

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
Darko Draskovic
2023-03-14 15:47:26 +01:00
parent 22c743c4dd
commit b7a1fbb2fa
9 changed files with 65 additions and 65 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ Copy `mfxkit` directory to the `mainflux` root directory, e.g. `~/go/src/github.
In `mainflux` root directory run
```
MF_MFXKIT_LOG_LEVEL=info go run cmd/mfxkit/main.go
CC_MFXKIT_LOG_LEVEL=info go run cmd/mfxkit/main.go
```
You should get a message similar to this one
@@ -38,7 +38,7 @@ Content-Length: 30
To change the secret or the port, prefix the `go run` command with environment variable assignments, e.g.
```
MF_MFXKIT_LOG_LEVEL=info MF_MFXKIT_SECRET=secret2 MF_MFXKIT_HTTP_PORT=9022 go run cmd/mfxkit/main.go
CC_MFXKIT_LOG_LEVEL=info CC_MFXKIT_SECRET=secret2 CC_MFXKIT_HTTP_PORT=9022 go run cmd/mfxkit/main.go
```
To see the change in action, run
+19 -19
View File
@@ -1,6 +1,6 @@
# Mfxkit
# Agent
Mfxkit service provides a barebones HTTP API and Service interface implementation for development of a core Mainflux service.
Agent service provides a barebones HTTP API and Service interface implementation for development of a core Mainflux service.
## Configuration
@@ -8,12 +8,12 @@ The service is configured using the environment variables from the following tab
| Variable | Description | Default |
|-----------------------|---------------------------------------------------------|---------|
| MF_MFXKIT_LOG_LEVEL | Log level for mfxkit service (debug, info, warn, error) | error |
| MF_MFXKIT_HTTP_PORT | Mfxkit service HTTP port | 9021 |
| MF_MFXKIT_SERVER_CERT | Path to server certificate in pem format | |
| MF_MFXKIT_SERVER_KEY | Path to server key in pem format | |
| MF_JAEGER_URL | Jaeger server URL | |
| MF_MFXKIT_SECRET | Mfxkit service secret | secret |
| CC_AGENT_LOG_LEVEL | Log level for agent service (debug, info, warn, error) | error |
| CC_AGENT_HTTP_PORT | Agent service HTTP port | 9021 |
| CC_AGENT_SERVER_CERT | Path to server certificate in pem format | |
| CC_AGENT_SERVER_KEY | Path to server key in pem format | |
| CC_JAEGER_URL | Jaeger server URL | |
| CC_AGENT_SECRET | Agent service secret | secret |
## Deployment
@@ -22,18 +22,18 @@ The service is distributed as a Docker container. The following snippet provides
```yaml
version: "3"
services:
mfxkit:
image: mainflux/mfxkit:[version]
agent:
image: mainflux/agent:[version]
container_name: [instance name]
ports:
- [host machine port]:[configured HTTP port]
environment:
MF_MFXKIT_LOG_LEVEL: [Kit log level]
MF_MFXKIT_HTTP_PORT: [Service HTTP port]
MF_MFXKIT_SERVER_CERT: [String path to server cert in pem format]
MF_MFXKIT_SERVER_KEY: [String path to server key in pem format]
MF_MFXKIT_SECRET: [Mfxkit service secret]
MF_JAEGER_URL: [Jaeger server URL]
CC_AGENT_LOG_LEVEL: [Kit log level]
CC_AGENT_HTTP_PORT: [Service HTTP port]
CC_AGENT_SERVER_CERT: [String path to server cert in pem format]
CC_AGENT_SERVER_KEY: [String path to server key in pem format]
CC_AGENT_SECRET: [Agent service secret]
CC_JAEGER_URL: [Jaeger server URL]
```
To start the service outside of the container, execute the following shell script:
@@ -44,14 +44,14 @@ go get github.com/mainflux/mainflux
cd $GOPATH/src/github.com/mainflux/mainflux
# compile the mfxkit
make mfxkit
# compile the agent
make agent
# copy binary to bin
make install
# set the environment variables and run the service
MF_MFXKIT_LOG_LEVEL=[Kit log level] MF_MFXKIT_HTTP_PORT=[Service HTTP port] MF_MFXKIT_SERVER_CERT: [String path to server cert in pem format] MF_MFXKIT_SERVER_KEY: [String path to server key in pem format] MF_JAEGER_URL=[Jaeger server URL] MF_MFXKIT_SECRET: [Mfxkit service secret] $GOBIN/mainflux-kit
CC_AGENT_LOG_LEVEL=[Kit log level] CC_AGENT_HTTP_PORT=[Service HTTP port] CC_AGENT_SERVER_CERT: [String path to server cert in pem format] CC_AGENT_SERVER_KEY: [String path to server key in pem format] CC_JAEGER_URL=[Jaeger server URL] CC_AGENT_SECRET: [Agent service secret] $GOBIN/mainflux-kit
```
## Usage
+4 -4
View File
@@ -18,7 +18,7 @@ import (
"github.com/mainflux/mainflux"
opentracing "github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus/promhttp"
cckit "github.com/ultravioletrs/cocosvm/agent"
"github.com/ultravioletrs/cocosvm/agent"
)
const (
@@ -31,7 +31,7 @@ var (
)
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(tracer opentracing.Tracer, svc cckit.Service) http.Handler {
func MakeHandler(tracer opentracing.Tracer, svc agent.Service) http.Handler {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(encodeError),
}
@@ -86,9 +86,9 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
w.Header().Set("Content-Type", contentType)
switch err {
case cckit.ErrMalformedEntity:
case agent.ErrMalformedEntity:
w.WriteHeader(http.StatusBadRequest)
case cckit.ErrUnauthorizedAccess:
case agent.ErrUnauthorizedAccess:
w.WriteHeader(http.StatusForbidden)
case errUnsupportedContentType:
w.WriteHeader(http.StatusUnsupportedMediaType)
+1 -1
View File
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// Package things contains the domain concept definitions needed to support
// Mainflux mfxkit service functionality.
// Mainflux agent service functionality.
package agent
+5 -5
View File
@@ -24,20 +24,20 @@ type Service interface {
Ping(string) (string, error)
}
type mfxkitService struct {
type agentService struct {
secret string
}
var _ Service = (*mfxkitService)(nil)
var _ Service = (*agentService)(nil)
// New instantiates the mfxkit service implementation.
// New instantiates the agent service implementation.
func New(secret string) Service {
return &mfxkitService{
return &agentService{
secret: secret,
}
}
func (ks *mfxkitService) Ping(secret string) (string, error) {
func (ks *agentService) Ping(secret string) (string, error) {
if ks.secret != secret {
return "", ErrUnauthorizedAccess
}
+14 -14
View File
@@ -37,12 +37,12 @@ const (
defServerKey = ""
defSecret = "secret"
envLogLevel = "MF_MFXKIT_LOG_LEVEL"
envHTTPPort = "MF_MFXKIT_HTTP_PORT"
envServerCert = "MF_MFXKIT_SERVER_CERT"
envServerKey = "MF_MFXKIT_SERVER_KEY"
envSecret = "MF_MFXKIT_SECRET"
envJaegerURL = "MF_JAEGER_URL"
envLogLevel = "CC_AGENT_LOG_LEVEL"
envHTTPPort = "CC_AGENT_HTTP_PORT"
envServerCert = "CC_AGENT_SERVER_CERT"
envServerKey = "CC_AGENT_SERVER_KEY"
envSecret = "CC_AGENT_SECRET"
envJaegerURL = "CC_JAEGER_URL"
)
type config struct {
@@ -64,13 +64,13 @@ func main() {
log.Fatalf(err.Error())
}
mfxkitTracer, mfxkitCloser := initJaeger("mfxkit", cfg.jaegerURL, logger)
defer mfxkitCloser.Close()
agentTracer, agentCloser := initJaeger("agent", cfg.jaegerURL, logger)
defer agentCloser.Close()
svc := newService(cfg.secret, logger)
errs := make(chan error, 2)
go startHTTPServer(agenthttpapi.MakeHandler(mfxkitTracer, svc), cfg.httpPort, cfg, logger, errs)
go startHTTPServer(agenthttpapi.MakeHandler(agentTracer, svc), cfg.httpPort, cfg, logger, errs)
go func() {
c := make(chan os.Signal)
@@ -79,7 +79,7 @@ func main() {
}()
err = <-errs
logger.Error(fmt.Sprintf("Mfxkit service terminated: %s", err))
logger.Error(fmt.Sprintf("Agent service terminated: %s", err))
}
func loadConfig() config {
@@ -124,13 +124,13 @@ func newService(secret string, logger logger.Logger) agent.Service {
svc = api.MetricsMiddleware(
svc,
kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "mfxkit",
Namespace: "agent",
Subsystem: "api",
Name: "request_count",
Help: "Number of requests received.",
}, []string{"method"}),
kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: "mfxkit",
Namespace: "agent",
Subsystem: "api",
Name: "request_latency_microseconds",
Help: "Total duration of requests in microseconds.",
@@ -143,11 +143,11 @@ func newService(secret string, logger logger.Logger) agent.Service {
func startHTTPServer(handler http.Handler, port string, cfg config, logger logger.Logger, errs chan error) {
p := fmt.Sprintf(":%s", port)
if cfg.serverCert != "" || cfg.serverKey != "" {
logger.Info(fmt.Sprintf("Mfxkit service started using https on port %s with cert %s key %s",
logger.Info(fmt.Sprintf("Agent service started using https on port %s with cert %s key %s",
port, cfg.serverCert, cfg.serverKey))
errs <- http.ListenAndServeTLS(p, cfg.serverCert, cfg.serverKey, handler)
return
}
logger.Info(fmt.Sprintf("Mfxkit service started using http on port %s", cfg.httpPort))
logger.Info(fmt.Sprintf("Agent service started using http on port %s", cfg.httpPort))
errs <- http.ListenAndServe(p, handler)
}
+7 -7
View File
@@ -1,9 +1,9 @@
# Docker: Environment variables in Compose
## Mfxkit
MF_MFXKIT_LOG_LEVEL=debug
MF_MFXKIT_HTTP_PORT=9021
MF_MFXKIT_SECRET=secret
MF_MFXKIT_SERVER_CERT=""
MF_MFXKIT_SERVER_KEY=""
MF_JAEGER_URL="jaeger:6831"
## Agent
CC_AGENT_LOG_LEVEL=debug
CC_AGENT_HTTP_PORT=9021
CC_AGENT_SECRET=secret
CC_AGENT_SERVER_CERT=""
CC_AGENT_SERVER_KEY=""
CC_JAEGER_URL="jaeger:6831"
+3 -3
View File
@@ -1,10 +1,10 @@
FROM golang:1.16-alpine AS builder
WORKDIR /go/src/github.com/mainflux/mfxkit
WORKDIR /go/src/github.com/mainflux/agent
COPY . .
RUN CGO_ENABLED=0 GOARCH=amd64 \
go build -mod=vendor -ldflags "-s -w" -o build/mainflux-mfxkit cmd/mfxkit/main.go \
&& mv build/mainflux-mfxkit /exe
go build -mod=vendor -ldflags "-s -w" -o build/mainflux-agent cmd/agent/main.go \
&& mv build/mainflux-agent /exe
FROM scratch
COPY --from=builder /exe /
+10 -10
View File
@@ -13,18 +13,18 @@ networks:
external: true
services:
mfxkit:
image: mainflux/mfxkit:latest
container_name: mainflux-mfxkit
agent:
image: mainflux/agent:latest
container_name: mainflux-agent
restart: on-failure
environment:
MF_MFXKIT_LOG_LEVEL: ${MF_MFXKIT_LOG_LEVEL}
MF_MFXKIT_HTTP_PORT: ${MF_MFXKIT_HTTP_PORT}
MF_MFXKIT_SERVER_CERT: ${MF_MFXKIT_SERVER_CERT}
MF_MFXKIT_SERVER_KEY: ${MF_MFXKIT_SERVER_KEY}
MF_JAEGER_URL: ${MF_JAEGER_URL}
MF_MFXKIT_SECRET: ${MF_MFXKIT_SECRET}
CC_AGENT_LOG_LEVEL: ${CC_AGENT_LOG_LEVEL}
CC_AGENT_HTTP_PORT: ${CC_AGENT_HTTP_PORT}
CC_AGENT_SERVER_CERT: ${CC_AGENT_SERVER_CERT}
CC_AGENT_SERVER_KEY: ${CC_AGENT_SERVER_KEY}
CC_JAEGER_URL: ${CC_JAEGER_URL}
CC_AGENT_SECRET: ${CC_AGENT_SECRET}
ports:
- ${MF_MFXKIT_HTTP_PORT}:${MF_MFXKIT_HTTP_PORT}
- ${CC_AGENT_HTTP_PORT}:${CC_AGENT_HTTP_PORT}
networks:
- docker_mainflux-base-net