@intentius/chant-lexicon-k8s 0.101.0 → 0.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/dist/actions/apps.d.ts +4 -4
  2. package/dist/actions/apps.d.ts.map +1 -1
  3. package/dist/actions/core.d.ts +5 -5
  4. package/dist/actions/core.d.ts.map +1 -1
  5. package/dist/actions/networking.d.ts.map +1 -1
  6. package/dist/codegen/generate-typescript.d.ts +2 -2
  7. package/dist/codegen/generate-typescript.d.ts.map +1 -1
  8. package/dist/codegen/generate.d.ts.map +1 -1
  9. package/dist/codegen/naming.d.ts.map +1 -1
  10. package/dist/codegen/versions.d.ts.map +1 -1
  11. package/dist/components/capability-plugin.d.ts.map +1 -1
  12. package/dist/composites/catalog.d.ts.map +1 -1
  13. package/dist/composites/cockroachdb-cluster.d.ts +2 -2
  14. package/dist/composites/gke-otel-collector.d.ts.map +1 -1
  15. package/dist/composites/index.d.ts +1 -0
  16. package/dist/composites/index.d.ts.map +1 -1
  17. package/dist/composites/otel-collector-agent.d.ts +19 -1
  18. package/dist/composites/otel-collector-agent.d.ts.map +1 -1
  19. package/dist/composites/otel-collector-node.d.ts +88 -0
  20. package/dist/composites/otel-collector-node.d.ts.map +1 -0
  21. package/dist/composites/otel-collector-shape.d.ts.map +1 -1
  22. package/dist/composites/otel-collector.d.ts +9 -1
  23. package/dist/composites/otel-collector.d.ts.map +1 -1
  24. package/dist/composites/ray-cluster.d.ts +6 -6
  25. package/dist/composites/ray-job.d.ts +5 -5
  26. package/dist/composites/ray-service.d.ts +6 -6
  27. package/dist/crd/crd-sources.d.ts.map +1 -1
  28. package/dist/crd/loader.d.ts.map +1 -1
  29. package/dist/crd/oci-chart.d.ts +50 -0
  30. package/dist/crd/oci-chart.d.ts.map +1 -0
  31. package/dist/crd/types.d.ts +5 -0
  32. package/dist/crd/types.d.ts.map +1 -1
  33. package/dist/effect-receipt-row.d.ts.map +1 -1
  34. package/dist/generated/index.d.ts +752 -729
  35. package/dist/generated/index.d.ts.map +1 -1
  36. package/dist/import/embedded.d.ts +4 -2
  37. package/dist/import/embedded.d.ts.map +1 -1
  38. package/dist/import/generator.d.ts.map +1 -1
  39. package/dist/import/parser.d.ts.map +1 -1
  40. package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
  41. package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
  42. package/dist/integrity.json +6 -5
  43. package/dist/lint/audit-catalog.d.ts.map +1 -1
  44. package/dist/lint/post-synth/index.d.ts.map +1 -1
  45. package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
  46. package/dist/lint/post-synth/wk8605.d.ts +23 -0
  47. package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
  48. package/dist/manifest.json +1 -1
  49. package/dist/meta.json +156 -17
  50. package/dist/okf/index.md +4 -0
  51. package/dist/okf/rules/WK8605.md +11 -0
  52. package/dist/okf/types/APIGroup.md +3 -3
  53. package/dist/okf/types/APIGroupList.md +1 -1
  54. package/dist/okf/types/APIResourceList.md +1 -1
  55. package/dist/okf/types/APIService.md +1 -1
  56. package/dist/okf/types/APIServiceList.md +2 -2
  57. package/dist/okf/types/APIVersions.md +1 -1
  58. package/dist/okf/types/BatchJob.md +1 -1
  59. package/dist/okf/types/CSIDriver.md +1 -1
  60. package/dist/okf/types/CSIDriverList.md +2 -2
  61. package/dist/okf/types/CSINode.md +1 -1
  62. package/dist/okf/types/CSINodeList.md +2 -2
  63. package/dist/okf/types/CSIStorageCapacity.md +2 -2
  64. package/dist/okf/types/CSIStorageCapacityList.md +2 -2
  65. package/dist/okf/types/CertificateSigningRequest.md +1 -1
  66. package/dist/okf/types/CertificateSigningRequestList.md +2 -2
  67. package/dist/okf/types/ClusterRole.md +1 -1
  68. package/dist/okf/types/ClusterRoleBindingList.md +2 -2
  69. package/dist/okf/types/ClusterRoleList.md +2 -2
  70. package/dist/okf/types/ClusterTrustBundle.md +1 -1
  71. package/dist/okf/types/ClusterTrustBundleList.md +2 -2
  72. package/dist/okf/types/ComponentStatus.md +1 -1
  73. package/dist/okf/types/ComponentStatusList.md +2 -2
  74. package/dist/okf/types/ConfigMapList.md +2 -2
  75. package/dist/okf/types/ControllerRevisionList.md +2 -2
  76. package/dist/okf/types/CoreEventList.md +2 -2
  77. package/dist/okf/types/CronJob.md +1 -1
  78. package/dist/okf/types/CronJobList.md +2 -2
  79. package/dist/okf/types/CustomResourceDefinition.md +1 -1
  80. package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
  81. package/dist/okf/types/DaemonSet.md +1 -1
  82. package/dist/okf/types/DaemonSetList.md +2 -2
  83. package/dist/okf/types/DeleteOptions.md +1 -1
  84. package/dist/okf/types/Deploy.md +1 -1
  85. package/dist/okf/types/DeploymentList.md +2 -2
  86. package/dist/okf/types/DeviceClass.md +1 -1
  87. package/dist/okf/types/DeviceClassList.md +2 -2
  88. package/dist/okf/types/DeviceTaintRule.md +1 -1
  89. package/dist/okf/types/DeviceTaintRuleList.md +2 -2
  90. package/dist/okf/types/EndpointSlice.md +2 -2
  91. package/dist/okf/types/EndpointSliceList.md +2 -2
  92. package/dist/okf/types/Endpoints.md +1 -1
  93. package/dist/okf/types/EndpointsList.md +2 -2
  94. package/dist/okf/types/Event.md +2 -2
  95. package/dist/okf/types/EventsEvent.md +2 -2
  96. package/dist/okf/types/EventsEventList.md +2 -2
  97. package/dist/okf/types/Eviction.md +1 -1
  98. package/dist/okf/types/FlowSchema.md +1 -1
  99. package/dist/okf/types/FlowSchemaList.md +2 -2
  100. package/dist/okf/types/GrafanaDashboard.md +14 -0
  101. package/dist/okf/types/GrafanaDatasource.md +14 -0
  102. package/dist/okf/types/GrafanaFolder.md +14 -0
  103. package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
  104. package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
  105. package/dist/okf/types/IPAddress.md +1 -1
  106. package/dist/okf/types/IPAddressList.md +2 -2
  107. package/dist/okf/types/Ing.md +1 -1
  108. package/dist/okf/types/IngressClass.md +1 -1
  109. package/dist/okf/types/IngressClassList.md +2 -2
  110. package/dist/okf/types/IngressList.md +2 -2
  111. package/dist/okf/types/JobList.md +2 -2
  112. package/dist/okf/types/Lease.md +1 -1
  113. package/dist/okf/types/LeaseCandidate.md +1 -1
  114. package/dist/okf/types/LeaseCandidateList.md +2 -2
  115. package/dist/okf/types/LeaseList.md +2 -2
  116. package/dist/okf/types/LimitRange.md +1 -1
  117. package/dist/okf/types/LimitRangeList.md +2 -2
  118. package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
  119. package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
  120. package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
  121. package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
  122. package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
  123. package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
  124. package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
  125. package/dist/okf/types/Namespace.md +1 -1
  126. package/dist/okf/types/NamespaceList.md +2 -2
  127. package/dist/okf/types/NetPol.md +1 -1
  128. package/dist/okf/types/NetworkPolicyList.md +2 -2
  129. package/dist/okf/types/Node.md +1 -1
  130. package/dist/okf/types/NodeList.md +2 -2
  131. package/dist/okf/types/PersistentVolume.md +1 -1
  132. package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
  133. package/dist/okf/types/PersistentVolumeList.md +2 -2
  134. package/dist/okf/types/PodCertificateRequest.md +1 -1
  135. package/dist/okf/types/PodCertificateRequestList.md +2 -2
  136. package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
  137. package/dist/okf/types/PodList.md +2 -2
  138. package/dist/okf/types/PodTemplateList.md +2 -2
  139. package/dist/okf/types/PriorityClassList.md +2 -2
  140. package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
  141. package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
  142. package/dist/okf/types/ReplicaSet.md +1 -1
  143. package/dist/okf/types/ReplicaSetList.md +2 -2
  144. package/dist/okf/types/ReplicationController.md +1 -1
  145. package/dist/okf/types/ReplicationControllerList.md +2 -2
  146. package/dist/okf/types/ResourceClaim.md +1 -1
  147. package/dist/okf/types/ResourceClaimList.md +2 -2
  148. package/dist/okf/types/ResourceClaimTemplate.md +1 -1
  149. package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
  150. package/dist/okf/types/ResourceQuota.md +1 -1
  151. package/dist/okf/types/ResourceQuotaList.md +2 -2
  152. package/dist/okf/types/ResourceSlice.md +1 -1
  153. package/dist/okf/types/ResourceSliceList.md +2 -2
  154. package/dist/okf/types/RoleBindingList.md +2 -2
  155. package/dist/okf/types/RoleList.md +2 -2
  156. package/dist/okf/types/RuntimeClass.md +2 -2
  157. package/dist/okf/types/RuntimeClassList.md +2 -2
  158. package/dist/okf/types/Scale.md +1 -1
  159. package/dist/okf/types/SecretList.md +2 -2
  160. package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
  161. package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
  162. package/dist/okf/types/Service.md +1 -1
  163. package/dist/okf/types/ServiceAccountList.md +2 -2
  164. package/dist/okf/types/ServiceCIDR.md +1 -1
  165. package/dist/okf/types/ServiceCIDRList.md +2 -2
  166. package/dist/okf/types/ServiceList.md +2 -2
  167. package/dist/okf/types/StatefulSet.md +1 -1
  168. package/dist/okf/types/StatefulSetList.md +2 -2
  169. package/dist/okf/types/Status.md +2 -2
  170. package/dist/okf/types/StorageClass.md +1 -1
  171. package/dist/okf/types/StorageClassList.md +2 -2
  172. package/dist/okf/types/StorageVersionMigration.md +1 -1
  173. package/dist/okf/types/StorageVersionMigrationList.md +2 -2
  174. package/dist/okf/types/SubjectAccessReview.md +1 -1
  175. package/dist/okf/types/TokenRequest.md +1 -1
  176. package/dist/okf/types/TokenReview.md +1 -1
  177. package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
  178. package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
  179. package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
  180. package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
  181. package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
  182. package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
  183. package/dist/okf/types/VolumeAttachment.md +1 -1
  184. package/dist/okf/types/VolumeAttachmentList.md +2 -2
  185. package/dist/okf/types/VolumeAttributesClassList.md +2 -2
  186. package/dist/op/activities/argo.d.ts.map +1 -1
  187. package/dist/op/activities/index.d.ts +3 -3
  188. package/dist/op/activities/index.d.ts.map +1 -1
  189. package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
  190. package/dist/op/builders.d.ts.map +1 -1
  191. package/dist/rules/wk8605.ts +131 -0
  192. package/dist/skills/chant-k8s.md +1 -1
  193. package/dist/spec/parse.d.ts +27 -0
  194. package/dist/spec/parse.d.ts.map +1 -1
  195. package/dist/types/index.d.ts +5360 -972
  196. package/dist/variables.d.ts.map +1 -1
  197. package/package.json +4 -4
  198. package/src/codegen/declarations.test.ts +118 -0
  199. package/src/codegen/generate-typescript.ts +69 -4
  200. package/src/codegen/generate.ts +15 -6
  201. package/src/composites/catalog.ts +6 -0
  202. package/src/composites/gke-otel-collector.ts +6 -1
  203. package/src/composites/index.ts +1 -0
  204. package/src/composites/otel-collector-agent.ts +39 -2
  205. package/src/composites/otel-collector-node.test.ts +174 -0
  206. package/src/composites/otel-collector-node.ts +213 -0
  207. package/src/composites/otel-collector.ts +15 -1
  208. package/src/crd/crd-sources.ts +26 -0
  209. package/src/crd/loader.test.ts +9 -1
  210. package/src/crd/loader.ts +26 -3
  211. package/src/crd/oci-chart.test.ts +149 -0
  212. package/src/crd/oci-chart.ts +178 -0
  213. package/src/crd/types.ts +5 -0
  214. package/src/generated/index.d.ts +5360 -972
  215. package/src/generated/index.ts +23 -0
  216. package/src/generated/lexicon-k8s.json +156 -17
  217. package/src/generated/operations.json +48 -0
  218. package/src/import/embedded-live.test.ts +46 -4
  219. package/src/import/embedded-roundtrip.test.ts +73 -7
  220. package/src/import/embedded-types.e2e.test.ts +3 -1
  221. package/src/import/embedded.test.ts +64 -0
  222. package/src/import/embedded.ts +31 -2
  223. package/src/import/generator.test.ts +19 -0
  224. package/src/import/generator.ts +20 -2
  225. package/src/import/testdata/embedded/README.md +4 -1
  226. package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
  227. package/src/import/testdata/embedded/fixtures.ts +18 -0
  228. package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
  229. package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
  230. package/src/lint/audit-catalog.ts +1 -0
  231. package/src/lint/post-synth/index.ts +2 -0
  232. package/src/lint/post-synth/post-synth.test.ts +3 -3
  233. package/src/lint/post-synth/wk8605.test.ts +141 -0
  234. package/src/lint/post-synth/wk8605.ts +131 -0
  235. package/src/skills/chant-k8s.md +1 -1
  236. package/src/spec/parse.test.ts +118 -0
  237. package/src/spec/parse.ts +250 -29
