Skip to content

Commit

Permalink
fix: 869, support for non default namespace for adot (#873)
Browse files Browse the repository at this point in the history
* fix: 869, support for non default namespace for adot

* fix: 869, support for non default namespace for adot
  • Loading branch information
nrajb committed Nov 10, 2023
1 parent 8daa266 commit a63f272
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
21 changes: 20 additions & 1 deletion docs/addons/adot-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Amazon EKS supports using Amazon EKS API to install and manage the AWS Distro for OpenTelemetry (ADOT) Operator. This enables a simplified experience for instrumenting your applications running on Amazon EKS to send metric and trace data to multiple monitoring service options like Amazon CloudWatch, Prometheus, and X-Ray.

This add-on is not automatically installed when you first create a cluster, it must be added to the cluster in order to manage ADOT Collectors.
This add-on is not automatically installed when you first create a cluster, it must be added to the cluster in order to manage ADOT Collectors. For creating add-on in specific namespace, `namespace` property needs to be passed.

For more information on the add-on, please review the [user guide](https://docs.aws.amazon.com/eks/latest/userguide/opentelemetry.html).

Expand All @@ -11,6 +11,7 @@ For more information on the add-on, please review the [user guide](https://docs.

## Usage

### Example with default namespace
```typescript
import * as cdk from 'aws-cdk-lib';
import * as blueprints from '@aws-quickstart/eks-blueprints';
Expand All @@ -25,6 +26,24 @@ const blueprint = blueprints.EksBlueprint.builder()
.build(app, 'my-stack-name');
```

### Example with non-default namespace
```typescript
import * as cdk from 'aws-cdk-lib';
import * as blueprints from '@aws-quickstart/eks-blueprints';

const app = new cdk.App();

const addOn = new blueprints.addons.AdotCollectorAddOn({
namespace:'adot', //User supplied, non-default namespace
version: 'v0.80.0-eksbuild.2'
}),

const blueprint = blueprints.EksBlueprint.builder()
.version("auto")
.addOns(addOn)
.build(app, 'my-stack-name');
```

## Validation

To validate that ADOT add-on is installed properly, ensure that the ADOT kubernetes resources are running in the cluster
Expand Down
18 changes: 18 additions & 0 deletions docs/addons/amp-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ const blueprint = blueprints.EksBlueprint.builder()
.build(app, 'my-stack-name');
```

With the same pattern, to deploy ADOT collector in non-default namespace:

```typescript
import * as cdk from 'aws-cdk-lib';
import * as blueprints from '@aws-quickstart/eks-blueprints';

const app = new cdk.App();

const addOn = new blueprints.addons.AmpAddOn({
ampPrometheusEndpoint: ampWorkspace.attrPrometheusEndpoint,
namespace: 'adot'
}),

const blueprint = blueprints.EksBlueprint.builder()
.addOns(addOn)
.build(app, 'my-stack-name');
```

Pattern #2: Overriding property values for Name and Tags for a custom AMP Workspace name and tags. This pattern creates a new AMP workspace with property values passed on such as `workspaceName`, `tags` and deploys an ADOT collector on the namespace specified in `namespace` with name in `name` and `deployment` as the mode to remote write metrics to AMP workspace.

```typescript
Expand Down
18 changes: 18 additions & 0 deletions docs/addons/xray-adot-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ const blueprint = blueprints.EksBlueprint.builder()
.build(app, 'my-stack-name');
```

With the same pattern, to deploy ADOT collector in non-default namespace:

```typescript
import * as cdk from 'aws-cdk-lib';
import * as blueprints from '@aws-quickstart/eks-blueprints';

const app = new cdk.App();

const addOn = new blueprints.addons.XrayAdotAddOn({
ampPrometheusEndpoint: ampWorkspace.attrPrometheusEndpoint,
namespace: 'adot'
}),

const blueprint = blueprints.EksBlueprint.builder()
.addOns(addOn)
.build(app, 'my-stack-name');
```

Pattern # 2 : Overriding Property value for different deployment Modes. This pattern deploys an ADOT collector on the namespace specified in `namespace`, name specified in `name` with `daemonset` as the mode to X-Ray console. Deployment mode can be overridden to any of these values - `deployment`, `daemonset`, `statefulset`, `sidecar`.

```typescript
Expand Down
10 changes: 8 additions & 2 deletions examples/blueprint-construct/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ export default class BlueprintConstruct {
new blueprints.addons.CertManagerAddOn(),
new blueprints.addons.KubeStateMetricsAddOn(),
new blueprints.addons.PrometheusNodeExporterAddOn(),
new blueprints.addons.AdotCollectorAddOn(),
new blueprints.addons.AdotCollectorAddOn({
namespace:'adot',
version: 'v0.80.0-eksbuild.2'
}),
new blueprints.addons.AmpAddOn({
ampPrometheusEndpoint: ampWorkspace.attrPrometheusEndpoint,
namespace: 'adot'
}),
new blueprints.addons.XrayAdotAddOn({
namespace: 'adot'
}),
new blueprints.addons.XrayAdotAddOn(),
new blueprints.addons.XrayAddOn(),
// new blueprints.addons.CloudWatchAdotAddOn(),
// new blueprints.addons.ContainerInsightsAddOn(),
Expand Down
24 changes: 19 additions & 5 deletions lib/addons/adot/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { KubernetesManifest } from "aws-cdk-lib/aws-eks";
import { Construct } from 'constructs';
import { ClusterInfo } from "../../spi";
import { dependable, loadYaml, readYamlDocument, supportsALL } from "../../utils";
import { createNamespace, dependable, loadYaml, readYamlDocument, supportsALL } from "../../utils";
import { CertManagerAddOn } from "../cert-manager";
import { CoreAddOn, CoreAddOnProps } from "../core-addon";
import { getAdotCollectorPolicyDocument } from "./iam-policy";

/**
* Configuration options for the Adot add-on.
*/
export type AdotCollectorAddOnProps = Omit<CoreAddOnProps, "saName" | "addOnName" >;
export type AdotCollectorAddOnProps = Omit<CoreAddOnProps, "saName" | "addOnName" > & {
namespace: string;
};

const defaultProps = {
addOnName: 'adot',
Expand All @@ -26,21 +28,33 @@ const defaultProps = {
export class AdotCollectorAddOn extends CoreAddOn {

constructor(props?: AdotCollectorAddOnProps) {
super({ ...defaultProps, ...props });
super({
...defaultProps,
namespace: props?.namespace ?? defaultProps.namespace,
...props
});

}
@dependable(CertManagerAddOn.name)
deploy(clusterInfo: ClusterInfo): Promise<Construct> {

const cluster = clusterInfo.cluster;

// Create namespace if not default
const ns = createNamespace(this.coreAddOnProps.namespace!, cluster, true, true);

// Applying ADOT Permission manifest
const otelPermissionsDoc = readYamlDocument(__dirname + '/otel-permissions.yaml');
const otelPermissionsManifest = otelPermissionsDoc.split("---").map(e => loadYaml(e));
const otelPermissionsStatement = new KubernetesManifest(cluster.stack, "adot-addon-otelPermissions", {
cluster,
manifest: otelPermissionsManifest,
overwrite: true
overwrite: true,

});


otelPermissionsStatement.node.addDependency(ns);

const addOnPromise = super.deploy(clusterInfo);
addOnPromise.then(addOn => addOn.node.addDependency(otelPermissionsStatement));
return addOnPromise;
Expand Down

0 comments on commit a63f272

Please sign in to comment.