Skip to content

Commit

Permalink
Rename krill to device simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanperry1 committed Nov 15, 2023
1 parent 446e214 commit d6e73fc
Show file tree
Hide file tree
Showing 130 changed files with 358 additions and 351 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: callout_build
name: device-simulator_build

on:
workflow_dispatch:
push:
tags:
- 'v*.*.*-callout'
- 'v*.*.*-device-simulator'

jobs:
call-docker-build:
uses: ./.github/workflows/docker_build.yml
with:
registry: makocr.azurecr.io/callout
file: samples/callout/Dockerfile
registry: makocr.azurecr.io/device-simulator
file: samples/device-simulator/Dockerfile
context: .
secrets:
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: krill_test
name: device-simulator_test

on:
workflow_dispatch:
push:
paths:
- samples/callout/**
- samples/device-simulator/**

jobs:
call-mage-test:
uses: ./.github/workflows/mage_tests.yml
with:
workdir: samples/callout/
workdir: samples/device-simulator/
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: krill_build
name: http_grpc_callout_build

on:
workflow_dispatch:
push:
tags:
- 'v*.*.*-krill'
- 'v*.*.*-http-grpc-callout'

jobs:
call-docker-build:
uses: ./.github/workflows/docker_build.yml
with:
registry: makocr.azurecr.io/krill
file: samples/krill/Dockerfile
registry: makocr.azurecr.io/http-grpc-callout
file: samples/http-grpc-callout/Dockerfile
context: .
secrets:
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: krill_test
name: http_grpc_callout_test

on:
workflow_dispatch:
push:
paths:
- samples/krill/**
- samples/http-grpc-callout/**

jobs:
call-mage-test:
uses: ./.github/workflows/mage_tests.yml
with:
workdir: samples/krill/
workdir: samples/http-grpc-callout/
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ bin
dns.yaml
/src/**/config.json
/bin
/krill
/listen
/mqtt
/manager
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ FROM mcr.microsoft.com/oss/go/microsoft/golang:1.21-cbl-mariner2.0 AS build

COPY ./lib /workdir/lib

COPY ./samples/krill /workdir/samples/krill
COPY ./samples/device-simulator /workdir/samples/device-simulator

WORKDIR /workdir/samples/krill
WORKDIR /workdir/samples/device-simulator

RUN go mod download

RUN go install github.com/magefile/mage@latest

RUN mage ci

RUN go build -o ./bin/krill ./cmd/krill
RUN go build -o ./bin/device-simulator ./cmd

EXPOSE 2112

CMD [ "/bin/krill" ]
CMD [ "/bin/device-simulator" ]
73 changes: 50 additions & 23 deletions samples/krill/README.md → samples/device-simulator/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# Krill
# Device Simulator

```
⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣤⣤⣀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣀⡙⠻⢶⣶⣦⣴⣶⣶⣶⠾⠛⠛⠋⠉⠉⠉⠉⠙⠃⠀⠀⠀⠀⠀
⠀⠀⠀⠉⠉⠙⠛⠛⠋⠉⠉⠡⣤⣴⣶⣶⣾⣿⣿⣿⣛⣩⣤⡤⠖⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢠⣴⣾⠂⣴⣦⠈⣿⣿⣿⣿⣿⣿⠿⠛⣋⠁⠀⠀⠀⠀⠀
⠀⠀⢀⣼⣿⣶⣄⡉⠻⣧⣌⣁⣴⣿⣿⣿⣿⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀
⠀⠀⣾⣿⣿⣿⣿⣿⣦⡈⢻⣿⣿⣿⣿⡿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⡀⢻⣿⣿⣿⣿⣿⣿⣿⡄⠙⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢠⣷⣄⡉⠻⢿⣿⣿⣿⠏⠠⢶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢸⣿⣿⣿⣶⣤⣈⠙⠁⠰⣦⣀⠉⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠘⢿⣿⣿⣿⣿⣿⡇⠠⣦⣄⠉⠳⣤⠈⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢠⣌⣉⡉⠉⣉⡁⠀⠀⠙⠗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠹⢿⣿⣿⣿⣿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠙⠻⣿⣿⠟⢀⣤⡀⠀⠀⠀⠀⠀⠀⣀⣀⣠⣤⣤⣤⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠿⠿⡿⠂⣀⣠⣤⣤⣤⣀⣉⣉⠉⠉⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠛⠛⠛⠋⠉⠉⠁
____ _ _____ _ _ _
| \ ___ _ _|_|___ ___ | __|_|_____ _ _| |___| |_ ___ ___
| | | -_| | | | _| -_| |__ | | | | | | .'| _| . | _|
|____/|___|\_/|_|___|___| |_____|_|_|_|_|___|_|__,|_| |___|_|
```