@@ -5,9 +5,11 @@
5
5
  * The parser offers two kinds of place to core's embedded-content resolver:
6
6
  *
7
7
  * - every `data` value of a ConfigMap, as text (a collector's `config.yaml`,
8
- * a Prometheus rule file, a Grafana dashboard's JSON);
8
+ * a Prometheus rule file, an `alertmanager.yml`, a Grafana dashboard's
9
+ * JSON);
9
10
  * - a `monitoring.coreos.com` PrometheusRule's `spec.groups`, as the rule file
10
- * `{ groups }` those groups would make.
11
+ * `{ groups }` those groups would make;
12
+ * - a Grafana Operator `GrafanaDashboard`'s `spec.json`, as text (#3015).
11
13
  *
12
14
  * Which lexicon imports the content is decided by core at run time, from the
13
15
  * lexicons that register an `embeddedImporters()`; this module names none of
@@ -35,10 +37,19 @@ function hintFor(key: string, doc: unknown, labels: Record<string, string>): Emb
35
37
  if (Array.isArray(doc.panels) && (GRAFANA_DASHBOARD_LABEL in labels || key.endsWith(".json"))) {
36
38
  return { lexicon: "grafana", what: "a Grafana dashboard" };
37
39
  }
40
+ const v2Dashboard =
41
+ (doc.kind === "Dashboard" && typeof doc.apiVersion === "string" && doc.apiVersion.startsWith("dashboard.grafana.app/")) ||
42
+ (isObject(doc.elements) && isObject(doc.layout));
43
+ if (v2Dashboard && (GRAFANA_DASHBOARD_LABEL in labels || key.endsWith(".json"))) {
44
+ return { lexicon: "grafana", what: "a Grafana dashboard" };
45
+ }
38
46
  if (isObject(doc.service) && isObject(doc.service.pipelines)) {
39
47
  return { lexicon: "otel", what: "an OpenTelemetry Collector config" };
40
48
  }
