From e852880a3b1345aa6ca88b437a7442d4a0564bef Mon Sep 17 00:00:00 2001 From: Michael Pleshakov Date: Thu, 29 Feb 2024 11:28:59 -0500 Subject: [PATCH] Define common data points 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 --- 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..e576a31 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("DeploymentID", d.DeploymentID)) + attrs = append(attrs, attribute.Int64("ClusterNodeCount", d.ClusterNodeCount)) return attrs diff --git a/pkg/telemetry/exporter.go b/pkg/telemetry/exporter.go index 2210c54..4420bb1 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 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 + // DeploymentID is the unique id of the project installation in the cluster. + DeploymentID string + // ClusterNodeCount is the number of nodes in the cluster. + ClusterNodeCount int64 } // Exportable allows exporting telemetry data using the Exporter.