Skip to content

Instantly share code, notes, and snippets.

Building reliable solutions

Xabier Larrakoetxea Gallego slok

Building reliable solutions
View GitHub Profile
slok /
Last active Aug 13, 2020
go performance, pprof, profiling

Enable profiling

Default http server

import _ "net/http/pprof"

Non-default server

View k8sunstructured_test.go
package k8sunstructured_test
import (
metav1 ""
slok / main.go
Created Jun 4, 2018
Kubernetes controller that updates annotation on pods with `kooper: test` label
View main.go
package main
import (
corev1 ""
metav1 ""
View kooper-vgo.log
$ time vgo build
vgo: finding v0.0.0-20170309230114-17543becf905
vgo: finding v2.0.0-20151008152123-3cfe88295d20
vgo: finding v0.0.0-20150321034511-ca8a464d23d5
vgo: finding v0.0.0-20151120032300-5627bad10b82
vgo: finding v0.0.0-20151125225445-9eab56311373
vgo: finding v0.0.0-20160207163330-193d1ecb466b
vgo: finding v0.0.0-20150606115303-ded5959c0d4e
vgo: finding v0.0.0-20160513154944-14437382a98e
FindRepo: Get x509: certificate signed by unknown authority
slok / handler-opentracing.go
Created May 23, 2018
kooper handler opentracing
View handler-opentracing.go
hand := &handler.HandlerFunc{
AddFunc: func(ctx context.Context, obj runtime.Object) error {
// Get the parent span.
pSpan := opentracing.SpanFromContext(ctx)
// Create a new span.
span := tracer.StartSpan("AddFunc", opentracing.ChildOf(pSpan.Context()))
defer span.Finish()
// Do stuff...
View kooper-example-controller.go
// Initialize logger.
log := &log.Std{}
// Create the controller that will refresh every 30 seconds.
ctrl := controller.NewSequential(30*time.Second, hand, retr, log)
// Start our controller.
stopC := make(chan struct{})
if err := ctrl.Run(stopC); err != nil {
log.Errorf("error running controller: %s", err)
View kooper-example-handler.go
// Our domain logic that will print every add/sync/update and delete event we .
hand := &handler.HandlerFunc{
AddFunc: func(obj runtime.Object) error {
pod := obj.(*corev1.Pod)
log.Infof("Pod Add event: %s/%s", pod.Namespace, pod.Name)
return nil
DeleteFunc: func(s string) error {
log.Infof("Pod Delete event: %s", s)
return nil
View kooper-example-resource.go
// Create our retriever so the controller knows how to get/listen for pod events.
retr := &retrieve.Resource{
Object: &corev1.Pod{},
ListerWatcher: &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return k8scli.CoreV1().Pods("").List(options)
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return k8scli.CoreV1().Pods("").Watch(options)
slok / amfirer.go
Last active Jun 4, 2019
Alertmanager alarm tester. Fire a custom alert to your alertmanager:
View amfirer.go
package main
import (
# Wait until consul instance on clust
check_consul_sync() {
# If we don't have leaders _last_log_index then get it
You can’t perform that action at this time.