Krill is a highly configurable MQTT asset simulator.
Device Simulator is a highly configurable MQTT asset simulator.

## Usage

### Krill as K8s Pod
### Device Simulator as K8s Pod

`kubectl run krill --image=azbluefin.azurecr.io/krill:latest --stdin < config.yml`
```sh
# From the root of the device-simulator directory.
docker build ../.. -f Dockerfile -t <yourcrhere>.azurecr.io/device-simulator:latest

Krill runs as a pod within the desired cluster using the kubectl run command. The configuration of choice is provided via stdin of the krill process within the pod, provided in the command above using `--stdin < config.yml`. Alternative names for a configuration file may be used -- the command simply uses stdin piping to provide krill with an appropriate configuration.
# Or if running from the root of the explore-iot-operations repository.
# docker build . -f ./samples/device-simulator/Dockerfile -t <yourcrhere>.azurecr.io/device-simulator:latest

# Push or load your newly built image into your cluster, depending on the k8s setup.
# docker push <yourcrhere>.azurecr.io/device-simulator:latest # Using AKS + Connected ACR
# minikube load <yourcrhere>.azurecr.io/device-simulator:latest # Using minikube
# docker save <yourcrhere>.azurecr.io/device-simulator:latest | k3s ctr images import - # Using K3s

kubectl run device-simulator --image=<yourcrhere>.azurecr.io/device-simulator:latest --stdin < config.yml
```

Device simulator runs as a pod within the desired cluster using the kubectl run command. The configuration of choice is provided via stdin of the simulator process within the pod, provided in the command above using `--stdin < config.yml`. Alternative names for a configuration file may be used -- the command simply uses stdin piping to provide simulator with an appropriate configuration.

See the example YAML configuration below, with comments describing the various configurable fields.

Expand Down Expand Up @@ -91,6 +93,31 @@ simulation:

```

### Device Simulator on the Command Line

#### Method 1

```sh
# With Golang installed, the device simulator can be run from the cmd folder.
cd ./cmd
go run . < config.yml
# Or by reading in a file instead of stdin:
# go run . --stdin=false --config=config.yml
```

#### Method 2

```sh
# With Golang installed, build a binary of the device simulator.
go build -o ./bin/device-simulator ./cmd
./device-simulator < config.yml

