From 9f16b230c8a79c6627b6b8c02fcfce88873e4d66 Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Mon, 16 Nov 2026 16:38:09 +0100 Subject: [PATCH 1/8] Present ResourceCollection selection feedback in Kubernetes CRD topology Give collection declarations a dedicated mapping and presentation with generation, readiness and selection results. Keep ordinary custom resources on their existing mapping. Add real CEL mapping and platform presentation checks. Refs StackVista/stackstate#828. --- .github/workflows/stackpacks-ci.yml | 29 +++ .../resources/detailed-overview.md | 12 ++ .../component-mappings/custom-resources.sty | 5 +- .../resource-collections.sty | 93 +++++++++ .../presentations/custom-resources.sty | 5 +- .../presentations/resource-collections.sty | 147 ++++++++++++++ stackpacks/otel-k8s-crd/stackpack.yaml | 2 +- tests/otel-k8s-crd/README.md | 36 ++++ .../ResourceCollectionPresentationTest.java | 149 ++++++++++++++ tests/otel-k8s-crd/presentation.py | 61 ++++++ .../otel-k8s-crd/resource_collections_test.go | 183 ++++++++++++++++++ tests/otel-k8s-crd/run.py | 52 +++++ 12 files changed, 771 insertions(+), 3 deletions(-) create mode 100644 stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty create mode 100644 stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty create mode 100644 tests/otel-k8s-crd/README.md create mode 100644 tests/otel-k8s-crd/ResourceCollectionPresentationTest.java create mode 100644 tests/otel-k8s-crd/presentation.py create mode 100644 tests/otel-k8s-crd/resource_collections_test.go create mode 100644 tests/otel-k8s-crd/run.py diff --git a/.github/workflows/stackpacks-ci.yml b/.github/workflows/stackpacks-ci.yml index 1fa3219..d9bb103 100644 --- a/.github/workflows/stackpacks-ci.yml +++ b/.github/workflows/stackpacks-ci.yml @@ -107,6 +107,35 @@ jobs: cat "${output}" grep -q "undeclared.*undeclaredValidationControl" "${output}" + - name: Check out the pinned collector mapping engine + if: matrix.stackpack == 'otel-k8s-crd' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + repository: StackVista/sts-opentelemetry-collector + ref: 9be47421ee2a5eaf9d5643e98374c72eb4d30047 + path: .ci/collector + persist-credentials: false + + - name: Set up the collector's Go toolchain + if: matrix.stackpack == 'otel-k8s-crd' + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: .ci/collector/connector/topologyconnector/go.mod + cache: false + + - name: Test ResourceCollection mapping and presentation + if: matrix.stackpack == 'otel-k8s-crd' + env: + GOTOOLCHAIN: local + run: | + python3 tests/otel-k8s-crd/run.py --collector-source .ci/collector + test -x "${JAVA_HOME_21_X64}/bin/java" + test -x "${JAVA_HOME_21_X64}/bin/javac" + python3 tests/otel-k8s-crd/presentation.py \ + --validator-image "${VALIDATOR_IMAGE}" \ + --java "${JAVA_HOME_21_X64}/bin/java" \ + --javac "${JAVA_HOME_21_X64}/bin/javac" + package: name: package (${{ matrix.stackpack }}) needs: [discover-stackpacks, validate, check-version-bump] diff --git a/stackpacks/otel-k8s-crd/resources/detailed-overview.md b/stackpacks/otel-k8s-crd/resources/detailed-overview.md index 9de123d..03f550a 100644 --- a/stackpacks/otel-k8s-crd/resources/detailed-overview.md +++ b/stackpacks/otel-k8s-crd/resources/detailed-overview.md @@ -11,6 +11,18 @@ The StackPack defines SUSE Observability settings (component and relation mappin - **instance of** - Links each Custom Resource to its defining Custom Resource Definition +### Resource collections + +ResourceCollection declarations appear in the **Resource Collections** overview +under **Kubernetes**. Their highlights show collection state, reason, details and +the declaration and observed generations. Configuration contains the selections; +status contains the collector's per-selection feedback. + +**Awaiting reconciliation** means the available feedback does not describe the +current declaration generation. **Collecting**, **Pending** and **Blocked** reflect +the collector's Ready condition. A blocked declaration can still collect its +permitted selections; collection state is separate from component health. + ### Data sources - CRD and CR discovery via the Kubernetes API server diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty index 077b0e0..539077b 100644 --- a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty @@ -10,7 +10,10 @@ nodes: scope: log: action: "log.body['type'] in ['ADDED', 'MODIFIED'] ? 'CREATE' : log.body['type'] == 'DELETED' ? 'DELETE' : 'CONTINUE'" - condition: log.eventName == 'KubernetesCustomResourceEvent' + condition: >- + log.eventName == 'KubernetesCustomResourceEvent' && + !(log.attributes['k8s.resource.group'] == 'observability.suse.com' && + log.attributes['k8s.resource.kind'] == 'ResourceCollection') vars: - name: "clusterName" value: "resource.attributes['k8s.cluster.name']" diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty new file mode 100644 index 0000000..05da7c5 --- /dev/null +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty @@ -0,0 +1,93 @@ +nodes: + - _type: "OtelComponentMapping" + name: "Kubernetes Resource Collection" + description: "Collection declarations and their generation-bound feedback" + identifier: "urn:stackpack:otel-k8s-crd:otel-component-mapping:resource-collection" + input: + signal: + - "LOGS" + resource: + scope: + log: + action: "log.body['type'] in ['ADDED', 'MODIFIED'] ? 'CREATE' : log.body['type'] == 'DELETED' ? 'DELETE' : 'CONTINUE'" + condition: >- + log.eventName == 'KubernetesCustomResourceEvent' && + log.attributes['k8s.resource.group'] == 'observability.suse.com' && + log.attributes['k8s.resource.kind'] == 'ResourceCollection' + vars: + - name: "clusterName" + value: "resource.attributes['k8s.cluster.name']" + - name: "name" + value: "log.attributes['k8s.object.name']" + - name: "object" + value: "log.body['object']" + - name: "status" + value: "'status' in log.body['object'] ? log.body['object']['status'] : {}" + - name: "readyConditions" + value: >- + 'status' in log.body['object'] && 'conditions' in log.body['object']['status'] + ? log.body['object']['status']['conditions'].filter(c, c['type'] == 'Ready') + : [] + - name: "generation" + value: >- + 'generation' in log.body['object']['metadata'] + ? log.body['object']['metadata']['generation'] : 0 + output: + identifier: "'urn:k8s:cr:/cluster/' + vars.clusterName + ':namespace/:group/observability.suse.com:kind/ResourceCollection:name/' + vars.name" + name: "vars.name" + typeName: "'custom resource'" + required: + configuration: "omit(vars.object, ['status', 'metadata'])" + tags: + - source: "'otel-k8s-crd'" + target: "stackpack" + - source: "'ResourceCollection'" + target: "k8s.resource.kind" + - source: "'observability.suse.com'" + target: "k8s.resource.group" + - source: "vars.name" + target: "k8s.resource.name" + - source: "vars.clusterName" + target: "cluster-name" + - source: >- + !(vars.generation > 0 && 'observedGeneration' in vars.status && + vars.status['observedGeneration'] == vars.generation && + size(vars.readyConditions) > 0 && + 'observedGeneration' in vars.readyConditions[0] && + vars.readyConditions[0]['observedGeneration'] == vars.generation) ? 'Awaiting reconciliation' : + vars.readyConditions[0]['status'] == 'True' ? 'Collecting' : + vars.readyConditions[0]['status'] == 'False' + ? (vars.readyConditions[0]['reason'] == 'ResourcesPending' ? 'Pending' : 'Blocked') + : 'Unknown' + target: "k8s.collection.state" + optional: + status: "vars.status" + tags: + - source: >- + (vars.generation > 0 && 'observedGeneration' in vars.status && + vars.status['observedGeneration'] == vars.generation && + size(vars.readyConditions) > 0 && + 'observedGeneration' in vars.readyConditions[0] && + vars.readyConditions[0]['observedGeneration'] == vars.generation) + ? vars.readyConditions[0]['reason'] : '' + target: "k8s.collection.reason" + - source: >- + (vars.generation > 0 && 'observedGeneration' in vars.status && + vars.status['observedGeneration'] == vars.generation && + size(vars.readyConditions) > 0 && + 'observedGeneration' in vars.readyConditions[0] && + vars.readyConditions[0]['observedGeneration'] == vars.generation) + ? vars.readyConditions[0]['message'] + : 'Waiting for feedback on the current declaration.' + target: "k8s.collection.message" + - source: "string(vars.object['metadata']['generation'])" + target: "k8s.collection.generation" + - source: "string(vars.status['observedGeneration'])" + target: "k8s.collection.observed-generation" + - source: "string(size(vars.object['spec']['resources']))" + target: "k8s.collection.selections" + - source: "vars.object['metadata']['creationTimestamp']" + target: "k8s.creationTimestamp" + expireAfter: 900000 + rank: + specificity: 100 diff --git a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty index c4d3162..8fa12dd 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty @@ -5,7 +5,10 @@ nodes: identifier: "urn:stackpack:otel-k8s-crd:component-presentation:custom-resource" binding: _type: ComponentPresentationQueryBinding - query: (label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource") + query: >- + label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource" + and not (label = "k8s.resource.group:observability.suse.com" + and label = "k8s.resource.kind:ResourceCollection") rank: specificity: 10 presentation: diff --git a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty new file mode 100644 index 0000000..b2540d9 --- /dev/null +++ b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty @@ -0,0 +1,147 @@ +nodes: + - _type: ComponentPresentation + name: "Resource Collection" + description: "Presentation for Kubernetes collection declarations" + identifier: "urn:stackpack:otel-k8s-crd:component-presentation:resource-collection" + binding: + _type: ComponentPresentationQueryBinding + query: >- + label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource" + and label = "k8s.resource.group:observability.suse.com" + and label = "k8s.resource.kind:ResourceCollection" + rank: + specificity: 20 + presentation: + icon: !icon cr.svg + filters: + - filterId: "crd_cluster" + topology: + groupingEnabled: true + showIndirectRelations: false + minimumGroupSize: 8 + groupedByLayers: false + groupedByDomains: true + autoGrouping: true + connectedComponents: true + overview: + name: + singular: "resource collection" + plural: "resource collections" + title: "Resource Collections" + mainMenu: + group: "Kubernetes" + order: 0 + columns: + - columnId: cr_name + title: "Name" + projection: + _type: ComponentLinkProjection + name: "name" + identifier: "identifiers[0]" + - columnId: collection_state + title: "Collection" + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.state')" + - columnId: collection_reason + title: "Reason" + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.reason')" + - columnId: collection_selections + title: "Selections" + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.selections')" + - columnId: cr_cluster + title: "Cluster" + projection: + _type: TextProjection + value: "tags.singleValue('cluster-name')" + - columnId: cr_age + title: "Age" + projection: + _type: DurationProjection + startTime: "tags.singleValue('k8s.creationTimestamp')" + highlight: + title: "Resource Collection" + fields: + - fieldId: collection_state + title: "Collection" + order: 100.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.state')" + - fieldId: collection_reason + title: "Reason" + order: 95.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.reason')" + - fieldId: collection_message + title: "Collection details" + order: 90.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.message')" + - fieldId: collection_generation + title: "Declaration generation" + order: 80.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.generation')" + - fieldId: collection_observed_generation + title: "Observed generation" + order: 75.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.observed-generation')" + - fieldId: collection_selections + title: "Selections" + order: 70.0 + projection: + _type: TextProjection + value: "tags.singleValue('k8s.collection.selections')" + - fieldId: kind + title: "Kind" + order: 60.0 + projection: + _type: ComponentLinkProjection + name: "tags.singleValue('k8s.resource.kind')" + identifier: "'urn:k8s:crd:/cluster/' + tags.singleValue('cluster-name') + ':group/' + tags.singleValue('k8s.resource.group') + ':kind/' + tags.singleValue('k8s.resource.kind')" + - fieldId: cluster + title: "Cluster" + order: 50.0 + projection: + _type: TextProjection + value: "tags.singleValue('cluster-name')" + - fieldId: age + title: "Age" + order: 40.0 + projection: + _type: DurationProjection + startTime: "tags.singleValue('k8s.creationTimestamp')" + - fieldId: labels + title: "Labels" + order: 10.0 + projection: + _type: TagProjection + provisioning: + topologySourceSelector: "source.identifier == identifiers[0]" + showConfiguration: true + showStatus: true + relatedResources: + - resourceId: "cr_definition" + title: "Custom Resource Definition" + order: 1.0 + topologyQuery: >- + (withNeighborsOf(direction = "both", + components = (identifier = "${identifiers[0]}"), + levels = "1")) and label = "source-type:custom resource definition" + presentationIdentifier: "urn:stackpack:otel-k8s-crd:component-presentation:custom-resource-definition" + events: + showEvents: true + relatedResourcesQuery: | + identifier = "${identifiers[0]}" + OR + (withNeighborsOf(direction = "both", components = (identifier = "${identifiers[0]}"), levels = "1") and label = "source-type:custom resource definition") diff --git a/stackpacks/otel-k8s-crd/stackpack.yaml b/stackpacks/otel-k8s-crd/stackpack.yaml index e82813d..d9ff15a 100644 --- a/stackpacks/otel-k8s-crd/stackpack.yaml +++ b/stackpacks/otel-k8s-crd/stackpack.yaml @@ -1,5 +1,5 @@ name: "otel-k8s-crd" -version: "0.0.9" +version: "0.0.10" schemaVersion: "2.0" displayName: "Kubernetes Custom Resources" categories: [ "Kubernetes" ] diff --git a/tests/otel-k8s-crd/README.md b/tests/otel-k8s-crd/README.md new file mode 100644 index 0000000..780e723 --- /dev/null +++ b/tests/otel-k8s-crd/README.md @@ -0,0 +1,36 @@ +The mapping regression uses the supplied collector checkout's CEL evaluator and +mapper. It copies the topology connector into a temporary directory and reads +its dependencies without changing the checkout. + +```sh +python3 tests/otel-k8s-crd/run.py \ + --collector-source /path/to/sts-opentelemetry-collector \ + --go /path/to/the/collectors/go +``` + +It covers current and stale Ready conditions, missing feedback, pending and +blocked collection, retained configuration/status, generic CR selection and +identity-only deletion. Run the platform validator separately to check the +presentation schema and expressions. + +These checks do not establish installation, backend persistence or rendered UI +behavior. They require a collector revision compatible with the StackPack and +run in the existing CI validation job for `otel-k8s-crd`, before packaging. +The workflow pins the collector engine revision and derives its Go toolchain +from that revision's module file. + +The presentation regression uses the platform image's actual STQL matching, +highlight evaluation, overview composition and CRD query specialization. Use +the validator image from the repository workflow, pinned by digest, and JDK 21: + +```sh +python3 tests/otel-k8s-crd/presentation.py \ + --validator-image 'quay.io/stackstate/stackstate-server@sha256:' +``` + +It extracts the image's libraries into a temporary directory and leaves the +platform checkout untouched. It verifies the collection states, missing observed +generation, name/cluster/age columns, and absence of namespace fields. These local +API checks do not prove persistence or browser rendering. +CI runs the same presentation check with JDK 21 from the GitHub-hosted runner and +the existing validator image pinned by digest. diff --git a/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java b/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java new file mode 100644 index 0000000..853f217 --- /dev/null +++ b/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java @@ -0,0 +1,149 @@ +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.stackstate.api.CnfSubQueryMatcher; +import com.stackstate.api.generated.model.ComponentField; +import com.stackstate.api.generated.model.ErrorField; +import com.stackstate.api.generated.model.TextField; +import com.stackstate.api.service.components.FieldContext; +import com.stackstate.api.service.components.FieldExtractor; +import com.stackstate.api.service.components.ParsedComponentField; +import com.stackstate.api.service.components.RelatedResourceExtractor; +import com.stackstate.api.service.overview.OverviewColumnDefinitionWithExpressions; +import com.stackstate.api.service.overview.OverviewPresentationDef; +import com.stackstate.api.service.overview.OverviewPresentationDefs; +import com.stackstate.api.service.overview.PresentationOverviewBuilder; +import com.stackstate.domain.state.HealthStateValue; +import com.stackstate.dto.dtos.componentpresentation.ComponentPresentation; +import com.stackstate.metrics.promql.PromQLParser; +import com.stackstate.metrics.promql.PromQLParserImpl; +import com.stackstate.settings.protocol.ComponentPresentationQueryBinding; +import com.stackstate.settings.protocol.ComponentPresentationRank; +import com.stackstate.settings.protocol.PresentationDefinition; +import com.stackstate.settings.provider.SettingsProvider; +import com.stackstate.stql.ErrorMessageParser$; +import org.apache.pekko.event.LoggingAdapter; +import org.apache.pekko.event.NoLogging$; +import scala.Option; +import scala.Tuple2; +import scala.collection.immutable.List; +import scala.collection.immutable.Seq; +import scala.collection.immutable.Set; +import scala.jdk.javaapi.CollectionConverters; +import spray.json.JsonParser; +import spray.json.ParserInput; + +import java.lang.reflect.Method; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Map; + +public class ResourceCollectionPresentationTest implements PresentationOverviewBuilder { + public SettingsProvider settingsProvider() { return null; } + public PromQLParser promqlParser() { return new PromQLParserImpl(); } + public LoggingAdapter log() { return NoLogging$.MODULE$; } + + private static void check(boolean value, String message) { + if (!value) throw new AssertionError(message); + } + + private static Seq seq(java.util.List values) { + return List.from(CollectionConverters.asScala(values)); + } + + private static ComponentPresentation read(Path path) throws Exception { + JsonNode node = new ObjectMapper(new YAMLFactory()).readTree(path.toFile()).get("nodes").get(0); + PresentationDefinition definition = PresentationDefinition.formatter().read( + JsonParser.apply(ParserInput.apply(node.get("presentation").toString()))); + return new ComponentPresentation( + Option.empty(), Option.empty(), node.get("name").asText(), Option.empty(), + Option.apply(node.get("identifier").asText()), Option.empty(), + new ComponentPresentationQueryBinding(node.get("binding").get("query").asText()), + Option.apply(new ComponentPresentationRank(node.get("rank").get("specificity").asDouble())), + Option.empty(), definition); + } + + private static boolean matches(ComponentPresentation candidate, ComponentPresentation base) { + return CnfSubQueryMatcher.isSubquery( + ErrorMessageParser$.MODULE$.parseTry(candidate.binding().query()).get(), + ErrorMessageParser$.MODULE$.parseTry(base.binding().query()).get()); + } + + private static FieldContext context(String state, boolean observed) { + var tags = new ArrayList(java.util.List.of( + "stackpack:otel-k8s-crd", "source-type:custom resource", + "k8s.resource.group:observability.suse.com", "k8s.resource.kind:ResourceCollection", + "cluster-name:fixture", "k8s.creationTimestamp:2026-11-13T12:00:00Z", + "k8s.collection.state:" + state, "k8s.collection.reason:FixtureReason", + "k8s.collection.message:Fixture feedback.", "k8s.collection.generation:2", + "k8s.collection.selections:1")); + if (observed) tags.add("k8s.collection.observed-generation:2"); + return new FieldContext( + 1, "virtualization", + Set.from(CollectionConverters.asScala(java.util.Set.of( + "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization"))), + Set.from(CollectionConverters.asScala(tags)), + scala.collection.immutable.Map.from(CollectionConverters.asScala(Map.of())), + "", "", "custom resource", HealthStateValue.CLEAR, Option.empty()); + } + + public static void main(String[] args) throws Exception { + Path presentations = Path.of(args[0], "settings", "presentations"); + ComponentPresentation specialized = read(presentations.resolve("resource-collections.sty")); + ComponentPresentation generic = read(presentations.resolve("custom-resources.sty")); + ComponentPresentation filters = read(presentations.resolve("common-filters.sty")); + check(!matches(generic, specialized), "Generic CR presentation also matches ResourceCollections"); + check(matches(filters, specialized), "Common cluster filter does not match"); + var matched = seq(java.util.List.of(specialized, filters)); + var parsed = FieldExtractor.parseFields(matched, Option.empty()); + check(parsed._1().isEmpty(), "Highlight parse errors: " + parsed._1()); + var fieldIds = new ArrayList(); + for (ParsedComponentField field : CollectionConverters.asJava(parsed._2())) { + fieldIds.add(field.fieldId()); + } + check(!fieldIds.contains("namespace"), "Cluster-scoped declarations show namespace"); + check(fieldIds.containsAll(java.util.List.of( + "collection_state", "collection_reason", "collection_message", "collection_generation", + "collection_observed_generation", "collection_selections", "kind", "cluster", "age", "labels")), + "Missing highlight fields: " + fieldIds); + System.out.println("PASS presentation matching and highlight composition"); + + for (String state : java.util.List.of("Collecting", "Pending", "Blocked", "Unknown", "Awaiting reconciliation")) { + var evaluated = FieldExtractor.evaluate(parsed._2(), context(state, !state.equals("Awaiting reconciliation")), + new PromQLParserImpl()); + var values = new java.util.HashMap(); + for (ComponentField field : CollectionConverters.asJava(evaluated)) { + check(!(field instanceof ErrorField), "Highlight evaluation error for " + state + ": " + field); + if (field instanceof TextField text) values.put(text.fieldId(), text.value()); + } + check(state.equals(values.get("collection_state")), "Incorrect collection state: " + values); + check("fixture".equals(values.get("cluster")), "Missing cluster: " + values); + check("Fixture feedback.".equals(values.get("collection_message")), "Missing feedback: " + values); + System.out.println("PASS highlight values: " + state); + } + + Method merge = PresentationOverviewBuilder.class.getDeclaredMethod( + "mergePresentationsAndBuildColumnDef", OverviewPresentationDefs.class); + merge.setAccessible(true); + var base = new OverviewPresentationDef(specialized.identifier().get(), specialized.rank().get().specificity(), + ErrorMessageParser$.MODULE$.parseTry(specialized.binding().query()).get(), + specialized.presentation().overview().get()); + @SuppressWarnings("unchecked") + var overview = (Tuple2, Seq>) merge.invoke( + new ResourceCollectionPresentationTest(), new OverviewPresentationDefs(base, seq(java.util.List.of()))); + check(overview._1().isEmpty(), "Overview projection errors: " + overview._1()); + var columns = new ArrayList(); + for (var column : CollectionConverters.asJava(overview._2())) columns.add(column.columnId()); + check(columns.equals(java.util.List.of( + "cr_name", "collection_state", "collection_reason", "collection_selections", "cr_cluster", "cr_age")), + "Incorrect overview columns: " + columns); + System.out.println("PASS overview column composition"); + + var relations = RelatedResourceExtractor.resolve(matched, Option.empty(), context("Collecting", true)); + check(relations.size() == 1, "Missing or duplicate CRD detail link: " + relations); + check(relations.head().toString().contains( + "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization"), + "CRD query did not specialize the component identifier: " + relations); + System.out.println("PASS CRD related-resource query specialization"); + } +} diff --git a/tests/otel-k8s-crd/presentation.py b/tests/otel-k8s-crd/presentation.py new file mode 100644 index 0000000..5dde2af --- /dev/null +++ b/tests/otel-k8s-crd/presentation.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +"""Check presentation composition using the platform validator image's API code.""" + +import argparse +import os +from pathlib import Path +import re +import subprocess +import tempfile + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--validator-image", required=True) + parser.add_argument("--pack-directory", type=Path) + parser.add_argument("--java", default="java") + parser.add_argument("--javac", default="javac") + args = parser.parse_args() + if not re.search(r"@sha256:[a-f0-9]{64}$", args.validator_image): + parser.error("--validator-image must be pinned by digest") + tests = Path(__file__).resolve().parent + pack = args.pack_directory or tests.parents[1] / "stackpacks" / "otel-k8s-crd" + with tempfile.TemporaryDirectory(prefix="resource-collection-presentation-") as temporary: + root = Path(temporary) + container = subprocess.check_output( + ["docker", "create", "--network", "none", args.validator_image], + text=True, + ).strip() + try: + subprocess.run( + ["docker", "cp", f"{container}:/opt/docker/lib", str(root)], + check=True, + ) + finally: + subprocess.run( + ["docker", "rm", container], check=True, stdout=subprocess.DEVNULL, + ) + classes = root / "classes" + classes.mkdir() + libraries = str(root / "lib" / "*") + subprocess.run( + [ + args.javac, "-proc:none", "-cp", libraries, "-d", str(classes), + str(tests / "ResourceCollectionPresentationTest.java"), + ], + cwd=root, check=True, + ) + logging = root / "logback.xml" + logging.write_text('\n') + subprocess.run( + [ + args.java, f"-Dlogback.configurationFile={logging}", + "-cp", str(classes) + os.pathsep + libraries, + "ResourceCollectionPresentationTest", str(pack.resolve()), + ], + cwd=root, check=True, + ) + + +if __name__ == "__main__": + main() diff --git a/tests/otel-k8s-crd/resource_collections_test.go b/tests/otel-k8s-crd/resource_collections_test.go new file mode 100644 index 0000000..e855a7d --- /dev/null +++ b/tests/otel-k8s-crd/resource_collections_test.go @@ -0,0 +1,183 @@ +package internal + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stackvista/sts-opentelemetry-collector/connector/topologyconnector/metrics" + "github.com/stackvista/sts-opentelemetry-collector/extension/settingsproviderextension/generated/settingsproto" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" +) + +func readStackPackMapping(t *testing.T, name string) settingsproto.OtelComponentMapping { + t.Helper() + body, err := os.ReadFile(filepath.Join(os.Getenv("RESOURCE_COLLECTION_STACKPACK"), + "settings", "component-mappings", name+".sty")) + require.NoError(t, err) + var document struct { + Nodes []map[string]any `yaml:"nodes"` + } + require.NoError(t, yaml.Unmarshal(body, &document)) + node := document.Nodes[0] + expression := func(value any) map[string]any { + return map[string]any{"expression": value} + } + for _, variable := range node["vars"].([]any) { + entry := variable.(map[string]any) + entry["value"] = expression(entry["value"]) + } + log := node["input"].(map[string]any)["resource"].(map[string]any)["scope"].(map[string]any)["log"].(map[string]any) + for _, key := range []string{"condition", "action"} { + log[key] = expression(log[key]) + } + output := node["output"].(map[string]any) + for _, key := range []string{"identifier", "name", "typeName"} { + output[key] = expression(output[key]) + } + for _, field := range []string{"required", "optional"} { + block := output[field].(map[string]any) + for _, key := range []string{"configuration", "status"} { + if value, found := block[key]; found { + block[key] = expression(value) + } + } + for _, tag := range block["tags"].([]any) { + entry := tag.(map[string]any) + entry["source"] = expression(entry["source"]) + } + } + body, err = json.Marshal(node) + require.NoError(t, err) + var mapping settingsproto.OtelComponentMapping + require.NoError(t, json.Unmarshal(body, &mapping)) + return mapping +} + +func TestStackPackResourceCollections(t *testing.T) { + evaluator, err := NewCELEvaluator(context.Background(), metrics.MeteredCacheSettings{ + Name: "stackpack_resource_collections", EnableMetrics: false, + }) + require.NoError(t, err) + mapper := NewMapper(context.Background(), + metrics.MeteredCacheSettings{Name: "tags", EnableMetrics: false}, + metrics.MeteredCacheSettings{Name: "templates", EnableMetrics: false}) + specialized := readStackPackMapping(t, "resource-collections") + generic := readStackPackMapping(t, "custom-resources") + tests := []struct { + name, ready, reason, expected string + observed, conditionGeneration int64 + }{ + {"no status", "", "", "Awaiting reconciliation", -1, -1}, + {"empty status", "", "", "Awaiting reconciliation", 0, 0}, + {"missing Ready", "", "", "Awaiting reconciliation", 2, 2}, + {"collecting", "True", "CollectionActive", "Collecting", 2, 2}, + {"pending API", "False", "ResourcesPending", "Pending", 2, 2}, + {"blocked reads", "False", "CollectionBlocked", "Blocked", 2, 2}, + {"blocked policy", "False", "InvalidSelection", "Blocked", 2, 2}, + {"unknown readiness", "Unknown", "Unknown", "Unknown", 2, 2}, + {"stale status", "True", "CollectionActive", "Awaiting reconciliation", 1, 1}, + {"stale condition", "True", "CollectionActive", "Awaiting reconciliation", 2, 1}, + {"missing condition generation", "True", "CollectionActive", "Awaiting reconciliation", 2, -1}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + object := map[string]any{ + "apiVersion": "observability.suse.com/v1alpha1", "kind": "ResourceCollection", + "metadata": map[string]any{"name": "virtualization", "generation": int64(2)}, + "spec": map[string]any{"resources": []any{ + map[string]any{"group": "kubevirt.io", "resource": "virtualmachines"}, + }}, + } + if test.observed >= 0 { + status := map[string]any{} + if test.observed > 0 { + status["observedGeneration"] = test.observed + } + if test.ready != "" { + condition := map[string]any{ + "type": "Ready", "status": test.ready, "reason": test.reason, "message": "Fixture feedback.", + } + if test.conditionGeneration >= 0 { + condition["observedGeneration"] = test.conditionGeneration + } + status["conditions"] = []any{ + map[string]any{"type": "Other", "status": "False"}, + condition, + } + } + object["status"] = status + } + evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", + map[string]any{"type": "MODIFIED", "object": object}, + map[string]any{"k8s.resource.group": "observability.suse.com", + "k8s.resource.kind": "ResourceCollection", "k8s.object.name": "virtualization"}), + nil, NewResource(map[string]any{"k8s.cluster.name": "fixture"})) + selected, err := evaluator.EvalBooleanExpression(*specialized.Input.Resource.Scope.Log.Condition, evalContext) + require.NoError(t, err) + require.True(t, selected) + selected, err = evaluator.EvalBooleanExpression(*generic.Input.Resource.Scope.Log.Condition, evalContext) + require.NoError(t, err) + require.False(t, selected) + variables, errors := EvalVariables(evaluator, evalContext, specialized.Vars) + require.Empty(t, errors) + component, errors := mapper.MapComponent(&specialized, evaluator, evalContext.CloneWithVariables(variables)) + require.Empty(t, errors) + require.Equal(t, "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization", component.ExternalId) + require.Equal(t, "custom resource", component.TypeName) + require.Contains(t, component.Tags, "k8s.collection.state:"+test.expected) + require.Contains(t, component.Tags, "k8s.collection.selections:1") + if test.expected == "Awaiting reconciliation" { + require.Contains(t, component.Tags, "k8s.collection.reason:") + if test.reason != "" { + require.NotContains(t, component.Tags, "k8s.collection.reason:"+test.reason) + } + require.Contains(t, component.Tags, "k8s.collection.message:Waiting for feedback on the current declaration.") + } else { + require.Contains(t, component.Tags, "k8s.collection.reason:"+test.reason) + } + require.Equal(t, object["spec"], component.ResourceDefinition.AsMap()["spec"]) + require.NotContains(t, component.ResourceDefinition.AsMap(), "metadata") + require.NotContains(t, component.ResourceDefinition.AsMap(), "status") + if status, ok := object["status"]; ok { + expected, err := json.Marshal(status) + require.NoError(t, err) + actual, err := json.Marshal(component.StatusData.AsMap()) + require.NoError(t, err) + require.JSONEq(t, string(expected), string(actual)) + } + }) + } + t.Run("ordinary CRs retain their generic mapping", func(t *testing.T) { + evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", + map[string]any{"type": "ADDED"}, map[string]any{ + "k8s.resource.group": "kubevirt.io", "k8s.resource.kind": "VirtualMachine", + }), nil, NewResource(map[string]any{})) + for _, mapping := range []settingsproto.OtelComponentMapping{generic, specialized} { + selected, err := evaluator.EvalBooleanExpression(*mapping.Input.Resource.Scope.Log.Condition, evalContext) + require.NoError(t, err) + require.Equal(t, mapping.Identifier == generic.Identifier, selected) + } + }) + t.Run("delete requires identity only", func(t *testing.T) { + evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", + map[string]any{"type": "DELETED"}, map[string]any{ + "k8s.resource.group": "observability.suse.com", "k8s.resource.kind": "ResourceCollection", + "k8s.object.name": "virtualization", + }), nil, NewResource(map[string]any{"k8s.cluster.name": "fixture"})) + action, err := evaluator.EvalStringExpression(*specialized.Input.Resource.Scope.Log.Action, evalContext) + require.NoError(t, err) + require.Equal(t, "DELETE", action) + needed := CollectVarReferences(evaluator, specialized.Output.Identifier) + variables := FilterVarsByName(specialized.Vars, needed) + resolved, errors := EvalVariables(evaluator, evalContext, &variables) + require.Empty(t, errors) + identifier, err := evaluator.EvalStringExpression(specialized.Output.Identifier, evalContext.CloneWithVariables(resolved)) + require.NoError(t, err) + require.True(t, strings.HasSuffix(identifier, ":name/virtualization")) + }) +} diff --git a/tests/otel-k8s-crd/run.py b/tests/otel-k8s-crd/run.py new file mode 100644 index 0000000..e6327d4 --- /dev/null +++ b/tests/otel-k8s-crd/run.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""Evaluate the StackPack mappings with the supplied collector's CEL engine.""" + +import argparse +import os +from pathlib import Path +import shutil +import subprocess +import tempfile + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--collector-source", required=True, type=Path) + parser.add_argument("--go", default="go") + args = parser.parse_args() + collector = args.collector_source.resolve() + tests = Path(__file__).resolve().parent + pack = tests.parents[1] / "stackpacks" / "otel-k8s-crd" + source = collector / "connector" / "topologyconnector" + if not (source / "go.mod").is_file(): + parser.error("--collector-source must contain connector/topologyconnector") + with tempfile.TemporaryDirectory(prefix="resource-collection-mapping-") as temporary: + root = Path(temporary) + module = root / "connector" / "topologyconnector" + shutil.copytree(source, module) + for dependency in ( + "exporter/stskafkaexporter", + "extension/settingsproviderextension", + ): + destination = root / dependency + destination.parent.mkdir(parents=True, exist_ok=True) + destination.symlink_to(collector / dependency, target_is_directory=True) + shutil.copyfile( + tests / "resource_collections_test.go", + module / "internal" / "stackpack_resource_collections_test.go", + ) + env = os.environ.copy() + env.update(GOWORK="off", RESOURCE_COLLECTION_STACKPACK=str(pack)) + subprocess.run( + [ + args.go, "test", "-mod=readonly", "-count=1", "-v", + "./internal", "-run", "^TestStackPackResourceCollections$", + ], + cwd=module, + env=env, + check=True, + ) + + +if __name__ == "__main__": + main() From 0c5cebde037c5c8bba5f8ad00cd9407211fac12e Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Tue, 17 Nov 2026 13:30:35 +0100 Subject: [PATCH 2/8] Keep ResourceCollection StackPack changes focused on content --- .github/workflows/stackpacks-ci.yml | 29 --- tests/otel-k8s-crd/README.md | 36 ---- .../ResourceCollectionPresentationTest.java | 149 -------------- tests/otel-k8s-crd/presentation.py | 61 ------ .../otel-k8s-crd/resource_collections_test.go | 183 ------------------ tests/otel-k8s-crd/run.py | 52 ----- 6 files changed, 510 deletions(-) delete mode 100644 tests/otel-k8s-crd/README.md delete mode 100644 tests/otel-k8s-crd/ResourceCollectionPresentationTest.java delete mode 100644 tests/otel-k8s-crd/presentation.py delete mode 100644 tests/otel-k8s-crd/resource_collections_test.go delete mode 100644 tests/otel-k8s-crd/run.py diff --git a/.github/workflows/stackpacks-ci.yml b/.github/workflows/stackpacks-ci.yml index d9bb103..1fa3219 100644 --- a/.github/workflows/stackpacks-ci.yml +++ b/.github/workflows/stackpacks-ci.yml @@ -107,35 +107,6 @@ jobs: cat "${output}" grep -q "undeclared.*undeclaredValidationControl" "${output}" - - name: Check out the pinned collector mapping engine - if: matrix.stackpack == 'otel-k8s-crd' - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - repository: StackVista/sts-opentelemetry-collector - ref: 9be47421ee2a5eaf9d5643e98374c72eb4d30047 - path: .ci/collector - persist-credentials: false - - - name: Set up the collector's Go toolchain - if: matrix.stackpack == 'otel-k8s-crd' - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: - go-version-file: .ci/collector/connector/topologyconnector/go.mod - cache: false - - - name: Test ResourceCollection mapping and presentation - if: matrix.stackpack == 'otel-k8s-crd' - env: - GOTOOLCHAIN: local - run: | - python3 tests/otel-k8s-crd/run.py --collector-source .ci/collector - test -x "${JAVA_HOME_21_X64}/bin/java" - test -x "${JAVA_HOME_21_X64}/bin/javac" - python3 tests/otel-k8s-crd/presentation.py \ - --validator-image "${VALIDATOR_IMAGE}" \ - --java "${JAVA_HOME_21_X64}/bin/java" \ - --javac "${JAVA_HOME_21_X64}/bin/javac" - package: name: package (${{ matrix.stackpack }}) needs: [discover-stackpacks, validate, check-version-bump] diff --git a/tests/otel-k8s-crd/README.md b/tests/otel-k8s-crd/README.md deleted file mode 100644 index 780e723..0000000 --- a/tests/otel-k8s-crd/README.md +++ /dev/null @@ -1,36 +0,0 @@ -The mapping regression uses the supplied collector checkout's CEL evaluator and -mapper. It copies the topology connector into a temporary directory and reads -its dependencies without changing the checkout. - -```sh -python3 tests/otel-k8s-crd/run.py \ - --collector-source /path/to/sts-opentelemetry-collector \ - --go /path/to/the/collectors/go -``` - -It covers current and stale Ready conditions, missing feedback, pending and -blocked collection, retained configuration/status, generic CR selection and -identity-only deletion. Run the platform validator separately to check the -presentation schema and expressions. - -These checks do not establish installation, backend persistence or rendered UI -behavior. They require a collector revision compatible with the StackPack and -run in the existing CI validation job for `otel-k8s-crd`, before packaging. -The workflow pins the collector engine revision and derives its Go toolchain -from that revision's module file. - -The presentation regression uses the platform image's actual STQL matching, -highlight evaluation, overview composition and CRD query specialization. Use -the validator image from the repository workflow, pinned by digest, and JDK 21: - -```sh -python3 tests/otel-k8s-crd/presentation.py \ - --validator-image 'quay.io/stackstate/stackstate-server@sha256:' -``` - -It extracts the image's libraries into a temporary directory and leaves the -platform checkout untouched. It verifies the collection states, missing observed -generation, name/cluster/age columns, and absence of namespace fields. These local -API checks do not prove persistence or browser rendering. -CI runs the same presentation check with JDK 21 from the GitHub-hosted runner and -the existing validator image pinned by digest. diff --git a/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java b/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java deleted file mode 100644 index 853f217..0000000 --- a/tests/otel-k8s-crd/ResourceCollectionPresentationTest.java +++ /dev/null @@ -1,149 +0,0 @@ -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.stackstate.api.CnfSubQueryMatcher; -import com.stackstate.api.generated.model.ComponentField; -import com.stackstate.api.generated.model.ErrorField; -import com.stackstate.api.generated.model.TextField; -import com.stackstate.api.service.components.FieldContext; -import com.stackstate.api.service.components.FieldExtractor; -import com.stackstate.api.service.components.ParsedComponentField; -import com.stackstate.api.service.components.RelatedResourceExtractor; -import com.stackstate.api.service.overview.OverviewColumnDefinitionWithExpressions; -import com.stackstate.api.service.overview.OverviewPresentationDef; -import com.stackstate.api.service.overview.OverviewPresentationDefs; -import com.stackstate.api.service.overview.PresentationOverviewBuilder; -import com.stackstate.domain.state.HealthStateValue; -import com.stackstate.dto.dtos.componentpresentation.ComponentPresentation; -import com.stackstate.metrics.promql.PromQLParser; -import com.stackstate.metrics.promql.PromQLParserImpl; -import com.stackstate.settings.protocol.ComponentPresentationQueryBinding; -import com.stackstate.settings.protocol.ComponentPresentationRank; -import com.stackstate.settings.protocol.PresentationDefinition; -import com.stackstate.settings.provider.SettingsProvider; -import com.stackstate.stql.ErrorMessageParser$; -import org.apache.pekko.event.LoggingAdapter; -import org.apache.pekko.event.NoLogging$; -import scala.Option; -import scala.Tuple2; -import scala.collection.immutable.List; -import scala.collection.immutable.Seq; -import scala.collection.immutable.Set; -import scala.jdk.javaapi.CollectionConverters; -import spray.json.JsonParser; -import spray.json.ParserInput; - -import java.lang.reflect.Method; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Map; - -public class ResourceCollectionPresentationTest implements PresentationOverviewBuilder { - public SettingsProvider settingsProvider() { return null; } - public PromQLParser promqlParser() { return new PromQLParserImpl(); } - public LoggingAdapter log() { return NoLogging$.MODULE$; } - - private static void check(boolean value, String message) { - if (!value) throw new AssertionError(message); - } - - private static Seq seq(java.util.List values) { - return List.from(CollectionConverters.asScala(values)); - } - - private static ComponentPresentation read(Path path) throws Exception { - JsonNode node = new ObjectMapper(new YAMLFactory()).readTree(path.toFile()).get("nodes").get(0); - PresentationDefinition definition = PresentationDefinition.formatter().read( - JsonParser.apply(ParserInput.apply(node.get("presentation").toString()))); - return new ComponentPresentation( - Option.empty(), Option.empty(), node.get("name").asText(), Option.empty(), - Option.apply(node.get("identifier").asText()), Option.empty(), - new ComponentPresentationQueryBinding(node.get("binding").get("query").asText()), - Option.apply(new ComponentPresentationRank(node.get("rank").get("specificity").asDouble())), - Option.empty(), definition); - } - - private static boolean matches(ComponentPresentation candidate, ComponentPresentation base) { - return CnfSubQueryMatcher.isSubquery( - ErrorMessageParser$.MODULE$.parseTry(candidate.binding().query()).get(), - ErrorMessageParser$.MODULE$.parseTry(base.binding().query()).get()); - } - - private static FieldContext context(String state, boolean observed) { - var tags = new ArrayList(java.util.List.of( - "stackpack:otel-k8s-crd", "source-type:custom resource", - "k8s.resource.group:observability.suse.com", "k8s.resource.kind:ResourceCollection", - "cluster-name:fixture", "k8s.creationTimestamp:2026-11-13T12:00:00Z", - "k8s.collection.state:" + state, "k8s.collection.reason:FixtureReason", - "k8s.collection.message:Fixture feedback.", "k8s.collection.generation:2", - "k8s.collection.selections:1")); - if (observed) tags.add("k8s.collection.observed-generation:2"); - return new FieldContext( - 1, "virtualization", - Set.from(CollectionConverters.asScala(java.util.Set.of( - "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization"))), - Set.from(CollectionConverters.asScala(tags)), - scala.collection.immutable.Map.from(CollectionConverters.asScala(Map.of())), - "", "", "custom resource", HealthStateValue.CLEAR, Option.empty()); - } - - public static void main(String[] args) throws Exception { - Path presentations = Path.of(args[0], "settings", "presentations"); - ComponentPresentation specialized = read(presentations.resolve("resource-collections.sty")); - ComponentPresentation generic = read(presentations.resolve("custom-resources.sty")); - ComponentPresentation filters = read(presentations.resolve("common-filters.sty")); - check(!matches(generic, specialized), "Generic CR presentation also matches ResourceCollections"); - check(matches(filters, specialized), "Common cluster filter does not match"); - var matched = seq(java.util.List.of(specialized, filters)); - var parsed = FieldExtractor.parseFields(matched, Option.empty()); - check(parsed._1().isEmpty(), "Highlight parse errors: " + parsed._1()); - var fieldIds = new ArrayList(); - for (ParsedComponentField field : CollectionConverters.asJava(parsed._2())) { - fieldIds.add(field.fieldId()); - } - check(!fieldIds.contains("namespace"), "Cluster-scoped declarations show namespace"); - check(fieldIds.containsAll(java.util.List.of( - "collection_state", "collection_reason", "collection_message", "collection_generation", - "collection_observed_generation", "collection_selections", "kind", "cluster", "age", "labels")), - "Missing highlight fields: " + fieldIds); - System.out.println("PASS presentation matching and highlight composition"); - - for (String state : java.util.List.of("Collecting", "Pending", "Blocked", "Unknown", "Awaiting reconciliation")) { - var evaluated = FieldExtractor.evaluate(parsed._2(), context(state, !state.equals("Awaiting reconciliation")), - new PromQLParserImpl()); - var values = new java.util.HashMap(); - for (ComponentField field : CollectionConverters.asJava(evaluated)) { - check(!(field instanceof ErrorField), "Highlight evaluation error for " + state + ": " + field); - if (field instanceof TextField text) values.put(text.fieldId(), text.value()); - } - check(state.equals(values.get("collection_state")), "Incorrect collection state: " + values); - check("fixture".equals(values.get("cluster")), "Missing cluster: " + values); - check("Fixture feedback.".equals(values.get("collection_message")), "Missing feedback: " + values); - System.out.println("PASS highlight values: " + state); - } - - Method merge = PresentationOverviewBuilder.class.getDeclaredMethod( - "mergePresentationsAndBuildColumnDef", OverviewPresentationDefs.class); - merge.setAccessible(true); - var base = new OverviewPresentationDef(specialized.identifier().get(), specialized.rank().get().specificity(), - ErrorMessageParser$.MODULE$.parseTry(specialized.binding().query()).get(), - specialized.presentation().overview().get()); - @SuppressWarnings("unchecked") - var overview = (Tuple2, Seq>) merge.invoke( - new ResourceCollectionPresentationTest(), new OverviewPresentationDefs(base, seq(java.util.List.of()))); - check(overview._1().isEmpty(), "Overview projection errors: " + overview._1()); - var columns = new ArrayList(); - for (var column : CollectionConverters.asJava(overview._2())) columns.add(column.columnId()); - check(columns.equals(java.util.List.of( - "cr_name", "collection_state", "collection_reason", "collection_selections", "cr_cluster", "cr_age")), - "Incorrect overview columns: " + columns); - System.out.println("PASS overview column composition"); - - var relations = RelatedResourceExtractor.resolve(matched, Option.empty(), context("Collecting", true)); - check(relations.size() == 1, "Missing or duplicate CRD detail link: " + relations); - check(relations.head().toString().contains( - "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization"), - "CRD query did not specialize the component identifier: " + relations); - System.out.println("PASS CRD related-resource query specialization"); - } -} diff --git a/tests/otel-k8s-crd/presentation.py b/tests/otel-k8s-crd/presentation.py deleted file mode 100644 index 5dde2af..0000000 --- a/tests/otel-k8s-crd/presentation.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -"""Check presentation composition using the platform validator image's API code.""" - -import argparse -import os -from pathlib import Path -import re -import subprocess -import tempfile - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--validator-image", required=True) - parser.add_argument("--pack-directory", type=Path) - parser.add_argument("--java", default="java") - parser.add_argument("--javac", default="javac") - args = parser.parse_args() - if not re.search(r"@sha256:[a-f0-9]{64}$", args.validator_image): - parser.error("--validator-image must be pinned by digest") - tests = Path(__file__).resolve().parent - pack = args.pack_directory or tests.parents[1] / "stackpacks" / "otel-k8s-crd" - with tempfile.TemporaryDirectory(prefix="resource-collection-presentation-") as temporary: - root = Path(temporary) - container = subprocess.check_output( - ["docker", "create", "--network", "none", args.validator_image], - text=True, - ).strip() - try: - subprocess.run( - ["docker", "cp", f"{container}:/opt/docker/lib", str(root)], - check=True, - ) - finally: - subprocess.run( - ["docker", "rm", container], check=True, stdout=subprocess.DEVNULL, - ) - classes = root / "classes" - classes.mkdir() - libraries = str(root / "lib" / "*") - subprocess.run( - [ - args.javac, "-proc:none", "-cp", libraries, "-d", str(classes), - str(tests / "ResourceCollectionPresentationTest.java"), - ], - cwd=root, check=True, - ) - logging = root / "logback.xml" - logging.write_text('\n') - subprocess.run( - [ - args.java, f"-Dlogback.configurationFile={logging}", - "-cp", str(classes) + os.pathsep + libraries, - "ResourceCollectionPresentationTest", str(pack.resolve()), - ], - cwd=root, check=True, - ) - - -if __name__ == "__main__": - main() diff --git a/tests/otel-k8s-crd/resource_collections_test.go b/tests/otel-k8s-crd/resource_collections_test.go deleted file mode 100644 index e855a7d..0000000 --- a/tests/otel-k8s-crd/resource_collections_test.go +++ /dev/null @@ -1,183 +0,0 @@ -package internal - -import ( - "context" - "encoding/json" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/stackvista/sts-opentelemetry-collector/connector/topologyconnector/metrics" - "github.com/stackvista/sts-opentelemetry-collector/extension/settingsproviderextension/generated/settingsproto" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" -) - -func readStackPackMapping(t *testing.T, name string) settingsproto.OtelComponentMapping { - t.Helper() - body, err := os.ReadFile(filepath.Join(os.Getenv("RESOURCE_COLLECTION_STACKPACK"), - "settings", "component-mappings", name+".sty")) - require.NoError(t, err) - var document struct { - Nodes []map[string]any `yaml:"nodes"` - } - require.NoError(t, yaml.Unmarshal(body, &document)) - node := document.Nodes[0] - expression := func(value any) map[string]any { - return map[string]any{"expression": value} - } - for _, variable := range node["vars"].([]any) { - entry := variable.(map[string]any) - entry["value"] = expression(entry["value"]) - } - log := node["input"].(map[string]any)["resource"].(map[string]any)["scope"].(map[string]any)["log"].(map[string]any) - for _, key := range []string{"condition", "action"} { - log[key] = expression(log[key]) - } - output := node["output"].(map[string]any) - for _, key := range []string{"identifier", "name", "typeName"} { - output[key] = expression(output[key]) - } - for _, field := range []string{"required", "optional"} { - block := output[field].(map[string]any) - for _, key := range []string{"configuration", "status"} { - if value, found := block[key]; found { - block[key] = expression(value) - } - } - for _, tag := range block["tags"].([]any) { - entry := tag.(map[string]any) - entry["source"] = expression(entry["source"]) - } - } - body, err = json.Marshal(node) - require.NoError(t, err) - var mapping settingsproto.OtelComponentMapping - require.NoError(t, json.Unmarshal(body, &mapping)) - return mapping -} - -func TestStackPackResourceCollections(t *testing.T) { - evaluator, err := NewCELEvaluator(context.Background(), metrics.MeteredCacheSettings{ - Name: "stackpack_resource_collections", EnableMetrics: false, - }) - require.NoError(t, err) - mapper := NewMapper(context.Background(), - metrics.MeteredCacheSettings{Name: "tags", EnableMetrics: false}, - metrics.MeteredCacheSettings{Name: "templates", EnableMetrics: false}) - specialized := readStackPackMapping(t, "resource-collections") - generic := readStackPackMapping(t, "custom-resources") - tests := []struct { - name, ready, reason, expected string - observed, conditionGeneration int64 - }{ - {"no status", "", "", "Awaiting reconciliation", -1, -1}, - {"empty status", "", "", "Awaiting reconciliation", 0, 0}, - {"missing Ready", "", "", "Awaiting reconciliation", 2, 2}, - {"collecting", "True", "CollectionActive", "Collecting", 2, 2}, - {"pending API", "False", "ResourcesPending", "Pending", 2, 2}, - {"blocked reads", "False", "CollectionBlocked", "Blocked", 2, 2}, - {"blocked policy", "False", "InvalidSelection", "Blocked", 2, 2}, - {"unknown readiness", "Unknown", "Unknown", "Unknown", 2, 2}, - {"stale status", "True", "CollectionActive", "Awaiting reconciliation", 1, 1}, - {"stale condition", "True", "CollectionActive", "Awaiting reconciliation", 2, 1}, - {"missing condition generation", "True", "CollectionActive", "Awaiting reconciliation", 2, -1}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - object := map[string]any{ - "apiVersion": "observability.suse.com/v1alpha1", "kind": "ResourceCollection", - "metadata": map[string]any{"name": "virtualization", "generation": int64(2)}, - "spec": map[string]any{"resources": []any{ - map[string]any{"group": "kubevirt.io", "resource": "virtualmachines"}, - }}, - } - if test.observed >= 0 { - status := map[string]any{} - if test.observed > 0 { - status["observedGeneration"] = test.observed - } - if test.ready != "" { - condition := map[string]any{ - "type": "Ready", "status": test.ready, "reason": test.reason, "message": "Fixture feedback.", - } - if test.conditionGeneration >= 0 { - condition["observedGeneration"] = test.conditionGeneration - } - status["conditions"] = []any{ - map[string]any{"type": "Other", "status": "False"}, - condition, - } - } - object["status"] = status - } - evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", - map[string]any{"type": "MODIFIED", "object": object}, - map[string]any{"k8s.resource.group": "observability.suse.com", - "k8s.resource.kind": "ResourceCollection", "k8s.object.name": "virtualization"}), - nil, NewResource(map[string]any{"k8s.cluster.name": "fixture"})) - selected, err := evaluator.EvalBooleanExpression(*specialized.Input.Resource.Scope.Log.Condition, evalContext) - require.NoError(t, err) - require.True(t, selected) - selected, err = evaluator.EvalBooleanExpression(*generic.Input.Resource.Scope.Log.Condition, evalContext) - require.NoError(t, err) - require.False(t, selected) - variables, errors := EvalVariables(evaluator, evalContext, specialized.Vars) - require.Empty(t, errors) - component, errors := mapper.MapComponent(&specialized, evaluator, evalContext.CloneWithVariables(variables)) - require.Empty(t, errors) - require.Equal(t, "urn:k8s:cr:/cluster/fixture:namespace/:group/observability.suse.com:kind/ResourceCollection:name/virtualization", component.ExternalId) - require.Equal(t, "custom resource", component.TypeName) - require.Contains(t, component.Tags, "k8s.collection.state:"+test.expected) - require.Contains(t, component.Tags, "k8s.collection.selections:1") - if test.expected == "Awaiting reconciliation" { - require.Contains(t, component.Tags, "k8s.collection.reason:") - if test.reason != "" { - require.NotContains(t, component.Tags, "k8s.collection.reason:"+test.reason) - } - require.Contains(t, component.Tags, "k8s.collection.message:Waiting for feedback on the current declaration.") - } else { - require.Contains(t, component.Tags, "k8s.collection.reason:"+test.reason) - } - require.Equal(t, object["spec"], component.ResourceDefinition.AsMap()["spec"]) - require.NotContains(t, component.ResourceDefinition.AsMap(), "metadata") - require.NotContains(t, component.ResourceDefinition.AsMap(), "status") - if status, ok := object["status"]; ok { - expected, err := json.Marshal(status) - require.NoError(t, err) - actual, err := json.Marshal(component.StatusData.AsMap()) - require.NoError(t, err) - require.JSONEq(t, string(expected), string(actual)) - } - }) - } - t.Run("ordinary CRs retain their generic mapping", func(t *testing.T) { - evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", - map[string]any{"type": "ADDED"}, map[string]any{ - "k8s.resource.group": "kubevirt.io", "k8s.resource.kind": "VirtualMachine", - }), nil, NewResource(map[string]any{})) - for _, mapping := range []settingsproto.OtelComponentMapping{generic, specialized} { - selected, err := evaluator.EvalBooleanExpression(*mapping.Input.Resource.Scope.Log.Condition, evalContext) - require.NoError(t, err) - require.Equal(t, mapping.Identifier == generic.Identifier, selected) - } - }) - t.Run("delete requires identity only", func(t *testing.T) { - evalContext := NewLogEvalContext(NewLog("KubernetesCustomResourceEvent", - map[string]any{"type": "DELETED"}, map[string]any{ - "k8s.resource.group": "observability.suse.com", "k8s.resource.kind": "ResourceCollection", - "k8s.object.name": "virtualization", - }), nil, NewResource(map[string]any{"k8s.cluster.name": "fixture"})) - action, err := evaluator.EvalStringExpression(*specialized.Input.Resource.Scope.Log.Action, evalContext) - require.NoError(t, err) - require.Equal(t, "DELETE", action) - needed := CollectVarReferences(evaluator, specialized.Output.Identifier) - variables := FilterVarsByName(specialized.Vars, needed) - resolved, errors := EvalVariables(evaluator, evalContext, &variables) - require.Empty(t, errors) - identifier, err := evaluator.EvalStringExpression(specialized.Output.Identifier, evalContext.CloneWithVariables(resolved)) - require.NoError(t, err) - require.True(t, strings.HasSuffix(identifier, ":name/virtualization")) - }) -} diff --git a/tests/otel-k8s-crd/run.py b/tests/otel-k8s-crd/run.py deleted file mode 100644 index e6327d4..0000000 --- a/tests/otel-k8s-crd/run.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 -"""Evaluate the StackPack mappings with the supplied collector's CEL engine.""" - -import argparse -import os -from pathlib import Path -import shutil -import subprocess -import tempfile - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--collector-source", required=True, type=Path) - parser.add_argument("--go", default="go") - args = parser.parse_args() - collector = args.collector_source.resolve() - tests = Path(__file__).resolve().parent - pack = tests.parents[1] / "stackpacks" / "otel-k8s-crd" - source = collector / "connector" / "topologyconnector" - if not (source / "go.mod").is_file(): - parser.error("--collector-source must contain connector/topologyconnector") - with tempfile.TemporaryDirectory(prefix="resource-collection-mapping-") as temporary: - root = Path(temporary) - module = root / "connector" / "topologyconnector" - shutil.copytree(source, module) - for dependency in ( - "exporter/stskafkaexporter", - "extension/settingsproviderextension", - ): - destination = root / dependency - destination.parent.mkdir(parents=True, exist_ok=True) - destination.symlink_to(collector / dependency, target_is_directory=True) - shutil.copyfile( - tests / "resource_collections_test.go", - module / "internal" / "stackpack_resource_collections_test.go", - ) - env = os.environ.copy() - env.update(GOWORK="off", RESOURCE_COLLECTION_STACKPACK=str(pack)) - subprocess.run( - [ - args.go, "test", "-mod=readonly", "-count=1", "-v", - "./internal", "-run", "^TestStackPackResourceCollections$", - ], - cwd=module, - env=env, - check=True, - ) - - -if __name__ == "__main__": - main() From dfb42decbc168365a1836fa68208c01f3a2c51cf Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Tue, 17 Nov 2026 16:51:17 +0100 Subject: [PATCH 3/8] Clarify collection declaration overview Show Collection Declarations after Custom Resources and share the generation freshness predicate. Mapping variables must read input directly, so current uses the source object rather than other mapping variables. --- .../resources/detailed-overview.md | 2 +- .../resource-collections.sty | 33 ++++++++----------- .../presentations/resource-collections.sty | 12 +++---- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/stackpacks/otel-k8s-crd/resources/detailed-overview.md b/stackpacks/otel-k8s-crd/resources/detailed-overview.md index 03f550a..103c199 100644 --- a/stackpacks/otel-k8s-crd/resources/detailed-overview.md +++ b/stackpacks/otel-k8s-crd/resources/detailed-overview.md @@ -13,7 +13,7 @@ The StackPack defines SUSE Observability settings (component and relation mappin ### Resource collections -ResourceCollection declarations appear in the **Resource Collections** overview +ResourceCollection declarations appear in the **Collection Declarations** overview under **Kubernetes**. Their highlights show collection state, reason, details and the declaration and observed generations. Configuration contains the selections; status contains the collector's per-selection feedback. diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty index 05da7c5..1329f9f 100644 --- a/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty @@ -28,10 +28,17 @@ nodes: 'status' in log.body['object'] && 'conditions' in log.body['object']['status'] ? log.body['object']['status']['conditions'].filter(c, c['type'] == 'Ready') : [] - - name: "generation" + - name: "current" value: >- - 'generation' in log.body['object']['metadata'] - ? log.body['object']['metadata']['generation'] : 0 + 'generation' in log.body['object']['metadata'] && + log.body['object']['metadata']['generation'] > 0 && + 'status' in log.body['object'] && + 'observedGeneration' in log.body['object']['status'] && + log.body['object']['status']['observedGeneration'] == log.body['object']['metadata']['generation'] && + 'conditions' in log.body['object']['status'] && + log.body['object']['status']['conditions'].exists(c, + c['type'] == 'Ready' && 'observedGeneration' in c && + c['observedGeneration'] == log.body['object']['metadata']['generation']) output: identifier: "'urn:k8s:cr:/cluster/' + vars.clusterName + ':namespace/:group/observability.suse.com:kind/ResourceCollection:name/' + vars.name" name: "vars.name" @@ -50,11 +57,7 @@ nodes: - source: "vars.clusterName" target: "cluster-name" - source: >- - !(vars.generation > 0 && 'observedGeneration' in vars.status && - vars.status['observedGeneration'] == vars.generation && - size(vars.readyConditions) > 0 && - 'observedGeneration' in vars.readyConditions[0] && - vars.readyConditions[0]['observedGeneration'] == vars.generation) ? 'Awaiting reconciliation' : + !vars.current ? 'Awaiting reconciliation' : vars.readyConditions[0]['status'] == 'True' ? 'Collecting' : vars.readyConditions[0]['status'] == 'False' ? (vars.readyConditions[0]['reason'] == 'ResourcesPending' ? 'Pending' : 'Blocked') @@ -64,20 +67,10 @@ nodes: status: "vars.status" tags: - source: >- - (vars.generation > 0 && 'observedGeneration' in vars.status && - vars.status['observedGeneration'] == vars.generation && - size(vars.readyConditions) > 0 && - 'observedGeneration' in vars.readyConditions[0] && - vars.readyConditions[0]['observedGeneration'] == vars.generation) - ? vars.readyConditions[0]['reason'] : '' + vars.current ? vars.readyConditions[0]['reason'] : '' target: "k8s.collection.reason" - source: >- - (vars.generation > 0 && 'observedGeneration' in vars.status && - vars.status['observedGeneration'] == vars.generation && - size(vars.readyConditions) > 0 && - 'observedGeneration' in vars.readyConditions[0] && - vars.readyConditions[0]['observedGeneration'] == vars.generation) - ? vars.readyConditions[0]['message'] + vars.current ? vars.readyConditions[0]['message'] : 'Waiting for feedback on the current declaration.' target: "k8s.collection.message" - source: "string(vars.object['metadata']['generation'])" diff --git a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty index b2540d9..419c74f 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty @@ -1,6 +1,6 @@ nodes: - _type: ComponentPresentation - name: "Resource Collection" + name: "Collection Declaration" description: "Presentation for Kubernetes collection declarations" identifier: "urn:stackpack:otel-k8s-crd:component-presentation:resource-collection" binding: @@ -25,12 +25,12 @@ nodes: connectedComponents: true overview: name: - singular: "resource collection" - plural: "resource collections" - title: "Resource Collections" + singular: "collection declaration" + plural: "collection declarations" + title: "Collection Declarations" mainMenu: group: "Kubernetes" - order: 0 + order: 1 columns: - columnId: cr_name title: "Name" @@ -64,7 +64,7 @@ nodes: _type: DurationProjection startTime: "tags.singleValue('k8s.creationTimestamp')" highlight: - title: "Resource Collection" + title: "Collection Declaration" fields: - fieldId: collection_state title: "Collection" From 7e5cb6a1b1e0cc0ee5af36515b922779fefe1f8a Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Wed, 18 Nov 2026 11:20:06 +0100 Subject: [PATCH 4/8] Move collection declarations to the Agent menu --- stackpacks/otel-k8s-crd/resources/detailed-overview.md | 2 +- .../settings/presentations/resource-collections.sty | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stackpacks/otel-k8s-crd/resources/detailed-overview.md b/stackpacks/otel-k8s-crd/resources/detailed-overview.md index 103c199..06d54de 100644 --- a/stackpacks/otel-k8s-crd/resources/detailed-overview.md +++ b/stackpacks/otel-k8s-crd/resources/detailed-overview.md @@ -14,7 +14,7 @@ The StackPack defines SUSE Observability settings (component and relation mappin ### Resource collections ResourceCollection declarations appear in the **Collection Declarations** overview -under **Kubernetes**. Their highlights show collection state, reason, details and +under **Agent**. Their highlights show collection state, reason, details and the declaration and observed generations. Configuration contains the selections; status contains the collector's per-selection feedback. diff --git a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty index 419c74f..f7906a1 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty @@ -29,8 +29,8 @@ nodes: plural: "collection declarations" title: "Collection Declarations" mainMenu: - group: "Kubernetes" - order: 1 + group: "Agent" + order: 0 columns: - columnId: cr_name title: "Name" From 4fd0a02df3dc79fd29b77938400d2731efeb7c48 Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Wed, 18 Nov 2026 12:51:03 +0100 Subject: [PATCH 5/8] Match CollectionDeclaration naming and place Agent last --- stackpacks/open-telemetry/settings/main-menu.sty | 3 ++- stackpacks/open-telemetry/stackpack.yaml | 2 +- stackpacks/otel-k8s-crd/icons/agent.svg | 7 +++++++ stackpacks/otel-k8s-crd/resources/detailed-overview.md | 2 +- ...rce-collections.sty => collection-declarations.sty} | 10 +++++----- .../settings/component-mappings/custom-resources.sty | 2 +- stackpacks/otel-k8s-crd/settings/main-menu.sty | 8 ++++++++ ...rce-collections.sty => collection-declarations.sty} | 4 ++-- .../settings/presentations/custom-resources.sty | 2 +- 9 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 stackpacks/otel-k8s-crd/icons/agent.svg rename stackpacks/otel-k8s-crd/settings/component-mappings/{resource-collections.sty => collection-declarations.sty} (92%) rename stackpacks/otel-k8s-crd/settings/presentations/{resource-collections.sty => collection-declarations.sty} (98%) diff --git a/stackpacks/open-telemetry/settings/main-menu.sty b/stackpacks/open-telemetry/settings/main-menu.sty index b5ad538..d0615fe 100644 --- a/stackpacks/open-telemetry/settings/main-menu.sty +++ b/stackpacks/open-telemetry/settings/main-menu.sty @@ -1,7 +1,8 @@ nodes: - _type: MainMenuGroup name: Open Telemetry + order: 0 iconbase64: !icon open-telemetry.svg defaultOpen: true items: [] - identifier: "urn:stackpack:open-telemetry:main-menu-group:open-telemetry" \ No newline at end of file + identifier: "urn:stackpack:open-telemetry:main-menu-group:open-telemetry" diff --git a/stackpacks/open-telemetry/stackpack.yaml b/stackpacks/open-telemetry/stackpack.yaml index fde883a..b34b7b9 100644 --- a/stackpacks/open-telemetry/stackpack.yaml +++ b/stackpacks/open-telemetry/stackpack.yaml @@ -1,5 +1,5 @@ name: "open-telemetry" -version: "0.1.6" +version: "0.1.7" schemaVersion: "2.0" displayName: "Open Telemetry" categories: [ "Open Telemetry" ] diff --git a/stackpacks/otel-k8s-crd/icons/agent.svg b/stackpacks/otel-k8s-crd/icons/agent.svg new file mode 100644 index 0000000..62d72a9 --- /dev/null +++ b/stackpacks/otel-k8s-crd/icons/agent.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stackpacks/otel-k8s-crd/resources/detailed-overview.md b/stackpacks/otel-k8s-crd/resources/detailed-overview.md index 06d54de..5a1ddd6 100644 --- a/stackpacks/otel-k8s-crd/resources/detailed-overview.md +++ b/stackpacks/otel-k8s-crd/resources/detailed-overview.md @@ -13,7 +13,7 @@ The StackPack defines SUSE Observability settings (component and relation mappin ### Resource collections -ResourceCollection declarations appear in the **Collection Declarations** overview +CollectionDeclaration declarations appear in the **Collection Declarations** overview under **Agent**. Their highlights show collection state, reason, details and the declaration and observed generations. Configuration contains the selections; status contains the collector's per-selection feedback. diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/collection-declarations.sty similarity index 92% rename from stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty rename to stackpacks/otel-k8s-crd/settings/component-mappings/collection-declarations.sty index 1329f9f..65cf35e 100644 --- a/stackpacks/otel-k8s-crd/settings/component-mappings/resource-collections.sty +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/collection-declarations.sty @@ -1,8 +1,8 @@ nodes: - _type: "OtelComponentMapping" - name: "Kubernetes Resource Collection" + name: "Kubernetes Collection Declaration" description: "Collection declarations and their generation-bound feedback" - identifier: "urn:stackpack:otel-k8s-crd:otel-component-mapping:resource-collection" + identifier: "urn:stackpack:otel-k8s-crd:otel-component-mapping:collection-declaration" input: signal: - "LOGS" @@ -13,7 +13,7 @@ nodes: condition: >- log.eventName == 'KubernetesCustomResourceEvent' && log.attributes['k8s.resource.group'] == 'observability.suse.com' && - log.attributes['k8s.resource.kind'] == 'ResourceCollection' + log.attributes['k8s.resource.kind'] == 'CollectionDeclaration' vars: - name: "clusterName" value: "resource.attributes['k8s.cluster.name']" @@ -40,7 +40,7 @@ nodes: c['type'] == 'Ready' && 'observedGeneration' in c && c['observedGeneration'] == log.body['object']['metadata']['generation']) output: - identifier: "'urn:k8s:cr:/cluster/' + vars.clusterName + ':namespace/:group/observability.suse.com:kind/ResourceCollection:name/' + vars.name" + identifier: "'urn:k8s:cr:/cluster/' + vars.clusterName + ':namespace/:group/observability.suse.com:kind/CollectionDeclaration:name/' + vars.name" name: "vars.name" typeName: "'custom resource'" required: @@ -48,7 +48,7 @@ nodes: tags: - source: "'otel-k8s-crd'" target: "stackpack" - - source: "'ResourceCollection'" + - source: "'CollectionDeclaration'" target: "k8s.resource.kind" - source: "'observability.suse.com'" target: "k8s.resource.group" diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty index 539077b..0a4e495 100644 --- a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty @@ -13,7 +13,7 @@ nodes: condition: >- log.eventName == 'KubernetesCustomResourceEvent' && !(log.attributes['k8s.resource.group'] == 'observability.suse.com' && - log.attributes['k8s.resource.kind'] == 'ResourceCollection') + log.attributes['k8s.resource.kind'] == 'CollectionDeclaration') vars: - name: "clusterName" value: "resource.attributes['k8s.cluster.name']" diff --git a/stackpacks/otel-k8s-crd/settings/main-menu.sty b/stackpacks/otel-k8s-crd/settings/main-menu.sty index 4966499..e5eb926 100644 --- a/stackpacks/otel-k8s-crd/settings/main-menu.sty +++ b/stackpacks/otel-k8s-crd/settings/main-menu.sty @@ -1,7 +1,15 @@ nodes: - _type: MainMenuGroup name: Kubernetes + order: 0 iconbase64: "" defaultOpen: true items: [] identifier: "urn:stackpack:otel-k8s-crd:main-menu-group:kubernetes" + - _type: MainMenuGroup + name: Agent + order: -1 + iconbase64: !icon agent.svg + defaultOpen: false + items: [] + identifier: "urn:stackpack:otel-k8s-crd:main-menu-group:agent" diff --git a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty b/stackpacks/otel-k8s-crd/settings/presentations/collection-declarations.sty similarity index 98% rename from stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty rename to stackpacks/otel-k8s-crd/settings/presentations/collection-declarations.sty index f7906a1..c2ec337 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/resource-collections.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/collection-declarations.sty @@ -2,13 +2,13 @@ nodes: - _type: ComponentPresentation name: "Collection Declaration" description: "Presentation for Kubernetes collection declarations" - identifier: "urn:stackpack:otel-k8s-crd:component-presentation:resource-collection" + identifier: "urn:stackpack:otel-k8s-crd:component-presentation:collection-declaration" binding: _type: ComponentPresentationQueryBinding query: >- label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource" and label = "k8s.resource.group:observability.suse.com" - and label = "k8s.resource.kind:ResourceCollection" + and label = "k8s.resource.kind:CollectionDeclaration" rank: specificity: 20 presentation: diff --git a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty index 8fa12dd..e5112ab 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty @@ -8,7 +8,7 @@ nodes: query: >- label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource" and not (label = "k8s.resource.group:observability.suse.com" - and label = "k8s.resource.kind:ResourceCollection") + and label = "k8s.resource.kind:CollectionDeclaration") rank: specificity: 10 presentation: From 0308d15a9c24e008f9b25a023ef404caf0524ca8 Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Wed, 18 Nov 2026 15:21:24 +0100 Subject: [PATCH 6/8] Include collection declarations in the custom resource inventory --- stackpacks/otel-k8s-crd/resources/detailed-overview.md | 3 +++ .../otel-k8s-crd/settings/presentations/custom-resources.sty | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stackpacks/otel-k8s-crd/resources/detailed-overview.md b/stackpacks/otel-k8s-crd/resources/detailed-overview.md index 5a1ddd6..871456b 100644 --- a/stackpacks/otel-k8s-crd/resources/detailed-overview.md +++ b/stackpacks/otel-k8s-crd/resources/detailed-overview.md @@ -18,6 +18,9 @@ under **Agent**. Their highlights show collection state, reason, details and the declaration and observed generations. Configuration contains the selections; status contains the collector's per-selection feedback. +Declarations also appear in **Kubernetes → Custom Resources** as part of the +custom-resource inventory. + **Awaiting reconciliation** means the available feedback does not describe the current declaration generation. **Collecting**, **Pending** and **Blocked** reflect the collector's Ready condition. A blocked declaration can still collect its diff --git a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty index e5112ab..14799cd 100644 --- a/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/presentations/custom-resources.sty @@ -7,8 +7,6 @@ nodes: _type: ComponentPresentationQueryBinding query: >- label = "stackpack:otel-k8s-crd" and label = "source-type:custom resource" - and not (label = "k8s.resource.group:observability.suse.com" - and label = "k8s.resource.kind:CollectionDeclaration") rank: specificity: 10 presentation: From d5cc0c67681e25ebcbe74989762091678bd372b3 Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Wed, 18 Nov 2026 16:21:25 +0100 Subject: [PATCH 7/8] Reuse the SUSE Geeko icon for the Agent menu --- stackpacks/otel-k8s-crd/icons/agent.svg | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/stackpacks/otel-k8s-crd/icons/agent.svg b/stackpacks/otel-k8s-crd/icons/agent.svg index 62d72a9..1487ec9 100644 --- a/stackpacks/otel-k8s-crd/icons/agent.svg +++ b/stackpacks/otel-k8s-crd/icons/agent.svg @@ -1,7 +1,5 @@ - - - - - - + + From fd52770493ec05db99d147512746bfd921904fc7 Mon Sep 17 00:00:00 2001 From: Alejandro Acevedo Date: Fri, 20 Nov 2026 14:41:00 +0100 Subject: [PATCH 8/8] Let declaration and generic resource mappings merge --- .../settings/component-mappings/custom-resources.sty | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty index 0a4e495..077b0e0 100644 --- a/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty +++ b/stackpacks/otel-k8s-crd/settings/component-mappings/custom-resources.sty @@ -10,10 +10,7 @@ nodes: scope: log: action: "log.body['type'] in ['ADDED', 'MODIFIED'] ? 'CREATE' : log.body['type'] == 'DELETED' ? 'DELETE' : 'CONTINUE'" - condition: >- - log.eventName == 'KubernetesCustomResourceEvent' && - !(log.attributes['k8s.resource.group'] == 'observability.suse.com' && - log.attributes['k8s.resource.kind'] == 'CollectionDeclaration') + condition: log.eventName == 'KubernetesCustomResourceEvent' vars: - name: "clusterName" value: "resource.attributes['k8s.cluster.name']"