Skip to content

Commit

Permalink
Merge pull request #3 from lightstep/in-flight
Browse files Browse the repository at this point in the history
Add InFlight Checks
  • Loading branch information
jaronoff97 authored Jul 10, 2023
2 parents c9e46d3 + 9cd2fdc commit 872a6b1
Show file tree
Hide file tree
Showing 15 changed files with 547 additions and 29 deletions.
11 changes: 10 additions & 1 deletion cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"fmt"
"github.com/lightstep/collector-cluster-check/pkg/checks/runcrd"
"os"
"path/filepath"
"strings"
Expand All @@ -44,7 +45,9 @@ type checkGroup struct {
var (
kubeConfig string
accessToken string
endpoint string
http bool
insecure bool
availableChecks = map[string]checkGroup{
"metrics": {
dependencies: []dependencies.Initializer{dependencies.MetricInitializer},
Expand All @@ -62,6 +65,10 @@ var (
dependencies: []dependencies.Initializer{},
checkers: []checks.NewChecker{dns.NewLookupCheck, dns.NewDialCheck},
},
"inflight": {
dependencies: []dependencies.Initializer{dependencies.DynamicClientInitializer, dependencies.KubernetesClientInitializer, dependencies.KubeConfigInitializer, dependencies.OtelCollectorConfigInitializer, dependencies.OtelColMetricInitializer, dependencies.OtelColTraceInitializer},
checkers: []checks.NewChecker{runcrd.NewRunCollectorCheck},
},
"all": {
dependencies: []dependencies.Initializer{dependencies.KubernetesClientInitializer, dependencies.CustomResourceClientInitializer, dependencies.MetricInitializer, dependencies.TraceInitializer},
checkers: []checks.NewChecker{dns.NewLookupCheck, dns.NewDialCheck, kubernetes.NewVersionCheck, prometheus.NewCheck, certmanager.NewCheck, oteloperator.NewCheck, lightstep.NewMetricCheck, lightstep.NewTraceCheck},
Expand Down Expand Up @@ -108,7 +115,7 @@ var checkCmd = &cobra.Command{
var results map[string]checks.CheckerResult
var opts []checks.RunnerOption
for _, d := range group.dependencies {
runnerOption, checkResult := d.Apply(cmd.Context(), http, accessToken, kubeConfig)
runnerOption, checkResult := d.Apply(cmd.Context(), endpoint, insecure, http, accessToken, kubeConfig)
depResults = append(depResults, checkResult)
if checkResult.IsFailure() {
return
Expand Down Expand Up @@ -174,7 +181,9 @@ func init() {
checkCmd.PersistentFlags().StringVarP(&kubeConfig, "kubeconfig", "", "", "absolute path to the kubeconfig file")
}
checkCmd.PersistentFlags().StringVarP(&accessToken, "accessToken", "", os.Getenv("LS_TOKEN"), "access token to send data to Lightstep")
checkCmd.PersistentFlags().StringVarP(&endpoint, "endpoint", "", "ingest.lightstep.com:443", "destination for OTLP data")
checkCmd.PersistentFlags().BoolVarP(&http, "http", "", false, "should telemetry be sent over http")
checkCmd.PersistentFlags().BoolVarP(&insecure, "insecure", "", false, "should telemetry be sent insecurely")

// Here you will define your flags and configuration settings.

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -169,6 +170,7 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 h1:BZHcxBETFHIdVyhyEfOvn/RdU/QGdLI4y34qQGjGWO0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks=
Expand Down Expand Up @@ -209,6 +211,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
34 changes: 29 additions & 5 deletions pkg/checks/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package checks

import (
"context"

sdkmetric "go.opentelemetry.io/otel/sdk/metric"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"

apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -47,10 +50,13 @@ type Checker interface {
}

type Config struct {
KubeClient *kubernetes.Clientset
CustomResourceClient *apiextensionsclientset.Clientset
KubeClient kubernetes.Interface
CustomResourceClient apiextensionsclientset.Interface
DynamicClient dynamic.Interface
MeterProvider *sdkmetric.MeterProvider
TracerProvider *sdktrace.TracerProvider
OtelColConfig *unstructured.Unstructured
KubeConf *rest.Config
}

type NewChecker func(c *Config) Checker
Expand All @@ -72,13 +78,31 @@ func NewRunner(checkers []NewChecker, opts ...RunnerOption) *Runner {
return r
}

func WithKubernetesClient(client *kubernetes.Clientset) RunnerOption {
func WithKubeConfig(conf *rest.Config) RunnerOption {
return func(r *Runner) {
r.conf.KubeConf = conf
}
}

func WithDynamicClient(client dynamic.Interface) RunnerOption {
return func(r *Runner) {
r.conf.DynamicClient = client
}
}

func WithOtelColConfig(conf *unstructured.Unstructured) RunnerOption {
return func(r *Runner) {
r.conf.OtelColConfig = conf
}
}

func WithKubernetesClient(client kubernetes.Interface) RunnerOption {
return func(r *Runner) {
r.conf.KubeClient = client
}
}

func WithCustomResourceClient(client *apiextensionsclientset.Clientset) RunnerOption {
func WithCustomResourceClient(client apiextensionsclientset.Interface) RunnerOption {
return func(r *Runner) {
r.conf.CustomResourceClient = client
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/checks/lightstep/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c MetricChecker) Run(ctx context.Context) checks.CheckerResult {
counter.Add(ctx, 1)
err = c.mp.ForceFlush(ctx)
if err != nil && strings.Contains(err.Error(), "DeadlineExceeded") {
return append(results, checks.NewFailedCheck(traceFlush, deadlineExceeded, err))
return append(results, checks.NewFailedCheck(metricFlush, deadlineExceeded, err))
} else if err != nil {
return append(results, checks.NewFailedCheck(metricFlush, badFlushMessage, err))
}
Expand Down
Loading

0 comments on commit 872a6b1

Please sign in to comment.