Skip to content

Commit

Permalink
Merge branch 'main' into chore/flag-autoscaling-v2beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant-shahi authored Sep 11, 2023
2 parents b8e0fbb + b02d19c commit 8ace748
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .chloggen/esexporter-checkapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: elasticsearchexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Do not export the function `DurationAsMicroseconds`

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26304]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
27 changes: 27 additions & 0 deletions .chloggen/k8sclusterreceiver-node-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: "enhancement"

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: k8sclusterreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add optional k8s.kubelet.version, k8s.kubeproxy.version node resource attributes"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24835]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 0 additions & 1 deletion cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exporter/awskinesisexporter
exporter/azuremonitorexporter
exporter/coralogixexporter
exporter/dynatraceexporter
exporter/elasticsearchexporter
exporter/f5cloudexporter
exporter/kafkaexporter
exporter/loadbalancingexporter
Expand Down
6 changes: 3 additions & 3 deletions exporter/elasticsearchexporter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (m *encodeModel) encodeSpan(resource pcommon.Resource, span ptrace.Span) ([
document.AddAttributes("Attributes", span.Attributes())
document.AddAttributes("Resource", resource.Attributes())
document.AddEvents("Events", span.Events())
document.AddInt("Duration", DurationAsMicroseconds(span.StartTimestamp().AsTime(), span.EndTimestamp().AsTime())) // unit is microseconds
document.AddInt("Duration", durationAsMicroseconds(span.StartTimestamp().AsTime(), span.EndTimestamp().AsTime())) // unit is microseconds

if m.dedup {
document.Dedup()
Expand All @@ -102,8 +102,8 @@ func spanLinksToString(spanLinkSlice ptrace.SpanLinkSlice) string {
return string(linkArrayBytes)
}

// DurationAsMicroseconds calculate span duration through end - start nanoseconds and converts time.Time to microseconds,
// durationAsMicroseconds calculate span duration through end - start nanoseconds and converts time.Time to microseconds,
// which is the format the Duration field is stored in the Span.
func DurationAsMicroseconds(start, end time.Time) int64 {
func durationAsMicroseconds(start, end time.Time) int64 {
return (end.UnixNano() - start.UnixNano()) / 1000
}
2 changes: 2 additions & 0 deletions receiver/k8sclusterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4
| k8s.hpa.uid | The k8s hpa uid. | Any Str | true |
| k8s.job.name | The k8s pod name. | Any Str | true |
| k8s.job.uid | The k8s job uid. | Any Str | true |
| k8s.kubelet.version | The version of Kubelet running on the node. | Any Str | false |
| k8s.kubeproxy.version | The version of Kube Proxy running on the node. | Any Str | false |
| k8s.namespace.name | The k8s namespace name. | Any Str | true |
| k8s.namespace.uid | The k8s namespace uid. | Any Str | true |
| k8s.node.name | The k8s node name. | Any Str | true |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ all_set:
enabled: true
k8s.job.uid:
enabled: true
k8s.kubelet.version:
enabled: true
k8s.kubeproxy.version:
enabled: true
k8s.namespace.name:
enabled: true
k8s.namespace.uid:
Expand Down Expand Up @@ -267,6 +271,10 @@ none_set:
enabled: false
k8s.job.uid:
enabled: false
k8s.kubelet.version:
enabled: false
k8s.kubeproxy.version:
enabled: false
k8s.namespace.name:
enabled: false
k8s.namespace.uid:
Expand Down
6 changes: 6 additions & 0 deletions receiver/k8sclusterreceiver/internal/node/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func Transform(node *corev1.Node) *corev1.Node {
ObjectMeta: metadata.TransformObjectMeta(node.ObjectMeta),
Status: corev1.NodeStatus{
Allocatable: node.Status.Allocatable,
NodeInfo: corev1.NodeSystemInfo{
KubeletVersion: node.Status.NodeInfo.KubeletVersion,
KubeProxyVersion: node.Status.NodeInfo.KubeProxyVersion,
},
},
}
for _, c := range node.Status.Conditions {
Expand Down Expand Up @@ -92,6 +96,8 @@ func CustomMetrics(set receiver.CreateSettings, rb *metadata.ResourceBuilder, no
rb.SetK8sNodeUID(string(node.UID))
rb.SetK8sNodeName(node.Name)
rb.SetOpencensusResourcetype("k8s")
rb.SetK8sKubeletVersion(node.Status.NodeInfo.KubeletVersion)
rb.SetK8sKubeproxyVersion(node.Status.NodeInfo.KubeProxyVersion)
rb.Emit().MoveTo(rm.Resource())
return rm
}
Expand Down
46 changes: 46 additions & 0 deletions receiver/k8sclusterreceiver/internal/node/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,37 @@ func TestNodeMetricsReportCPUMetrics(t *testing.T) {
),
)
}
func TestNodeOptionalMetrics(t *testing.T) {
n := testutils.NewNode("2")
rac := metadata.DefaultResourceAttributesConfig()
rac.K8sKubeletVersion.Enabled = true
rac.K8sKubeproxyVersion.Enabled = true

rb := metadata.NewResourceBuilder(rac)
rm := CustomMetrics(receivertest.NewNopCreateSettings(), rb, n,
[]string{},
[]string{
"cpu",
"memory",
},

pcommon.Timestamp(time.Now().UnixNano()),
)
m := pmetric.NewMetrics()
rm.MoveTo(m.ResourceMetrics().AppendEmpty())

expected, err := golden.ReadMetrics(filepath.Join("testdata", "expected_optional.yaml"))
require.NoError(t, err)
require.NoError(t, pmetrictest.CompareMetrics(expected, m,
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
),
)

}
func TestNodeConditionValue(t *testing.T) {
type args struct {
node *corev1.Node
Expand Down Expand Up @@ -162,6 +192,18 @@ func TestTransform(t *testing.T) {
Address: "192.168.1.100",
},
},
NodeInfo: corev1.NodeSystemInfo{
MachineID: "24736a453e8f47a1ad2f9d95d31085f5",
SystemUUID: "444005f7-e2e8-42fd-ab87-9f8496790a29",
BootID: "d7ee9a98-ff89-4eed-b723-cffd38ea6c0f",
KernelVersion: "6.4.12-arch1-1",
OSImage: "Ubuntu 22.04.1 LTS",
ContainerRuntimeVersion: "containerd://1.6.9",
KubeletVersion: "v1.25.3",
KubeProxyVersion: "v1.25.3",
OperatingSystem: "linux",
Architecture: "amd64",
},
},
}
wantNode := &corev1.Node{
Expand All @@ -183,6 +225,10 @@ func TestTransform(t *testing.T) {
corev1.ResourceCPU: resource.MustParse("4"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
NodeInfo: corev1.NodeSystemInfo{
KubeletVersion: "v1.25.3",
KubeProxyVersion: "v1.25.3",
},
},
}
assert.Equal(t, wantNode, Transform(originalNode))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resourceMetrics:
- resource:
attributes:
- key: k8s.node.name
value:
stringValue: test-node-2
- key: k8s.node.uid
value:
stringValue: test-node-2-uid
- key: k8s.kubelet.version
value:
stringValue: v1.25.3
- key: k8s.kubeproxy.version
value:
stringValue: v1.25.3
- key: opencensus.resourcetype
value:
stringValue: k8s
schemaUrl: https://opentelemetry.io/schemas/1.18.0
scopeMetrics:
- metrics:
- description: Amount of cpu allocatable on the node
gauge:
dataPoints:
- asDouble: 0.123
name: k8s.node.allocatable_cpu
unit: '{cpu}'
- description: Amount of memory allocatable on the node
gauge:
dataPoints:
- asInt: "456"
name: k8s.node.allocatable_memory
unit: By
scope:
name: otelcol/k8sclusterreceiver
version: latest
4 changes: 4 additions & 0 deletions receiver/k8sclusterreceiver/internal/testutils/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func NewNode(id string) *corev1.Node {
"hugepages-2Mi": *resource.NewQuantity(2048, resource.DecimalSI),
"hugepages-5Mi": *resource.NewQuantity(2048, resource.DecimalSI),
},
NodeInfo: corev1.NodeSystemInfo{
KubeletVersion: "v1.25.3",
KubeProxyVersion: "v1.25.3",
},
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions receiver/k8sclusterreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ resource_attributes:
type: string
enabled: true

k8s.kubelet.version:
description: The version of Kubelet running on the node.
type: string
enabled: false

k8s.kubeproxy.version:
description: The version of Kube Proxy running on the node.
type: string
enabled: false

openshift.clusterquota.uid:
description: The k8s ClusterResourceQuota uid.
type: string
Expand Down

0 comments on commit 8ace748

Please sign in to comment.