Git Product home page Git Product logo

kubernetes-telemetry's Introduction

Kong Kubernetes Telemetry

Toolkit for telemetry data for Kong's Kubernetes products, such as the Kong Kubernetes Ingress Controller (KIC).

Usage

import (
  "context"
  "time"

  "github.com/bombsimon/logrusr/v3"
  "github.com/sirupsen/logrus"
  "k8s.io/client-go/kubernetes"
  "k8s.io/client-go/rest"
  "k8s.io/client-go/tools/clientcmd"

  "github.com/kong/kubernetes-telemetry/pkg/forwarders"
  "github.com/kong/kubernetes-telemetry/pkg/serializers"
  "github.com/kong/kubernetes-telemetry/pkg/telemetry"
)

func main() {
  log := logrusr.New(logrus.New())
  m, err := telemetry.NewManager(
    "custom-ping",
    telemetry.OptManagerPeriod(time.Hour),
    telemetry.OptManagerLogger(log),
  )
  // Handle errors ...

  // Configure your Kubernetes client(s)
  loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
  // If you want to change the loading rules (which files in which order), you can do so here
  kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, nil)
  restConfig, err := kubeConfig.ClientConfig()
  // Handle errors ...
  cl, err := kubernetes.NewForConfig(restConfig)
  // Handle errors ...

  w, err := telemetry.NewIdentifyPlatformWorkflow(cl)
  // Handle errors ...
  m.AddWorkflow(w)

  // Add more workflows/providers if needed ...
  
  // Configure serialization ...
  serializer := serializers.NewSemicolonDelimited()
  // ... and forwarding
  tf, err := forwarders.NewTLSForwarder(splunkEndpoint, log)
  // Handle errors ...
  consumer := telemetry.NewConsumer(serializer, tf)
  m.AddConsumer(consumer)

  // Start the manager
  err := m.Start()
  // Handle errors ...


  // Trigger asynchronous report as needed.
  err := m.TriggerExecute(context.Background(), "custom-event-happened");
  // Handle errors ...

Forwarders

Forwarders can be used to forward serialized telemetry reports to a particular destination.

  • TLSForwarder can be used to forward data to a TLS endpoint
  • LogForwarder can be used to forward data to a configured logger instance
  • DiscardForwarder can be used to discard received reports

Serializers

Users can pick the serializer of their choice for data serialization.

Currently only 1 serializer is supported with more implementations to come as needed.

Semicolon delimited values

This serializer uses the following predefined keys to express telemetry data:

  • k8s_arch - inferred kubernetes cluster architecture
  • k8sv - inferred kubernetes cluster version
  • k8sv_semver - inferred kubernetes cluster version in semver format
  • k8s_provider - inferred kubernetes cluster provider
  • k8s_pods_count - number of pods running in the cluster
  • k8s_services_count - number of services defined in the cluster
  • hn - hostname where this telemetry framework is running on
  • feature-<NAME> - feature gate (with the boolean state indicated whether enabled or disabled)

kubernetes-telemetry's People

Contributors

dependabot[bot] avatar mflendrich avatar mheap avatar pmalek avatar programmer04 avatar rainest avatar randmonkey avatar scseanchow avatar shaneutt avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

shaneutt

kubernetes-telemetry's Issues

Ensuring de-duplication of telemetry

Just a reminder: The purpose of this issue is to ensure that we have some mechanism to de-duplicate telemetry data for multiple deployments on a single cluster. For instance, a cluster may have more than one deployment of the KIC, or may have both the Operator and a KIC reporting the same metrics for the cluster. However this is done (and it might simply just be a matter of how we report to splunk, and "last update wins") we just need to ensure that we're not counting any duplicate data.

Implement one-off reports sending

As of now only a periodic reporting is possible.

Users might want to send a one-off report (e.g. during a an app launch to report startup). This issue aims to track this functionality.

SPIKE: mesh telemetry mechanism

The purpose of this issue is to come up with strategy and enumerate the heuristics we can use to determine if and which mesh networks are present on a cluster (running KIC) and whether or not KIC/Gateway are themselves running in a mesh.

This is a precursor to the https://github.com/kong/telemetry library.

Acceptance Criteria:

  • we have a design for the heuristics that will be used to determine: is a mesh deployed? what mesh is it? is kong deployed in that mesh? WITHOUT changing RBAC permissions on KIC
  • we have a design for the heuristics that will be used to determine: is a mesh deployed? what mesh is it? is kong deployed in that mesh? Where new RBAC rules would be needed.
  • stretch: identify the % of services that are in mesh - FR separated out - #8

Getting the KEP "implementable"

The purpose of this task is to get the KEP into an implementable state with sign-off from @Kong/team-k8s. This may include a POC which drives the technical side of the document.

Cluster version provider should provide a parsed kubernetes semver

In addition to providing cluster version verbatim as returned from the /version API, cluster version provider should also return in its report a field with parsed semver of kubernetes version, so that it can be compared across cluster providers.

The reason for this is that different cloud providers have different formats for kubernetes version strings e.g.

  • GKE has the following format: v1.24.1-gke.1400
  • AWS EKS uses something like: v1.22.10-eks-84b4fe6

which cannot be compared to each other.

Research different ways of obtaining version and architecture information from cluster nodes

As of now the cluster version and architecture are gathered from the cluster using discovery's interface ServerVersion().

This only gets the information that is retrieved from the API. This wouldn't be accurate for heterogenous clusters with different versions of k8s, different architectures and/or in the middle of a cluster upgrade.

This might not be critical but will return inaccurate information which we don't want.

Initially brought up in the comment about a TODO: #12 (comment)

Address possible blocking calls in forwarders

As of now the forwarders don't use a context.Context as an argument to Forward().

This might cause issues like blocking other pieces of code whenever the consumer of the report being forwarded do not respond in a timely manner.

This could also be a problem in implementations like rawChannelForwarder where the consumer is responsible for consumption of the report in timely manner and if that's not the case then the whole pipeline can stall.

Related comment from a review: #45 (comment)

Telemetry Library - Initial POC

The purpose of this issue is to implement a POC of KEP 1. As a part of this work, we may also make some iterations upon KEP 1 and iterate on the design. It's also potentially reasonable to decline KEP 1 and look for a different approach.

`(*tlsForwarder.)Forward` causes nil pointer dereference

Problem Statement

When running KGO with telemetry enabled, the operator gets in CrashLoopBackOff status for a nil pointer dereference error.
I Installed KGO through the README guide in a Kind cluster.

Stacktrace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x15d909e]

goroutine 308 [running]:
github.com/kong/kubernetes-telemetry/pkg/forwarders.(*tlsForwarder).Forward(0x0, {0x1c71e70?, 0xc0004fe140?}, {0xc000164240, 0x104, 0x120})
	/go/pkg/mod/github.com/kong/[email protected]/pkg/forwarders/tlsforwarder.go:66 +0x5e
github.com/kong/kubernetes-telemetry/pkg/telemetry.NewConsumer.func1()
	/go/pkg/mod/github.com/kong/[email protected]/pkg/telemetry/consumer.go:49 +0x1c3
created by github.com/kong/kubernetes-telemetry/pkg/telemetry.NewConsumer
	/go/pkg/mod/github.com/kong/[email protected]/pkg/telemetry/consumer.go:35 +0x171

Add integration tests to the project

Kubernetes-telemetry is used in production by KIC, hence proper test suite should be added. Moreover creating unit tests with mocked client is tedious and may be error prone, because it requires some hack like e.g. in #143

envtest can be leveraged similarly as it's being done in KIC to spin up etcd and api-server, create those resources and assert that counters work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.