Skip to content

Commit

Permalink
Merge pull request #1 from VitalyGushin/main
Browse files Browse the repository at this point in the history
NSM Dashboard initial impl.
  • Loading branch information
denis-tingaikin authored Dec 22, 2023
2 parents 1285ddf + eef2e3b commit b5e41ee
Show file tree
Hide file tree
Showing 10 changed files with 938 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

.idea/
junit/
nohup.out
.DS_Store
.vscode
4 changes: 2 additions & 2 deletions .license/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This folder contains the copyright templates for source files of NSM project.

Below is an example of valid copyright header for `.go` files:
```
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2020 Pragmagic Inc. and/or its affiliates.
//
// Copyright (c) 2020 Cisco and/or its affiliates.
//
Expand All @@ -24,7 +24,7 @@ Below is an example of valid copyright header for `.go` files:
Note you can use your company name instead of `Cisco and/or its affiliates`.
Also, source code files can have multi copyright holders, for example:
```
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2020 Pragmagic Inc. and/or its affiliates.
//
// Copyright (c) 2020 Cisco and/or its affiliates.
//
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ CMD dlv -l :40000 --headless=true --api-version=2 test -test.v ./...

FROM alpine as runtime
COPY --from=build /bin/app /bin/app

# Expose port for REST server
EXPOSE 3001

CMD /bin/app
90 changes: 23 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,31 @@
# Build
# Network Service Mesh Dashboard Backend

## Build cmd binary locally
NSM dashboard backend part provides graphical model data for [the UI part](https://github.com/networkservicemesh/cmd-dashboard-ui) through the REST API

You can build the locally by executing
Written in [Go](https://go.dev/)

```bash
go build ./...
```
The entire NSM dashboard deployment info see [here](https://github.com/networkservicemesh/deployments-k8s/tree/main/examples/observability/dashboard)

## Build Docker container
## Dev/debug

You can build the docker container by running:
### To run dashboard backend in the cluster:

```bash
docker build .
```
1. `git clone [email protected]:networkservicemesh/deployments-k8s.git`
2. `cd deployments-k8s/examples/observability/dashboard`
3. Edit `dashboard-pod.yaml` and remove the `dashboard-ui` container
4. `kubectl apply -f dashboard-pod.yaml`
5. `kubectl apply -f dashboard-backend-service.yaml`
6. `kubectl port-forward -n nsm-system service/dashboard-backend 3001:3001`
7. Check `http://localhost:3001/nodes` in the browser

# Testing
### To run dashboard backend with a custom container ([Docker](https://docs.docker.com/engine/install/) have to be installed) in the cluster:

## Testing Docker container

Testing is run via a Docker container. To run testing run:

```bash
docker run --privileged --rm $(docker build -q --target test .)
```

# Debugging

## Debugging the tests
If you wish to debug the test code itself, that can be acheived by running:

```bash
docker run --privileged --rm -p 40000:40000 $(docker build -q --target debug .)
```

This will result in the tests running under dlv. Connecting your debugger to localhost:40000 will allow you to debug.

```bash
-p 40000:40000
```
forwards port 40000 in the container to localhost:40000 where you can attach with your debugger.

```bash
--target debug
```

Runs the debug target, which is just like the test target, but starts tests with dlv listening on port 40000 inside the container.

## Debugging the cmd

When you run 'cmd' you will see an early line of output that tells you:

```Setting env variable DLV_LISTEN_FORWARDER to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.```

If you follow those instructions when running the Docker container:
```bash
docker run --privileged -e DLV_LISTEN_FORWARDER=:50000 -p 50000:50000 --rm $(docker build -q --target test .)
```

```-e DLV_LISTEN_FORWARDER=:50000``` tells docker to set the environment variable DLV_LISTEN_FORWARDER to :50000 telling
dlv to listen on port 50000.

```-p 50000:50000``` tells docker to forward port 50000 in the container to port 50000 in the host. From there, you can
just connect dlv using your favorite IDE and debug cmd.

## Debugging the tests and the cmd

```bash
docker run --privileged -e DLV_LISTEN_FORWARDER=:50000 -p 40000:40000 -p 50000:50000 --rm $(docker build -q --target debug .)
```

Please note, the tests **start** the cmd, so until you connect to port 40000 with your debugger and walk the tests
through to the point of running cmd, you will not be able to attach a debugger on port 50000 to the cmd.
1. `git clone [email protected]:networkservicemesh/cmd-dashboard-backend.git`
2. `cd cmd-dashboard-backend`
3. Make the necessary code changes
4. Create a [Dockerhub](https://hub.docker.com/) repository
5. `docker build -t your-dh-namespace/dh-repo-name .`
6. `docker push your-dh-namespace/dh-repo-name`
7. `cd deployments-k8s/examples/observability/dashboard`
8. Edit `dashboard-pod.yaml` and set your Dockerhub image address for the `dashboard-backend` container
9. Execute the steps 3-7 from the previous section
74 changes: 73 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
module github.com/networkservicemesh/cmd-template
module github.com/networkservicemesh/cmd-dashboard-backend

go 1.20

require (
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29
github.com/gin-gonic/gin v1.9.1
github.com/networkservicemesh/api v1.11.0
github.com/networkservicemesh/sdk v1.11.0
github.com/sirupsen/logrus v1.9.0
github.com/spiffe/go-spiffe/v2 v2.0.0
google.golang.org/grpc v1.59.0
)

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/zeebo/errs v1.2.2 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect
go.opentelemetry.io/otel v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0-rc.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.42.0-rc.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.42.0-rc.1 // indirect
go.opentelemetry.io/otel/metric v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/sdk v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/sdk/metric v1.19.0-rc.1 // indirect
go.opentelemetry.io/otel/trace v1.19.0-rc.1 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b5e41ee

Please sign in to comment.