Skip to content

Instantly share code, notes, and snippets.

@smijar
smijar / readme.md
Created March 24, 2023 04:25
Prometheus histogram instrumentation example

to run example

# term 1
cd histo-example
go clean && go build .
./histo-example

# term 2 - run some load
for i in {1..100000};do curl http://localhost:2112/hello1; curl http://localhost:2112/hello2; sleep 0.5; done
@smijar
smijar / metrics_example1.go
Last active March 22, 2023 18:26
golang example to instrument code to generate and client library to Parse (extra) Prometheus metrics
package metrics_examples
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
# To deploy: kubectl apply -f nginx-hello-world-deployment.yaml
# Access it with the API as a proxy:
# $ kubectl proxy
# Then in your browser: http://localhost:8001/api/v1/namespaces/default/services/nginx:/proxy/#!/
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
@smijar
smijar / jcurl.sh
Created January 6, 2023 18:57
Retrieves JWT token and uses it for "curl" calls
export JWT_TOKEN=$(curl -s -H "Content-Type:application/json" -XPOST http://localhost:8080/tokenz -d '{"email":"youremail@youremaildomain.app", "password":"password"}' | jq -r '.token')
curl -H "Content-Type:application/json" -H "Authorization: Bearer $JWT_TOKEN" $@
@smijar
smijar / albums.go
Created December 15, 2022 03:10
Gin Gonic REST sample
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
// album represents data about a record album.
type album struct {
@smijar
smijar / envs.txt
Last active November 17, 2022 15:19
Using pandas to read CSV and convert each row into a dictionary
canadacentral env-1 demogroup-1
westus env-2 demogroup-1
westus env-3 demogroup-1
westus env-4 demogroup-1
westus env-5 demogroup-1
uksouth env-1 demogroup-2
canadacentral env-2 demogroup-2
canadacentral env-3 demogroup-2
canadacentral env-4 demogroup-2
@smijar
smijar / examples.ref
Last active September 30, 2022 01:40
Multipass VM with nginx, docker, kind
# description
below we show some examples of running containers under docker with KKM
# examples
```shell
$ docker run -d --rm -p 8080:8080 --runtime=krun --name spring-boot-hello kontainguide/spring-boot-hello:1.0
$ curl http://localhost:8080
# python
$ docker run -d --rm -p 5000:5000 --runtime=krun --name py-flask-hello kontainguide/py-flask-hello:1.0

install knative plugins locally

# ref: https://knative.dev/docs/getting-started/quickstart-install/#install-the-knative-cli
echo
echo "installing knative with kind cluster..."
echo "downloading kn CLI"
sudo curl -s -Lo /usr/local/bin/kn https://github.com/knative/client/releases/download/knative-v1.4.1/kn-linux-amd64
sudo chmod +x /usr/local/bin/kn
sleep 2
echo

patching knative cluster for allowing addition of "runtime class" kind for functions

export config map to see what is in it

kubectl get configmap/config-features -n knative-serving -o yaml

then patch it with a merge

echo "patching configmap/config-features to enable podspec.runtimeclassname for installing KM..."