From 6fef29d15aaec912edb5bba8b63c8479452261b2 Mon Sep 17 00:00:00 2001 From: Michael Pleshakov Date: Tue, 5 Mar 2024 12:40:33 -0500 Subject: [PATCH] Define common data points (#27) Problem: Ensure that our Kubernetes-related projects share common telemetry data points for consistency. Solution: - Define common data points type. - Generate Attributes() methods to allow using the type with the Exporter (to implement Exportable interface). A project that uses the exporter library will also export the defined data type. CLOSES - https://github.com/nginxinc/telemetry-exporter/issues/8 Co-authored-by: Saylor Berman --- pkg/telemetry/data_attributes_generated.go | 9 +++++++- pkg/telemetry/exporter.go | 25 ++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pkg/telemetry/data_attributes_generated.go b/pkg/telemetry/data_attributes_generated.go index 5d24ebb..56a7f9e 100644 --- a/pkg/telemetry/data_attributes_generated.go +++ b/pkg/telemetry/data_attributes_generated.go @@ -13,7 +13,14 @@ import ( func (d *Data) Attributes() []attribute.KeyValue { var attrs []attribute.KeyValue - attrs = append(attrs, attribute.Int64("Nodes", d.Nodes)) + attrs = append(attrs, attribute.String("ProjectName", d.ProjectName)) + attrs = append(attrs, attribute.String("ProjectVersion", d.ProjectVersion)) + attrs = append(attrs, attribute.String("ProjectArchitecture", d.ProjectArchitecture)) + attrs = append(attrs, attribute.String("ClusterID", d.ClusterID)) + attrs = append(attrs, attribute.String("ClusterVersion", d.ClusterVersion)) + attrs = append(attrs, attribute.String("ClusterPlatform", d.ClusterPlatform)) + attrs = append(attrs, attribute.String("InstallationID", d.InstallationID)) + attrs = append(attrs, attribute.Int64("ClusterNodeCount", d.ClusterNodeCount)) return attrs diff --git a/pkg/telemetry/exporter.go b/pkg/telemetry/exporter.go index 2210c54..d6632fc 100644 --- a/pkg/telemetry/exporter.go +++ b/pkg/telemetry/exporter.go @@ -11,16 +11,27 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" ) -// Data includes common telemetry data points. -// FIXME(pleshakov): Define the data points. -// Currently, only one data point is added, for the only reason that we can make sure the generator -// generates code for a struct defined in this package. -// https://github.com/nginxinc/telemetry-exporter/issues/8 will define the actual data points. +// Data defines common telemetry data points for NGINX Kubernetes-related projects. // //go:generate go run -tags=generator github.com/nginxinc/telemetry-exporter/cmd/generator -type Data type Data struct { - // Nodes is a number of nodes. - Nodes int64 + // ProjectName is the name of the project. + ProjectName string + // ProjectVersion is the version of the project. + ProjectVersion string + // ProjectArchitecture is the architecture of the project. For example, "amd64". + ProjectArchitecture string + // ClusterID is the unique id of the Kubernetes cluster where the project is installed. + // It is the UID of the `kube-system` Namespace. + ClusterID string + // ClusterVersion is the Kubernetes version of the cluster. + ClusterVersion string + // ClusterPlatform is the Kubernetes platform of the cluster. + ClusterPlatform string + // InstallationID is the unique id of the project installation in the cluster. + InstallationID string + // ClusterNodeCount is the number of nodes in the cluster. + ClusterNodeCount int64 } // Exportable allows exporting telemetry data using the Exporter.