Skip to content

Commit

Permalink
NSM Dashboard initial impl.
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guschin <[email protected]>
  • Loading branch information
Vitaliy Guschin committed Dec 20, 2023
1 parent 1285ddf commit c1c1930
Show file tree
Hide file tree
Showing 7 changed files with 801 additions and 70 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: 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 providing 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
53 changes: 52 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
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/gorilla/mux v1.8.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/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.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/matttproud/golang_protobuf_extensions v1.0.4 // 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/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/crypto v0.16.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
)
Loading

0 comments on commit c1c1930

Please sign in to comment.