diff --git a/samples/anomaly-detection/Dockerfile b/samples/anomaly-detection/Dockerfile index e00f596..e047e00 100644 --- a/samples/anomaly-detection/Dockerfile +++ b/samples/anomaly-detection/Dockerfile @@ -14,8 +14,8 @@ RUN go install github.com/magefile/mage@latest RUN mage ci -RUN go build -o ./bin/anomaly-detection ./cmd/anomaly-detection +RUN go build -o ./bin/anomaly-detection ./cmd EXPOSE 2112 -CMD [ "/bin/anomaly-detection" ] +CMD [ "./bin/anomaly-detection" ] diff --git a/samples/anomaly-detection/README.md b/samples/anomaly-detection/README.md index 923391c..b55052d 100644 --- a/samples/anomaly-detection/README.md +++ b/samples/anomaly-detection/README.md @@ -2,21 +2,23 @@ ## Usage +This demo assumes a K3S cluster. + ### Server as a Pod ```sh # From the root of the anomaly-detection directory. -docker build ../.. -f Dockerfile -t .azurecr.io/anomaly-detection:latest +docker build ../.. -f Dockerfile -t makocr.azurecr.io/anomaly-detection:latest # Or if running from the root of the explore-iot-operations repository. -# docker build . -f ./samples/anomaly-detection/Dockerfile -t .azurecr.io/anomaly-detection:latest +# docker build . -f ./samples/anomaly-detection/Dockerfile -t makocr.azurecr.io/anomaly-detection:latest # Push or load your newly built image into your cluster, depending on the k8s setup. -# docker push .azurecr.io/anomaly-detection:latest # Using AKS + Connected ACR -# minikube load .azurecr.io/anomaly-detection:latest # Using minikube -# docker save .azurecr.io/anomaly-detection:latest | k3s ctr images import - # Using K3s +# docker push makocr.azurecr.io/anomaly-detection:latest # Using AKS + Connected ACR +# minikube load makocr.azurecr.io/anomaly-detection:latest # Using minikube +# docker save makocr.azurecr.io/anomaly-detection:latest | k3s ctr images import - # Using K3s -kubectl run anomaly-detection --image=.azurecr.io/anomaly-detection:latest --stdin < config.yml +kubectl apply -f manifest.yml ``` ### Configuration diff --git a/samples/anomaly-detection/cmd/config.yml b/samples/anomaly-detection/cmd/config.yml deleted file mode 100644 index ae8fdc3..0000000 --- a/samples/anomaly-detection/cmd/config.yml +++ /dev/null @@ -1,24 +0,0 @@ -logger: - level: 0 -server: - route: /anomaly - port: 3333 -algorithm: - temperature: - lambda: 0.25 - lFactor: 3 - controlT: 90 - controlS: 20 - controlN: 10 - vibration: - lambda: 0.25 - lFactor: 3 - controlT: 50 - controlS: 20 - controlN: 10 - humidity: - lambda: 0.25 - lFactor: 3 - controlT: 80 - controlS: 20 - controlN: 10 diff --git a/samples/anomaly-detection/go.mod b/samples/anomaly-detection/go.mod index 93df207..dabae74 100644 --- a/samples/anomaly-detection/go.mod +++ b/samples/anomaly-detection/go.mod @@ -12,6 +12,7 @@ replace ( require ( github.com/explore-iot-ops/lib/env v0.0.0-00010101000000-000000000000 github.com/explore-iot-ops/lib/logger v0.0.0-00010101000000-000000000000 + github.com/explore-iot-ops/lib/mage v0.0.0-00010101000000-000000000000 github.com/gofiber/fiber/v2 v2.51.0 github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 @@ -19,14 +20,19 @@ require ( ) require ( + github.com/VividCortex/ewma v1.1.1 // indirect github.com/andybalholm/brotli v1.0.5 // indirect + github.com/cheggaaa/pb/v3 v3.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/color v1.9.0 // indirect github.com/google/uuid v1.4.0 // indirect github.com/klauspost/compress v1.16.7 // indirect + github.com/magefile/mage v1.15.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/princjef/mageutil v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.50.0 // indirect diff --git a/samples/anomaly-detection/go.sum b/samples/anomaly-detection/go.sum index 2cb1e0f..dc852d4 100644 --- a/samples/anomaly-detection/go.sum +++ b/samples/anomaly-detection/go.sum @@ -1,8 +1,16 @@ +github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= +github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/cheggaaa/pb v2.0.7+incompatible/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= +github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM= +github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ= github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U= @@ -10,17 +18,30 @@ github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= +github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/matryer/is v1.3.0 h1:9qiso3jaJrOe6qBRJRBt2Ldht05qDiFP9le0JOIhRSI= +github.com/matryer/is v1.3.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/princjef/mageutil v1.0.0 h1:1OfZcJUMsooPqieOz2ooLjI+uHUo618pdaJsbCXcFjQ= +github.com/princjef/mageutil v1.0.0/go.mod h1:mkShhaUomCYfAoVvTKRcbAs8YSVPdtezI5j6K+VXhrs= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -34,12 +55,23 @@ github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/VividCortex/ewma.v1 v1.1.1/go.mod h1:TekXuFipeiHWiAlO1+wSS23vTcyFau5u3rxXUSXj710= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/cheggaaa/pb.v2 v2.0.7/go.mod h1:0CiZ1p8pvtxBlQpLXkHuUTpdJ1shm3OqCF1QugkjHL4= +gopkg.in/fatih/color.v1 v1.7.0/go.mod h1:P7yosIhqIl/sX8J8UypY5M+dDpD2KmyfP5IRs5v/fo0= +gopkg.in/mattn/go-colorable.v0 v0.1.0/go.mod h1:BVJlBXzARQxdi3nZo6f6bnl5yR20/tOL6p+V0KejgSY= +gopkg.in/mattn/go-isatty.v0 v0.0.4/go.mod h1:wt691ab7g0X4ilKZNmMII3egK0bTxl37fEn/Fwbd8gc= +gopkg.in/mattn/go-runewidth.v0 v0.0.4/go.mod h1:BmXejnxvhwdaATwiJbB1vZ2dtXkQKZGu9yLFCZb4msQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/samples/anomaly-detection/lib/ewma/emwa_test.go b/samples/anomaly-detection/lib/ewma/emwa_test.go index c51bf47..630b443 100644 --- a/samples/anomaly-detection/lib/ewma/emwa_test.go +++ b/samples/anomaly-detection/lib/ewma/emwa_test.go @@ -67,7 +67,6 @@ func TestSquareSum(t *testing.T) { nextMean = ewma.Mean(5, obs, mean) sum = ewma.SquareSum(obs, sum, nextMean, mean) require.Equal(t, 65.2, sum) - mean = nextMean } func TestControlLimit(t *testing.T) { diff --git a/samples/anomaly-detection/magefile.go b/samples/anomaly-detection/magefile.go index f764480..8f475a6 100644 --- a/samples/anomaly-detection/magefile.go +++ b/samples/anomaly-detection/magefile.go @@ -13,7 +13,11 @@ import ( func CI() error { return mage.CI( "github.com/explore-iot-ops/samples/anomaly-detection/", - map[string]any{"cmd": nil}, + map[string]any{ + "cmd": nil, + "lib/configuration": nil, + "lib/payload": nil, + }, 3000, 0.00, 0.00, diff --git a/samples/anomaly-detection/manifest.yml b/samples/anomaly-detection/manifest.yml new file mode 100644 index 0000000..7db06fb --- /dev/null +++ b/samples/anomaly-detection/manifest.yml @@ -0,0 +1,92 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: azure-iot-operations + name: anomaly-conf +data: + config.yml: |- + logger: + level: 0 + server: + route: /anomaly + port: 3333 + algorithm: + temperature: + lambda: 0.25 + lFactor: 3 + controlT: 90 + controlS: 20 + controlN: 10 + vibration: + lambda: 0.25 + lFactor: 3 + controlT: 50 + controlS: 20 + controlN: 10 + humidity: + lambda: 0.25 + lFactor: 3 + controlT: 80 + controlS: 20 + controlN: 10 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: azure-iot-operations + name: anomaly-detection + labels: + app: anomaly-detection +spec: + replicas: 1 + selector: + matchLabels: + app: anomaly-detection + template: + metadata: + labels: + app: anomaly-detection + spec: + containers: + - name: anomaly-detection + image: makocr.azurecr.io/anomaly-detection:latest + imagePullPolicy: Always + ports: + - name: http + containerPort: 3333 + resources: + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + command: + - "./bin/anomaly-detection" + - "--stdin=false" + - "--config=/etc/anomaly-detection/config.yml" + volumeMounts: + - mountPath: /etc/anomaly-detection/config.yml + subPath: config.yml + name: config + readOnly: true + volumes: + - name: config + configMap: + name: anomaly-conf +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: anomaly-svc + labels: + app: anomaly-detection +spec: + ports: + - port: 3333 + name: http + type: ClusterIP + selector: + app: anomaly-detection \ No newline at end of file diff --git a/samples/http-grpc-callout/Dockerfile b/samples/http-grpc-callout/Dockerfile index bbf7acd..6e8fc6e 100644 --- a/samples/http-grpc-callout/Dockerfile +++ b/samples/http-grpc-callout/Dockerfile @@ -14,8 +14,8 @@ RUN go install github.com/magefile/mage@latest RUN mage ci -RUN go build -o ./bin/http-grpc-callout ./cmd/http-grpc-callout +RUN go build -o ./bin/http-grpc-callout ./cmd EXPOSE 2112 -CMD [ "/bin/http-grpc-callout" ] +CMD [ "./bin/http-grpc-callout" ] diff --git a/samples/http-grpc-callout/README.md b/samples/http-grpc-callout/README.md index 5363bae..8929880 100644 --- a/samples/http-grpc-callout/README.md +++ b/samples/http-grpc-callout/README.md @@ -8,17 +8,17 @@ GRPC/HTTP Callout Server is a server for testing the http and grpc callout capab ```sh # From the root of the http-grpc-callout directory. -docker build ../.. -f Dockerfile -t .azurecr.io/http-grpc-callout:latest +docker build ../.. -f Dockerfile -t makocr.azurecr.io/http-grpc-callout:latest # Or if running from the root of the explore-iot-operations repository. -# docker build . -f ./samples/http-grpc-callout/Dockerfile -t .azurecr.io/http-grpc-callout:latest +# docker build . -f ./samples/http-grpc-callout/Dockerfile -t makocr.azurecr.io/http-grpc-callout:latest # Push or load your newly built image into your cluster, depending on the k8s setup. -# docker push .azurecr.io/http-grpc-callout:latest # Using AKS + Connected ACR -# minikube load .azurecr.io/http-grpc-callout:latest # Using minikube -# docker save .azurecr.io/http-grpc-callout:latest | k3s ctr images import - # Using K3s +# docker push makocr.azurecr.io/http-grpc-callout:latest # Using AKS + Connected ACR +# minikube load makocr.azurecr.io/http-grpc-callout:latest # Using minikube +# docker save makocr.azurecr.io/http-grpc-callout:latest | k3s ctr images import - # Using K3s -kubectl run http-grpc-callout --image=.azurecr.io/http-grpc-callout:latest --stdin < config.yml +kubectl apply -f manifest.yml ``` ### Configuration diff --git a/samples/http-grpc-callout/cmd/config.yml b/samples/http-grpc-callout/cmd/config.yml deleted file mode 100644 index 49f5233..0000000 --- a/samples/http-grpc-callout/cmd/config.yml +++ /dev/null @@ -1,43 +0,0 @@ -logger: - level: 0 -servers: - http: - port: 3333 - resources: - - path: /example - method: GET - status: 200 - outputs: ["output1", "output2"] - response: | - { - "hello": "world" - } - - path: /example - method: POST - status: 200 - outputs: ["output3", "output4"] - response: | - { - "hello": "world1" - } - grpc: - port: 3334 - outputs: ["output1", "output4"] -outputs: - - name: output1 - type: stdout - - name: output2 - type: mqtt - qos: 1 - path: default/output1 - endpoint: localhost:1883 - - name: output3 - type: mqtt - qos: 1 - path: default/output2 - endpoint: localhost:1883 - - name: output4 - type: mqtt - qos: 1 - path: grpc/example - endpoint: localhost:1883 diff --git a/samples/http-grpc-callout/manifest.yml b/samples/http-grpc-callout/manifest.yml new file mode 100644 index 0000000..f33e29b --- /dev/null +++ b/samples/http-grpc-callout/manifest.yml @@ -0,0 +1,143 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: azure-iot-operations + name: callout-conf +data: + config.yml: |- + logger: + level: 0 + servers: + http: + port: 3333 + resources: + - path: /example + method: GET + status: 200 + outputs: ["output1"] + response: | + { + "hello": "world" + } + - path: /example + method: POST + status: 200 + outputs: ["output1"] + response: | + { + "hello": "world1" + } + - path: /ts + method: GET + status: 200 + outputs: ["output1"] + response: | + { + "timestamp": "2023-11-16T8:18:10-08:00" + } + - path: /anomaly + method: GET + status: 200 + outputs: ["output1"] + response: | + { + "Payload": { + "assetID": "Tac_S1", + "asset_id": "Tac_S1", + "asset_name": "Tacoma_Slicer_Tacoma_Slicer__asset_0", + "humidity": 82.34915832237789, + "machine_status": 1, + "maintenanceStatus": "Upcoming", + "name": "Contoso", + "operating_time": 5999, + "serialNumber": "SN010", + "site": "Tacoma", + "source_timestamp": "2023-11-02T20:27:09.143Z", + "temperature": 93.56069711661576, + "vibration": 50.98858025013501 + } + } + grpc: + port: 3334 + outputs: ["output1"] + outputs: + - name: output1 + type: stdout +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: azure-iot-operations + name: http-grpc-callout + labels: + app: http-grpc-callout +spec: + replicas: 1 + selector: + matchLabels: + app: http-grpc-callout + template: + metadata: + labels: + app: http-grpc-callout + spec: + containers: + - name: http-grpc-callout + image: makocr.azurecr.io/http-grpc-callout:latest + imagePullPolicy: Always + ports: + - name: http + containerPort: 3333 + - name: grpc + containerPort: 3334 + resources: + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + command: + - "./bin/http-grpc-callout" + - "--stdin=false" + - "--config=/etc/http-grpc-callout/config.yml" + volumeMounts: + - mountPath: /etc/http-grpc-callout/config.yml + subPath: config.yml + name: config + readOnly: true + volumes: + - name: config + configMap: + name: callout-conf +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: callout-svc-http + labels: + app: http-grpc-callout +spec: + ports: + - port: 3333 + name: http + type: ClusterIP + selector: + app: http-grpc-callout +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: callout-svc-grpc + labels: + app: http-grpc-callout +spec: + ports: + - port: 3334 + name: grpc + type: ClusterIP + selector: + app: http-grpc-callout diff --git a/samples/http-grpc-shift-calculation/Dockerfile b/samples/http-grpc-shift-calculation/Dockerfile index bb0f749..3d6c70f 100644 --- a/samples/http-grpc-shift-calculation/Dockerfile +++ b/samples/http-grpc-shift-calculation/Dockerfile @@ -14,8 +14,8 @@ RUN go install github.com/magefile/mage@latest RUN mage ci -RUN go build -o ./bin/http-grpc-shift-calculation ./cmd/http-grpc-shift-calculation +RUN go build -o ./bin/http-grpc-shift-calculation ./cmd EXPOSE 2112 -CMD [ "/bin/http-grpc-shift-calculation" ] +CMD [ "./bin/http-grpc-shift-calculation" ] diff --git a/samples/http-grpc-shift-calculation/README.md b/samples/http-grpc-shift-calculation/README.md index b682c64..6e4c932 100644 --- a/samples/http-grpc-shift-calculation/README.md +++ b/samples/http-grpc-shift-calculation/README.md @@ -6,17 +6,17 @@ ```sh # From the root of the http-grpc-shift-calculation directory. -docker build ../.. -f Dockerfile -t .azurecr.io/http-grpc-shift-calculation:latest +docker build ../.. -f Dockerfile -t makocr.azurecr.io/http-grpc-shift-calculation:latest # Or if running from the root of the explore-iot-operations repository. -# docker build . -f ./samples/http-grpc-shift-calculation/Dockerfile -t .azurecr.io/http-grpc-shift-calculation:latest +# docker build . -f ./samples/http-grpc-shift-calculation/Dockerfile -t makocr.azurecr.io/http-grpc-shift-calculation:latest # Push or load your newly built image into your cluster, depending on the k8s setup. -# docker push .azurecr.io/http-grpc-shift-calculation:latest # Using AKS + Connected ACR -# minikube load .azurecr.io/http-grpc-shift-calculation:latest # Using minikube -# docker save .azurecr.io/http-grpc-shift-calculation:latest | k3s ctr images import - # Using K3s +# docker push makocr.azurecr.io/http-grpc-shift-calculation:latest # Using AKS + Connected ACR +# minikube load makocr.azurecr.io/http-grpc-shift-calculation:latest # Using minikube +# docker save makocr.azurecr.io/http-grpc-shift-calculation:latest | k3s ctr images import - # Using K3s -kubectl run http-grpc-shift-calculation --image=.azurecr.io/http-grpc-shift-calculation:latest --stdin < config.yml +kubectl apply -f manifest.yml ``` ### Server Configuration diff --git a/samples/http-grpc-shift-calculation/cmd/config.yml b/samples/http-grpc-shift-calculation/cmd/config.yml deleted file mode 100644 index cf357e7..0000000 --- a/samples/http-grpc-shift-calculation/cmd/config.yml +++ /dev/null @@ -1,8 +0,0 @@ -logger: - level: 0 -server: - httpPort: 3333 - grpcPort: 4444 -calculator: - shifts: 3 - initialTime: 2023-11-16T00:00:00-08:00 diff --git a/samples/http-grpc-shift-calculation/cmd/handler.go b/samples/http-grpc-shift-calculation/cmd/handler.go index d4aef23..4a62b9d 100644 --- a/samples/http-grpc-shift-calculation/cmd/handler.go +++ b/samples/http-grpc-shift-calculation/cmd/handler.go @@ -6,7 +6,7 @@ package main import ( "time" - "github.com/explore-iot-ops/samples/http-grpc-shift-calculator/lib/shift" + "github.com/explore-iot-ops/samples/http-grpc-shift-calculation/lib/shift" ) type InvalidMessageTypeError struct{} @@ -21,7 +21,7 @@ func (err *MissingTimestampError) Error() string { return "missing timestamp" } -type InvalidShiftTimestampError struct {} +type InvalidShiftTimestampError struct{} func (err *InvalidShiftTimestampError) Error() string { return "invalid shift timestamp" diff --git a/samples/http-grpc-shift-calculation/cmd/main.go b/samples/http-grpc-shift-calculation/cmd/main.go index 5b4c08a..bbbbb5a 100644 --- a/samples/http-grpc-shift-calculation/cmd/main.go +++ b/samples/http-grpc-shift-calculation/cmd/main.go @@ -14,7 +14,7 @@ import ( "github.com/explore-iot-ops/lib/env" "github.com/explore-iot-ops/lib/logger" "github.com/explore-iot-ops/lib/proto" - "github.com/explore-iot-ops/samples/http-grpc-shift-calculator/lib/shift" + "github.com/explore-iot-ops/samples/http-grpc-shift-calculation/lib/shift" "google.golang.org/grpc" "gopkg.in/yaml.v3" diff --git a/samples/http-grpc-shift-calculation/go.mod b/samples/http-grpc-shift-calculation/go.mod index 3288e1d..03f92b0 100644 --- a/samples/http-grpc-shift-calculation/go.mod +++ b/samples/http-grpc-shift-calculation/go.mod @@ -1,4 +1,4 @@ -module github.com/explore-iot-ops/samples/http-grpc-shift-calculator +module github.com/explore-iot-ops/samples/http-grpc-shift-calculation go 1.21.3 @@ -12,23 +12,30 @@ replace ( require ( github.com/explore-iot-ops/lib/env v0.0.0-00010101000000-000000000000 github.com/explore-iot-ops/lib/logger v0.0.0-00010101000000-000000000000 + github.com/explore-iot-ops/lib/mage v0.0.0-00010101000000-000000000000 github.com/explore-iot-ops/lib/proto v0.0.0-00010101000000-000000000000 github.com/gofiber/fiber/v2 v2.51.0 github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 + google.golang.org/grpc v1.59.0 gopkg.in/yaml.v3 v3.0.1 ) require ( + github.com/VividCortex/ewma v1.1.1 // indirect github.com/andybalholm/brotli v1.0.5 // indirect + github.com/cheggaaa/pb/v3 v3.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/color v1.9.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.4.0 // indirect github.com/klauspost/compress v1.16.7 // indirect + github.com/magefile/mage v1.15.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/princjef/mageutil v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.50.0 // indirect @@ -37,6 +44,5 @@ require ( golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect - google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/samples/http-grpc-shift-calculation/go.sum b/samples/http-grpc-shift-calculation/go.sum index 684f56c..609fd3f 100644 --- a/samples/http-grpc-shift-calculation/go.sum +++ b/samples/http-grpc-shift-calculation/go.sum @@ -1,8 +1,16 @@ +github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= +github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/cheggaaa/pb v2.0.7+incompatible/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= +github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM= +github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ= github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U= @@ -16,17 +24,30 @@ github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= +github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/matryer/is v1.3.0 h1:9qiso3jaJrOe6qBRJRBt2Ldht05qDiFP9le0JOIhRSI= +github.com/matryer/is v1.3.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/princjef/mageutil v1.0.0 h1:1OfZcJUMsooPqieOz2ooLjI+uHUo618pdaJsbCXcFjQ= +github.com/princjef/mageutil v1.0.0/go.mod h1:mkShhaUomCYfAoVvTKRcbAs8YSVPdtezI5j6K+VXhrs= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -42,6 +63,11 @@ github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVS github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -58,7 +84,13 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/VividCortex/ewma.v1 v1.1.1/go.mod h1:TekXuFipeiHWiAlO1+wSS23vTcyFau5u3rxXUSXj710= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/cheggaaa/pb.v2 v2.0.7/go.mod h1:0CiZ1p8pvtxBlQpLXkHuUTpdJ1shm3OqCF1QugkjHL4= +gopkg.in/fatih/color.v1 v1.7.0/go.mod h1:P7yosIhqIl/sX8J8UypY5M+dDpD2KmyfP5IRs5v/fo0= +gopkg.in/mattn/go-colorable.v0 v0.1.0/go.mod h1:BVJlBXzARQxdi3nZo6f6bnl5yR20/tOL6p+V0KejgSY= +gopkg.in/mattn/go-isatty.v0 v0.0.4/go.mod h1:wt691ab7g0X4ilKZNmMII3egK0bTxl37fEn/Fwbd8gc= +gopkg.in/mattn/go-runewidth.v0 v0.0.4/go.mod h1:BmXejnxvhwdaATwiJbB1vZ2dtXkQKZGu9yLFCZb4msQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/samples/http-grpc-shift-calculation/manifest.yml b/samples/http-grpc-shift-calculation/manifest.yml new file mode 100644 index 0000000..5727c7a --- /dev/null +++ b/samples/http-grpc-shift-calculation/manifest.yml @@ -0,0 +1,93 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: azure-iot-operations + name: shift-conf +data: + config.yml: |- + logger: + level: 0 + server: + httpPort: 3333 + grpcPort: 3334 + calculator: + shifts: 3 + initialTime: 2023-11-16T00:00:00-08:00 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: azure-iot-operations + name: http-grpc-shift + labels: + app: http-grpc-shift +spec: + replicas: 1 + selector: + matchLabels: + app: http-grpc-shift + template: + metadata: + labels: + app: http-grpc-shift + spec: + containers: + - name: http-grpc-shift + image: makocr.azurecr.io/http-grpc-shift-calculation:latest + imagePullPolicy: Always + ports: + - name: http + containerPort: 3333 + - name: grpc + containerPort: 3334 + resources: + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + command: + - "./bin/http-grpc-shift-calculation" + - "--stdin=false" + - "--config=/etc/http-grpc-shift/config.yml" + volumeMounts: + - mountPath: /etc/http-grpc-shift/config.yml + subPath: config.yml + name: config + readOnly: true + volumes: + - name: config + configMap: + name: shift-conf +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: shift-svc-http + labels: + app: http-grpc-shift +spec: + ports: + - port: 3333 + name: http + type: ClusterIP + selector: + app: http-grpc-shift +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: shift-svc-grpc + labels: + app: http-grpc-shift +spec: + ports: + - port: 3334 + name: grpc + type: ClusterIP + selector: + app: http-grpc-shift diff --git a/samples/industrial-data-simulator/Dockerfile b/samples/industrial-data-simulator/Dockerfile index 5e656ce..cbf0dbe 100644 --- a/samples/industrial-data-simulator/Dockerfile +++ b/samples/industrial-data-simulator/Dockerfile @@ -18,4 +18,4 @@ RUN go build -o ./bin/industrial-data-simulator ./cmd EXPOSE 2112 -CMD [ "/bin/industrial-data-simulator" ] +CMD [ "./bin/industrial-data-simulator" ] diff --git a/samples/industrial-data-simulator/README.md b/samples/industrial-data-simulator/README.md index 56e2652..7c0d965 100644 --- a/samples/industrial-data-simulator/README.md +++ b/samples/industrial-data-simulator/README.md @@ -17,17 +17,17 @@ Industrial Data Simulator is a highly configurable MQTT asset simulator. ```sh # From the root of the industrial-data-simulator directory. -docker build ../.. -f Dockerfile -t .azurecr.io/industrial-data-simulator:latest +docker build ../.. -f Dockerfile -t makocr.azurecr.io/industrial-data-simulator:latest # Or if running from the root of the explore-iot-operations repository. -# docker build . -f ./samples/industrial-data-simulator/Dockerfile -t .azurecr.io/industrial-data-simulator:latest +# docker build . -f ./samples/industrial-data-simulator/Dockerfile -t makocr.azurecr.io/industrial-data-simulator:latest # Push or load your newly built image into your cluster, depending on the k8s setup. -# docker push .azurecr.io/industrial-data-simulator:latest # Using AKS + Connected ACR -# minikube load .azurecr.io/industrial-data-simulator:latest # Using minikube -# docker save .azurecr.io/industrial-data-simulator:latest | k3s ctr images import - # Using K3s +# docker push makocr.azurecr.io/industrial-data-simulator:latest # Using AKS + Connected ACR +# minikube load makocr.azurecr.io/industrial-data-simulator:latest # Using minikube +# docker save makocr.azurecr.io/industrial-data-simulator:latest | k3s ctr images import - # Using K3s -kubectl run industrial-data-simulator --image=.azurecr.io/industrial-data-simulator:latest --stdin < config.yml +kubectl apply -f manifest.yml ``` Industrial Data 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. diff --git a/samples/industrial-data-simulator/configs/simple/config.yml b/samples/industrial-data-simulator/configs/simple/config.yml index 5e38662..21b8b81 100644 --- a/samples/industrial-data-simulator/configs/simple/config.yml +++ b/samples/industrial-data-simulator/configs/simple/config.yml @@ -1,21 +1,21 @@ metrics: type: prometheus port: 2114 -logLevel: 1 +logLevel: 0 simulation: target: - host: localhost + host: aio-mq-dmqtt-frontend port: 1883 sites: - name: site0 mqttVersion: v5 - assetCount: 3 + assetCount: 1 tags: - id: float_1 configuration: x count: 1 rate: - messagesPerPeriod: 2 + messagesPerPeriod: 1 periodSeconds: 1 tagsPerMessage: 2 payloadFormat: OPCUA diff --git a/samples/industrial-data-simulator/manifest.yml b/samples/industrial-data-simulator/manifest.yml new file mode 100644 index 0000000..3f076ea --- /dev/null +++ b/samples/industrial-data-simulator/manifest.yml @@ -0,0 +1,90 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: azure-iot-operations + name: simulator-conf +data: + config.yml: |- + metrics: + type: prometheus + port: 2114 + logLevel: 0 + simulation: + target: + host: aio-mq-dmqtt-frontend + port: 1883 + sites: + - name: site0 + mqttVersion: v5 + assetCount: 1 + tags: + - id: float_1 + configuration: x + count: 1 + rate: + messagesPerPeriod: 1 + periodSeconds: 1 + tagsPerMessage: 2 + payloadFormat: OPCUA + topicFormat: /{{.SiteName}}/{{.AssetName}} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: azure-iot-operations + name: data-simulator + labels: + app: data-simulator +spec: + replicas: 1 + selector: + matchLabels: + app: data-simulator + template: + metadata: + labels: + app: data-simulator + spec: + containers: + - name: data-simulator + image: makocr.azurecr.io/industrial-data-simulator:latest + imagePullPolicy: Always + ports: + - name: prometheus + containerPort: 2114 + resources: + requests: + memory: "128Mi" + cpu: "1000m" + limits: + memory: "128Mi" + cpu: "1000m" + command: + - "./bin/industrial-data-simulator" + - "--stdin=false" + - "--config=/etc/data-simulator/config.yml" + volumeMounts: + - mountPath: /etc/data-simulator/config.yml + subPath: config.yml + name: config + readOnly: true + volumes: + - name: config + configMap: + name: simulator-conf +--- +apiVersion: v1 +kind: Service +metadata: + namespace: azure-iot-operations + name: simulator-svc-prom + labels: + app: data-simulator +spec: + ports: + - port: 2114 + name: prometheus + type: ClusterIP + selector: + app: data-simulator diff --git a/samples/sql-input/README.md b/samples/sql-input/README.md index 7507b9d..85a5661 100644 --- a/samples/sql-input/README.md +++ b/samples/sql-input/README.md @@ -6,5 +6,5 @@ A setup script is included to create the postgres database in SQL and load a pre ```sh # ./setup.sh $K8S_NAMESPACE $DB_NAME $DB_USERNAME $DB_PASSWORD $LOCAL_SQL_FILE_PATH -./setup.sh default database username password ./initialization.sql +./setup.sh azure-iot-operations database username password ./initialization.sql ``` diff --git a/samples/sql-input/manifest.yml b/samples/sql-input/manifest.yml index 9b9ecd6..bc03983 100644 --- a/samples/sql-input/manifest.yml +++ b/samples/sql-input/manifest.yml @@ -2,7 +2,7 @@ kind: PersistentVolume apiVersion: v1 metadata: - namespace: default + namespace: azure-iot-operations name: pg-pv labels: app: postgres @@ -19,7 +19,7 @@ spec: kind: PersistentVolumeClaim apiVersion: v1 metadata: - namespace: default + namespace: azure-iot-operations name: pg-pvc labels: app: postgres @@ -34,7 +34,7 @@ spec: apiVersion: v1 kind: ConfigMap metadata: - namespace: default + namespace: azure-iot-operations name: pg-config labels: app: postgres @@ -46,7 +46,7 @@ data: apiVersion: v1 kind: Service metadata: - namespace: default + namespace: azure-iot-operations name: pg-svc labels: app: postgres @@ -61,7 +61,7 @@ spec: apiVersion: apps/v1 kind: StatefulSet metadata: - namespace: default + namespace: azure-iot-operations name: pg-statefulset labels: app: postgres