# Or by reading in a file instead of stdin:
# ./device-simulator --stdin=false --config=config.yml
```

## Configuring a Simulation

### Configuring Payload Formats

There are currently five supported types of payload formats:
Expand Down Expand Up @@ -178,7 +205,7 @@ Example Equations:

## Metrics

Prometheus metrics are provided by the krill simulator at the port specified in the metrics field of the configuration. The available metrics are:
Prometheus metrics are provided by the simulator at the port specified in the metrics field of the configuration. The available metrics are:

1. `krill_entity_gauge` - shows the count of each system entity.
1. `krill_<siteName>_asset_publish_counter` - records the number of messages published, labeled by asset identifier.
1. `device_simulator_entity_gauge` - shows the count of each system entity.
1. `device_simulator_<siteName>_asset_publish_counter` - records the number of messages published, labeled by asset identifier.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ import (

"github.com/explore-iot-ops/lib/env"
"github.com/explore-iot-ops/lib/logger"
"github.com/explore-iot-ops/samples/krill/components/broker"
"github.com/explore-iot-ops/samples/krill/components/client"
"github.com/explore-iot-ops/samples/krill/components/edge"
"github.com/explore-iot-ops/samples/krill/components/formatter"
"github.com/explore-iot-ops/samples/krill/components/limiter"
"github.com/explore-iot-ops/samples/krill/components/node"
"github.com/explore-iot-ops/samples/krill/components/observer"
"github.com/explore-iot-ops/samples/krill/components/outlet"
"github.com/explore-iot-ops/samples/krill/components/provider"
"github.com/explore-iot-ops/samples/krill/components/publisher"
"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/krill/components/renderer"
"github.com/explore-iot-ops/samples/krill/components/site"
"github.com/explore-iot-ops/samples/krill/components/subscriber"
"github.com/explore-iot-ops/samples/krill/components/topic"
"github.com/explore-iot-ops/samples/krill/components/tracer"
"github.com/explore-iot-ops/samples/krill/lib/exporter"
"github.com/explore-iot-ops/samples/krill/lib/krill"
"github.com/explore-iot-ops/samples/device-simulator/components/broker"
"github.com/explore-iot-ops/samples/device-simulator/components/client"
"github.com/explore-iot-ops/samples/device-simulator/components/edge"
"github.com/explore-iot-ops/samples/device-simulator/components/formatter"
"github.com/explore-iot-ops/samples/device-simulator/components/limiter"
"github.com/explore-iot-ops/samples/device-simulator/components/node"
"github.com/explore-iot-ops/samples/device-simulator/components/observer"
"github.com/explore-iot-ops/samples/device-simulator/components/outlet"
"github.com/explore-iot-ops/samples/device-simulator/components/provider"
"github.com/explore-iot-ops/samples/device-simulator/components/publisher"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/components/renderer"
"github.com/explore-iot-ops/samples/device-simulator/components/site"
"github.com/explore-iot-ops/samples/device-simulator/components/subscriber"
"github.com/explore-iot-ops/samples/device-simulator/components/topic"
"github.com/explore-iot-ops/samples/device-simulator/components/tracer"
"github.com/explore-iot-ops/samples/device-simulator/lib/exporter"
"github.com/explore-iot-ops/samples/device-simulator/lib/external"
"gopkg.in/yaml.v3"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -48,7 +48,7 @@ func main() {

func run() error {

fmt.Print(krill.Krill)
fmt.Print(external.Logo)

ctx := context.Background()

Expand All @@ -70,8 +70,8 @@ func run() error {
unmarshal = json.Unmarshal
}

configReader := env.New[krill.Configuration](
func(cr *env.ConfigurationReader[krill.Configuration]) {
configReader := env.New[external.Configuration](
func(cr *env.ConfigurationReader[external.Configuration]) {
cr.Unmarshal = unmarshal
if *flags["stdin"].(*bool) {
cr.ReadFile = func(_ string) ([]byte, error) {
Expand Down Expand Up @@ -189,7 +189,7 @@ func run() error {
topicService := topic.NewService(topicStore, registryStore)
tracerService := tracer.NewService(tracerStore, registryStore)

builder := krill.New(
builder := external.New(
brokerService,
clientService,
edgeService,
Expand All @@ -208,7 +208,7 @@ func run() error {
tracerService,
)

lg.Printf("parsing krill configuration")
lg.Printf("parsing external configuration")

err = builder.Parse(configuration.Simulation)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package broker
import (
"fmt"

"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
)

type Source interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package broker

import (
"github.com/explore-iot-ops/samples/krill/components/observer"
"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/krill/lib/component"
"github.com/explore-iot-ops/samples/device-simulator/components/observer"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/lib/component"
)

type Store component.Store[Source, component.ID]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package broker
import (
"testing"

"github.com/explore-iot-ops/samples/krill/components/observer"
"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/krill/lib/component"
"github.com/explore-iot-ops/samples/device-simulator/components/observer"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/lib/component"
"github.com/stretchr/testify/require"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"time"

"github.com/explore-iot-ops/lib/logger"
"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/krill/components/site"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/components/site"

mqtt "github.com/eclipse/paho.mqtt.golang"
)
Expand All @@ -28,10 +28,7 @@ type PublisherSubscriber interface {
GetName() string
}

// Publisher is an interface whose implementation should include the observable functionality (see registry // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package),
// Publisher is an interface whose implementation should include the observable functionality (see registry package),
// as well as the ability to publish a message on a given topic.
type Publisher interface {
Publish(topic string, qos byte, messagesRetained bool, data []byte) error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

mqttv5 "github.com/eclipse/paho.golang/paho"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/explore-iot-ops/samples/krill/components/site"
"github.com/explore-iot-ops/samples/krill/lib/errors"
"github.com/explore-iot-ops/samples/device-simulator/components/site"
"github.com/explore-iot-ops/samples/device-simulator/lib/errors"
"github.com/stretchr/testify/require"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package client
import (
"fmt"

"github.com/explore-iot-ops/samples/krill/lib/errors"
"github.com/explore-iot-ops/samples/device-simulator/lib/errors"
)

type BrokerConnectionError struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"context"

"github.com/explore-iot-ops/lib/logger"
"github.com/explore-iot-ops/samples/krill/components/broker"
"github.com/explore-iot-ops/samples/krill/components/observer"
"github.com/explore-iot-ops/samples/krill/components/registry"
"github.com/explore-iot-ops/samples/krill/components/site"
"github.com/explore-iot-ops/samples/krill/lib/component"
"github.com/explore-iot-ops/samples/krill/lib/dialer"
"github.com/explore-iot-ops/samples/device-simulator/components/broker"
"github.com/explore-iot-ops/samples/device-simulator/components/observer"
"github.com/explore-iot-ops/samples/device-simulator/components/registry"
"github.com/explore-iot-ops/samples/device-simulator/components/site"
"github.com/explore-iot-ops/samples/device-simulator/lib/component"
"github.com/explore-iot-ops/samples/device-simulator/lib/dialer"

mqttv5 "github.com/eclipse/paho.golang/paho"
mqttv3 "github.com/eclipse/paho.mqtt.golang"
Expand Down
Loading

0 comments on commit d6e73fc

Please sign in to comment.