Skip to content

Instantly share code, notes, and snippets.

Registration of Kubernetes API objects

Definition of terms: API Object - This is anything that a Kubernetes cluster would know about, examples are Pods, Deployments, Services, DeploymentLists. It can be extended by Custom Resource Definitions (CRDs) GroupVersionKind (GVK) - This is the identifier of an API Object. eg Core/V1/Pod GroupVersionResource (GVR) - This is an identifier for one particular GVK pods.core.v1 Schema - This is an object that understands how to translate a Go struct into the GroupVersionKind for the API object that struct represents and back. This is used in the encoding and decoding process.

When you use Kubernetes types in a go program you will import somthing like "k8s.io/apimachinery/pkg/apis/core/v1". In that package it will have something to register that API's known types. This SchemaBuilder, and the schemas from other types are used by the kubernetes client (and th

@MadVikingGod
MadVikingGod / go.work
Created March 23, 2022 21:28
go.work file for opentelemetry-go and it's contrib
go 1.18
use (
opentelemetry-go
opentelemetry-go/bridge/opencensus
opentelemetry-go/bridge/opencensus/test
opentelemetry-go/bridge/opentracing
opentelemetry-go/example/fib
opentelemetry-go/example/jaeger
opentelemetry-go/example/namedtracer
  • sdk/metric/number
  • sdk/metric/number/traits
    • "go.opentelemetry.io/otel/sdk/metric/number"
  • sdk/metric/sdkinstrument
    • "go.opentelemetry.io/otel/sdk/metric/number"
  • sdk/metric/aggregator/aggregation
    • "go.opentelemetry.io/otel/sdk/metric/number"
    • "go.opentelemetry.io/otel/sdk/metric/sdkinstrument"
  • sdk/metric/aggregator
  • "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregation"
@MadVikingGod
MadVikingGod / main.go
Created June 7, 2022 15:06
example of #2946
package main
import (
"context"
"fmt"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/sdk/trace"
benchstat bench-old bench-new
name old time/op new time/op delta
Int64Sum/count-10-4 7.81µs ±37% 3.29µs ± 5% -57.85% (p=0.000 n=10+10)
Int64Sum/count-50-4 36.1µs ±31% 15.6µs ± 7% -56.85% (p=0.000 n=10+10)
Int64Sum/count-100-4 64.7µs ± 5% 31.0µs ± 4% -52.17% (p=0.000 n=8+10)
Float64Sum/count-10-4 8.22µs ±31% 3.50µs ± 2% -57.45% (p=0.000 n=10+10)
Float64Sum/count-50-4 36.2µs ±29% 16.6µs ± 5% -54.13% (p=0.000 n=9+10)
Float64Sum/count-100-4 69.9µs ±15% 33.3µs ± 4% -52.37% (p=0.000 n=8+10)
Int64SumParallel-4 11.4ms ±19% 0.0ms ±51% -99.59% (p=0.000 n=9+10)
Float64SumParallel-4 12.3ms ±31% 0.1ms ±60% -99.57% (p=0.000 n=10+10)
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@MadVikingGod
MadVikingGod / example.md
Created August 19, 2022 16:07
otel AssertEqual outputs

This is an example of how test data compares when using different levels of metricdatatest.AssertEqual.

Asserting at the Metrics level

var tt.want metricsdata.Metrics
var rm metricsdata.ResourceMetrics // This was from Collect()

require.Len(t, rm.ScopeMetrics, 1)
sm := rm.ScopeMetrics[0]

Metric Test Cases

This is a list of language independent test cases to help validate an SDK's behavior. It's intended to enumerate some of the interactions of different parts of the specification.

Async Counters with Attribute Filters

Instrument

Async Counter

@MadVikingGod
MadVikingGod / Error
Created November 21, 2022 21:48
Attribute test
--- FAIL: TestIncorrectCast (0.00s)
--- FAIL: TestIncorrectCast/Float64 (0.00s)
kv_test.go:169:
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic
Panic value: reflect: call of reflect.Value.Type on zero Value
Panic stack: goroutine 48 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/stretchr/testify/assert.didPanic.func1()
11:cpuset:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
10:hugetlb:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
9:pids:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
8:memory:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
7:net_cls,net_prio:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
6:perf_event:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
5:blkio:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249ae8506/58a77afcbf0b16959d526758f6696677c862517acc97a562dc5c5b09afbf5236
4:devices:/kubepods/besteffort/pod28478e30-384f-41e5-9d85-eae249a