41
49
  if (looksLikeRuleGroups(doc.groups)) return { lexicon: "prometheus", what: "a Prometheus rule file" };
50
+ if ((isObject(doc.route) || Array.isArray(doc.receivers)) && !("apiVersion" in doc) && !("kind" in doc)) {
51
+ return { lexicon: "prometheus", what: "an Alertmanager config" };
52
+ }
42
53
  return undefined;
43
54
  }
44
55
 
@@ -87,6 +98,24 @@ export function delegateEmbedded(
87
98
  return;
88
99
  }
89
100
 
101
+ if (type === "K8s::Grafana::GrafanaDashboard" && isObject(properties.spec) && typeof properties.spec.json === "string") {
102
+ const text = properties.spec.json;
103
+ const doc = embeddedDocument(text);
104
+ if (!isObject(doc)) return;
105
+ const ref = embedded.resolve({
106
+ host: "k8s",
107
+ hostType: type,
108
+ location: `GrafanaDashboard ${name} spec.json`,
109
+ directory: name,
110
+ text,
111
+ document: doc,
112
+ labels,
113
+ expectedOwner: { lexicon: "grafana", what: "a Grafana dashboard" },
114
+ });
115
+ if (ref) properties.spec = { ...properties.spec, json: ref };
116
+ return;
117
+ }
118
+
90
119
  if (type === "K8s::Monitoring::PrometheusRule" && isObject(properties.spec) && Array.isArray(properties.spec.groups)) {
91
120
  const groups = properties.spec.groups;
92
121
  const ref = embedded.resolve({
@@ -112,6 +112,25 @@ describe("K8sGenerator", () => {
112
112
  expect(files[0].content).toContain("ServicePort");
113
113
  });
114
114
 
115
+ // chant #3093 — the property classes carry their members, so a Role's
116
+ // rules built as IngressRules would no longer type-check.
117
+ test("a Role's rules use the PolicyRule constructor, an Ingress's the IngressRule one", () => {
118
+ const files = generator.generate(makeIR([
119
+ {
120
+ logicalId: "role",
121
+ type: "K8s::Rbac::Role",
122
+ properties: { metadata: { name: "r" }, rules: [{ apiGroups: [""], resources: ["pods"], verbs: ["get"] }] },
123
+ },
124
+ {
125
+ logicalId: "clusterRole",
126
+ type: "K8s::Rbac::ClusterRole",
127
+ properties: { metadata: { name: "cr" }, rules: [{ apiGroups: [""], resources: ["nodes"], verbs: ["list"] }] },
128
+ },
129
+ ]));
130
+ expect(files[0].content).toContain("new PolicyRule(");
131
+ expect(files[0].content).not.toContain("IngressRule");
132
+ });
133
+
115
134
  test("handles empty IR", () => {
116
135
  const ir = makeIR([]);
117
136
  const files = generator.generate(ir);
@@ -107,6 +107,23 @@ const SERVICE_PORT_TYPES = new Set([
107
107
  "K8s::Core::Service",
108
108
  ]);
109
109
 
110
+ /**
111
+ * A Role's and a ClusterRole's top-level `rules` are PolicyRules, not the
112
+ * IngressRules {@link PROPERTY_CONSTRUCTORS} maps `rules` to. Since the
113
+ * property classes carry their members (chant #3093), an IngressRule built
114
+ * from `apiGroups`/`verbs` no longer type-checks.
115
+ */
116
+ const POLICY_RULE_TYPES = new Set([
117
+ "K8s::Rbac::Role",
118
+ "K8s::Rbac::ClusterRole",
119
+ ]);
120
+
121
+ /** The constructor for `key` on a resource of `parentType`. */
122
+ function constructorFor(key: string, parentType: string): string | undefined {
123
+ if (key === "rules" && POLICY_RULE_TYPES.has(parentType)) return "PolicyRule";
124
+ return PROPERTY_CONSTRUCTORS[key];
125
+ }
126
+
110
127
  /**
111
128
  * Generate TypeScript source code from a Kubernetes IR.
112
129
  */
@@ -132,6 +149,7 @@ export class K8sGenerator implements TypeScriptGenerator {
132
149
  ...usedConstructors,
133
150
  ...Object.values(PROPERTY_CONSTRUCTORS),
134
151
  "ServicePort",
152
+ "PolicyRule",
135
153
  ...ir.resources.map((r) => r.logicalId),
136
154
  ]);
137
155
 
@@ -197,7 +215,7 @@ export class K8sGenerator implements TypeScriptGenerator {
197
215
  continue;
198
216
  }
199
217
 
200
- const constructor = PROPERTY_CONSTRUCTORS[key];
218
+ const constructor = constructorFor(key, parentType);
201
219
  if (!constructor) continue;
202
220
 
203
221
  if (Array.isArray(value)) {
@@ -243,7 +261,7 @@ export class K8sGenerator implements TypeScriptGenerator {
243
261
  }
244
262
 
245
263
  // Check if this key maps to a property constructor
246
- const constructor = PROPERTY_CONSTRUCTORS[key];
264
+ const constructor = constructorFor(key, parentType);
247
265
  if (constructor) {
248
266
  // Array of constructors (containers, volumes, ports, env, etc.)
249
267
  if (Array.isArray(value)) {
@@ -1,7 +1,7 @@
1
1
  # Embedded-content import fixtures
2
2
 
3
3
  Manifests that hold another lexicon's content, for `embedded-roundtrip.test.ts`
4
- and `embedded-types.e2e.test.ts` (#2962).
4
+ `embedded-live.test.ts` and `embedded-types.e2e.test.ts` (#2962, #3031).
5
5
 
6
6
  | File | Source |
7
7
  |---|---|
@@ -9,3 +9,6 @@ and `embedded-types.e2e.test.ts` (#2962).
9
9
  | `node-exporter-prometheusrule.yaml` | prometheus-operator/kube-prometheus `v0.19.0`, `manifests/nodeExporter-prometheusRule.yaml`, unchanged. |
10
10
  | `grafana-dashboard-configmap.yaml` | prometheus-operator/kube-prometheus `v0.19.0`, `manifests/grafana-dashboardDefinitions.yaml`: the `grafana-dashboard-alertmanager-overview` item of that ConfigMapList, written as a ConfigMap of its own with the Grafana sidecar's `grafana_dashboard: "1"` label added, re-serialized by js-yaml. The dashboard JSON is unchanged. |
11
11
  | `agent-observability.yaml` | `chant build src --lexicon k8s` of `examples/agent-observability` as of #2954: collector ConfigMaps from the k8s collector composites, Prometheus's `rules.yml` from `ruleFileYaml`, and the Grafana dashboard, datasource and provider ConfigMaps from `GrafanaConfigMaps` (`@intentius/chant-lexicon-grafana/k8s`). |
12
+ | `alertmanager-configmap.yaml` | prometheus-community/helm-charts at `8d235acbefe2d95f1b1365fafdf07279ae05176f`, chart alertmanager 2.0.1 (Alertmanager v0.34.1), Apache-2.0: `helm template alertmanager alertmanager --repo https://prometheus-community.github.io/helm-charts --version 2.0.1 --namespace monitoring --show-only templates/configmap.yaml`, with `config:` set to Alertmanager's own `doc/examples/simple.yml` at v0.34.1 (Apache-2.0; vendored in the prometheus lexicon as `src/import/testdata/upstream/alertmanager-simple.yml`) plus the chart's `enabled: true`. The rendered output is unchanged, apart from the leading `---`. |
13
+ | `grafana-v2-dashboard-configmap.yaml` | The grafana lexicon's `test/fixtures/exports/grafana-13.2.2/checkout.v2-resource.json` (Grafana 13.2.2's "V2 Resource" export, provenance in that directory's README), written as the `checkout.json` value of a ConfigMap with the Grafana sidecar's `grafana_dashboard: "1"` label, serialized by js-yaml. The dashboard JSON is unchanged. |
14
+ | `grafana-operator-dashboard.yaml` | The dashboard JSON of `grafana-dashboard-configmap.yaml`, unchanged, as the `spec.json` of a Grafana Operator `GrafanaDashboard` (`grafana.integreatly.org/v1beta1`, Grafana Operator v5.25.0) with an `instanceSelector`, a `folder` and a `resyncPeriod`, serialized by js-yaml (#3015). |
@@ -0,0 +1,91 @@
1
+ # Source: alertmanager/templates/configmap.yaml
2
+ apiVersion: v1
3
+ kind: ConfigMap
4
+ metadata:
5
+ name: alertmanager
6
+ labels:
7
+ helm.sh/chart: alertmanager-2.0.1
8
+ app.kubernetes.io/name: alertmanager
9
+ app.kubernetes.io/instance: alertmanager
10
+ app.kubernetes.io/version: "v0.34.1"
11
+ app.kubernetes.io/managed-by: Helm
12
+ namespace: monitoring
13
+ data:
14
+ alertmanager.yml: |
15
+ global:
16
+ smtp_auth_password: password
17
+ smtp_auth_username: alertmanager
18
+ smtp_from: alertmanager@example.org
19
+ smtp_smarthost: localhost:25
20
+ inhibit_rules:
21
+ - equal:
22
+ - alertname
23
+ - cluster
24
+ - service
25
+ source_matchers:
26
+ - severity="critical"
27
+ target_matchers:
28
+ - severity="warning"
29
+ receivers:
30
+ - email_configs:
31
+ - to: team-X+alerts@example.org
32
+ name: team-X-mails
33
+ - email_configs:
34
+ - to: team-X+alerts-critical@example.org
35
+ name: team-X-pager
36
+ pagerduty_configs:
37
+ - service_key: <team-X-key>
38
+ - email_configs:
39
+ - to: team-Y+alerts@example.org
40
+ name: team-Y-mails
41
+ - name: team-Y-pager
42
+ pagerduty_configs:
43
+ - service_key: <team-Y-key>
44
+ - name: team-DB-pager
45
+ pagerduty_configs:
46
+ - service_key: <team-DB-key>
47
+ route:
48
+ group_by:
49
+ - alertname
50
+ - cluster
51
+ - service
52
+ group_interval: 5m
53
+ group_wait: 30s
54
+ receiver: team-X-mails
55
+ repeat_interval: 3h
56
+ routes:
57
+ - matchers:
58
+ - service=~"foo1|foo2|baz"
59
+ receiver: team-X-mails
60
+ routes:
61
+ - matchers:
62
+ - severity="critical"
63
+ receiver: team-X-pager
64
+ - matchers:
65
+ - service="files"
66
+ receiver: team-Y-mails
67
+ routes:
68
+ - matchers:
69
+ - severity="critical"
70
+ receiver: team-Y-pager
71
+ - group_by:
72
+ - alertname
73
+ - cluster
74
+ - database
75
+ matchers:
76
+ - service="database"
77
+ receiver: team-DB-pager
78
+ routes:
79
+ - continue: true
80
+ matchers:
81
+ - owner="team-X"
82
+ receiver: team-X-pager
83
+ - matchers:
84
+ - owner="team-Y"
85
+ receiver: team-Y-pager
86
+ templates:
87
+ - /etc/alertmanager/template/*.tmpl
88
+ tracing:
89
+ endpoint: localhost:4317
90
+ insecure: true
91
+ sampling_fraction: 1
@@ -8,6 +8,7 @@
8
8
  import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "fs";
9
9
  import { join, relative, resolve } from "path";
10
10
  import { importCommand, type ImportResult } from "@intentius/chant/cli/commands/import";
11
+ import { parsePrometheusYaml } from "@intentius/chant-lexicon-prometheus/import/parser";
11
12
 
12
13
  export const pkgDir = resolve(import.meta.dirname, "../../../..");
13
14
  export const repoRoot = resolve(pkgDir, "../..");
@@ -51,3 +52,20 @@ export async function importManifest(yaml: string, options: { detect?: boolean }
51
52
  export function removeDir(dir: string): void {
52
53
  rmSync(dir, { recursive: true, force: true });
53
54
  }
55
+
56
+ /**
57
+ * An alertmanager.yml as the prometheus importer reads it, receivers and
58
+ * time intervals sorted by name (the serializer sorts them): what an
59
+ * imported ConfigMap's `alertmanager.yml` must give back (#3031).
60
+ */
61
+ export function alertmanagerConfig(text: string): Record<string, unknown> {
62
+ const parsed = parsePrometheusYaml(text);
63
+ if (parsed.kind !== "alertmanager") throw new Error("not an alertmanager.yml");
64
+ const byName = (a: { name: string }, b: { name: string }) => a.name.localeCompare(b.name);
65
+ const { receivers, time_intervals, ...rest } = parsed.config;
66
+ return {
67
+ ...rest,
68
+ ...(receivers ? { receivers: [...receivers].sort(byName) } : {}),
69
+ ...(time_intervals ? { time_intervals: [...time_intervals].sort(byName) } : {}),
70
+ };
71
+ }
@@ -0,0 +1,363 @@
1
+ apiVersion: grafana.integreatly.org/v1beta1
2
+ kind: GrafanaDashboard
3
+ metadata:
4
+ name: alertmanager-overview
5
+ namespace: monitoring
6
+ spec:
7
+ instanceSelector:
8
+ matchLabels:
9
+ dashboards: grafana
10
+ folder: Alertmanager
11
+ resyncPeriod: 5m
12
+ json: |-
13
+ {
14
+ "graphTooltip": 1,
15
+ "panels": [
16
+ {
17
+ "collapsed": false,
18
+ "gridPos": {
19
+ "h": 1,
20
+ "w": 24,
21
+ "x": 0,
22
+ "y": 0
23
+ },
24
+ "id": 1,
25
+ "panels": [
26
+
27
+ ],
28
+ "title": "Alerts",
29
+ "type": "row"
30
+ },
31
+ {
32
+ "datasource": {
33
+ "type": "prometheus",
34
+ "uid": "$datasource"
35
+ },
36
+ "description": "current set of alerts stored in the Alertmanager",
37
+ "fieldConfig": {
38
+ "defaults": {
39
+ "custom": {
40
+ "fillOpacity": 10,
41
+ "showPoints": "never",
42
+ "stacking": {
43
+ "mode": "normal"
44
+ }
45
+ },
46
+ "unit": "none"
47
+ }
48
+ },
49
+ "gridPos": {
50
+ "h": 7,
51
+ "w": 12,
52
+ "x": 0,
53
+ "y": 1
54
+ },
55
+ "id": 2,
56
+ "options": {
57
+ "legend": {
58
+ "showLegend": false
59
+ },
60
+ "tooltip": {
61
+ "mode": "multi"
62
+ }
63
+ },
64
+ "pluginVersion": "v13.0.0",
65
+ "targets": [
66
+ {
67
+ "datasource": {
68
+ "type": "prometheus",
69
+ "uid": "$datasource"
70
+ },
71
+ "expr": "sum(alertmanager_alerts{namespace=~\"$namespace\",service=~\"$service\"}) by (namespace,service,instance)",
72
+ "intervalFactor": 2,
73
+ "legendFormat": "{{instance}}"
74
+ }
75
+ ],
76
+ "title": "Alerts",
77
+ "type": "timeseries"
78
+ },
79
+ {
80
+ "datasource": {
81
+ "type": "prometheus",
82
+ "uid": "$datasource"
83
+ },
84
+ "description": "rate of successful and invalid alerts received by the Alertmanager",
85
+ "fieldConfig": {
86
+ "defaults": {
87
+ "custom": {
88
+ "fillOpacity": 10,
89
+ "showPoints": "never",
90
+ "stacking": {
91
+ "mode": "normal"
92
+ }
93
+ },
94
+ "unit": "ops"
95
+ }
96
+ },
97
+ "gridPos": {
98
+ "h": 7,
99
+ "w": 12,
100
+ "x": 12,
101
+ "y": 1
102
+ },
103
+ "id": 3,
104
+ "options": {
105
+ "legend": {
106
+ "showLegend": false
107
+ },
108
+ "tooltip": {
109
+ "mode": "multi"
110
+ }
111
+ },
112
+ "pluginVersion": "v13.0.0",
113
+ "targets": [
114
+ {
115
+ "datasource": {
116
+ "type": "prometheus",
117
+ "uid": "$datasource"
118
+ },
119
+ "expr": "sum(rate(alertmanager_alerts_received_total{namespace=~\"$namespace\",service=~\"$service\"}[$__rate_interval])) by (namespace,service,instance)",
120
+ "intervalFactor": 2,
121
+ "legendFormat": "{{instance}} Received"
122
+ },
123
+ {
124
+ "datasource": {
125
+ "type": "prometheus",
126
+ "uid": "$datasource"
127
+ },
128
+ "expr": "sum(rate(alertmanager_alerts_invalid_total{namespace=~\"$namespace\",service=~\"$service\"}[$__rate_interval])) by (namespace,service,instance)",
129
+ "intervalFactor": 2,
130
+ "legendFormat": "{{instance}} Invalid"
131
+ }
132
+ ],
133
+ "title": "Alerts receive rate",
134
+ "type": "timeseries"
135
+ },
136
+ {
137
+ "collapsed": false,
138
+ "gridPos": {
139
+ "h": 1,
140
+ "w": 24,
141
+ "x": 0,
142
+ "y": 8
143
+ },
144
+ "id": 4,
145
+ "panels": [
146
+
147
+ ],
148
+ "title": "Notifications",
149
+ "type": "row"
150
+ },
151
+ {
152
+ "datasource": {
153
+ "type": "prometheus",
154
+ "uid": "$datasource"
155
+ },
156
+ "description": "rate of successful and invalid notifications sent by the Alertmanager",
157
+ "fieldConfig": {
158
+ "defaults": {
159
+ "custom": {
160
+ "fillOpacity": 10,
161
+ "showPoints": "never",
162
+ "stacking": {
163
+ "mode": "normal"
164
+ }
165
+ },
166
+ "unit": "ops"
167
+ }
168
+ },
169
+ "gridPos": {
170
+ "h": 7,
171
+ "w": 12,
172
+ "x": 0,
173
+ "y": 9
174
+ },
175
+ "id": 5,
176
+ "options": {
177
+ "legend": {
178
+ "showLegend": false
179
+ },
180
+ "tooltip": {
181
+ "mode": "multi"
182
+ }
183
+ },
184
+ "pluginVersion": "v13.0.0",
185
+ "repeat": "integration",
186
+ "targets": [
187
+ {
188
+ "datasource": {
189
+ "type": "prometheus",
190
+ "uid": "$datasource"
191
+ },
192
+ "expr": "sum(rate(alertmanager_notifications_total{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (integration,namespace,service,instance)",
193
+ "intervalFactor": 2,
194
+ "legendFormat": "{{instance}} Total"
195
+ },
196
+ {
197
+ "datasource": {
198
+ "type": "prometheus",
199
+ "uid": "$datasource"
200
+ },
201
+ "expr": "sum(rate(alertmanager_notifications_failed_total{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (integration,namespace,service,instance)",
202
+ "intervalFactor": 2,
203
+ "legendFormat": "{{instance}} Failed"
204
+ }
205
+ ],
206
+ "title": "$integration: Notifications Send Rate",
207
+ "type": "timeseries"
208
+ },
209
+ {
210
+ "datasource": {
211
+ "type": "prometheus",
212
+ "uid": "$datasource"
213
+ },
214
+ "description": "latency of notifications sent by the Alertmanager",
215
+ "fieldConfig": {
216
+ "defaults": {
217
+ "custom": {
218
+ "fillOpacity": 10,
219
+ "showPoints": "never",
220
+ "stacking": {
221
+ "mode": "normal"
222
+ }
223
+ },
224
+ "unit": "s"
225
+ }
226
+ },
227
+ "gridPos": {
228
+ "h": 7,
229
+ "w": 12,
230
+ "x": 12,
231
+ "y": 9
232
+ },
233
+ "id": 6,
234
+ "options": {
235
+ "legend": {
236
+ "showLegend": false
237
+ },
238
+ "tooltip": {
239
+ "mode": "multi"
240
+ }
241
+ },
242
+ "pluginVersion": "v13.0.0",
243
+ "repeat": "integration",
244
+ "targets": [
245
+ {
246
+ "datasource": {
247
+ "type": "prometheus",
248
+ "uid": "$datasource"
249
+ },
250
+ "expr": "histogram_quantile(0.99,\n sum(rate(alertmanager_notification_latency_seconds_bucket{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (le,namespace,service,instance)\n)\n",
251
+ "intervalFactor": 2,
252
+ "legendFormat": "{{instance}} 99th Percentile"
253
+ },
254
+ {
255
+ "datasource": {
256
+ "type": "prometheus",
257
+ "uid": "$datasource"
258
+ },
259
+ "expr": "histogram_quantile(0.50,\n sum(rate(alertmanager_notification_latency_seconds_bucket{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (le,namespace,service,instance)\n)\n",
260
+ "intervalFactor": 2,
261
+ "legendFormat": "{{instance}} Median"
262
+ },
263
+ {
264
+ "datasource": {
265
+ "type": "prometheus",
266
+ "uid": "$datasource"
267
+ },
268
+ "expr": "sum(rate(alertmanager_notification_latency_seconds_sum{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (namespace,service,instance)\n/\nsum(rate(alertmanager_notification_latency_seconds_count{namespace=~\"$namespace\",service=~\"$service\", integration=\"$integration\"}[$__rate_interval])) by (namespace,service,instance)\n",
269
+ "intervalFactor": 2,
270
+ "legendFormat": "{{instance}} Average"
271
+ }
272
+ ],
273
+ "title": "$integration: Notification Duration",
274
+ "type": "timeseries"
275
+ }
276
+ ],
277
+ "schemaVersion": 39,
278
+ "tags": [
279
+ "alertmanager-mixin"
280
+ ],
281
+ "templating": {
282
+ "list": [
283
+ {
284
+ "current": {
285
+ "selected": false,
286
+ "text": "Prometheus",
287
+ "value": "Prometheus"
288
+ },
289
+ "hide": 0,
290
+ "label": "Data Source",
291
+ "name": "datasource",
292
+ "query": "prometheus",
293
+ "type": "datasource"
294
+ },
295
+ {
296
+ "current": {
297
+ "selected": false,
298
+ "text": "",
299
+ "value": ""
300
+ },
301
+ "datasource": {
302
+ "type": "prometheus",
303
+ "uid": "${datasource}"
304
+ },
305
+ "includeAll": false,
306
+ "label": "namespace",
307
+ "name": "namespace",
308
+ "query": "label_values(alertmanager_alerts, namespace)",
309
+ "refresh": 2,
310
+ "sort": 1,
311
+ "type": "query"
312
+ },
313
+ {
314
+ "current": {
315
+ "selected": false,
316
+ "text": "",
317
+ "value": ""
318
+ },
319
+ "datasource": {
320
+ "type": "prometheus",
321
+ "uid": "${datasource}"
322
+ },
323
+ "includeAll": false,
324
+ "label": "service",
325
+ "name": "service",
326
+ "query": "label_values(alertmanager_alerts, service)",
327
+ "refresh": 2,
328
+ "sort": 1,
329
+ "type": "query"
330
+ },
331
+ {
332
+ "current": {
333
+ "selected": false,
334
+ "text": "$__all",
335
+ "value": "$__all"
336
+ },
337
+ "datasource": {
338
+ "type": "prometheus",
339
+ "uid": "${datasource}"
340
+ },
341
+ "hide": 2,
342
+ "includeAll": true,
343
+ "name": "integration",
344
+ "query": "label_values(alertmanager_notifications_total{integration=~\".*\"}, integration)",
345
+ "refresh": 2,
346
+ "sort": 1,
347
+ "type": "query"
348
+ }
349
+ ]
350
+ },
351
+ "time": {
352
+ "from": "now-1h",
353
+ "to": "now"
354
+ },
355
+ "timepicker": {
356
+ "refresh_intervals": [
357
+ "30s"
358
+ ]
359
+ },
360
+ "timezone": "utc",
361
+ "title": "Alertmanager / Overview",
362
+ "uid": "alertmanager-overview"
363
+ }