Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Sidecar support #875

Closed
iamhopaul123 opened this issue Apr 27, 2020 · 1 comment
Closed

[Feature] Sidecar support #875

iamhopaul123 opened this issue Apr 27, 2020 · 1 comment
Assignees
Labels
type/design Issues that are design proposals.

Comments

@iamhopaul123
Copy link
Contributor

Overview

Currently adding sidecar container in ecs-preview needs users to run app package then modify the generated CloudFormation template, then push their image manually, which is not an easy task. As a result, we consider adding sidecar patterns for ecs-preview to provide a pleasant experience of adding common sidecar containers.

Type of Sidecars

A sidecar container is a second container added to the task definition. We can generally categorize sidecar containers into three types: explicit sidecar, implicit sidecar (hidecar), and generic sidecar.

Explicit Sidecar

Explicit sidecar is a type of sidecar container which requires users to customized/configured image and explicitly performs as a sidecar container. To take NGINX as an example, users need to configure nginx.conf file and build their own NGINX image. Most of users are aware of the fact that they have NGINX as a sidecar image for their service.

Implicit Sidecar (Hidecar)

Implicit sidecar, on the contrary, doesn’t require users to have their own sidecar image and most of users do not even know the existence of the sidecar container. For example, currently Firelens as a sidecar container help users to route their app log. However, the images used by the sidecar container are basically the same so that users do not need to configure the image itself. AppMesh can be another example since most of cases the sidecar containers consume the same envoy image.

Generic Sidecar

Generic sidecars are sidecar containers that are not supported as a pattern. For example the sidecar requires adding/modifying other resources and IAM policies. According to our tenet Make difficult simple and make impossible possible, we support generic sidecars by allowing them to add addons stack for adding additional resources or policies.

Design Proposal

For explicit sidecar containers, we’ll have a “sidecars” field in the manifest and users can configure their explicit sidecar containers. And for implicit sidecar containers it should be case by case. For example, we’ll have a “firelensLog” field for configuring the log for their application, in which users can configure Firelens if they’d like to use fluentbit to route their log elsewhere. For generic sidecars, we’ll introduce how to add them as sidecars inecs-preview.

Explicit Sidecar

We’ll take X-ray as an example for adding explicit sidecars. To add an X-ray sidecar container to their application, users need to modify their manifest after running app init.

Manifest

sidecars:
  xray:
    port: 2000/udp
    image: 123456789012.dkr.ecr.us-east-2.amazonaws.com/xray-daemon    # Image URL for sidecar container. Local images and images in the Docker Hub registry and ECR repository are supported.
    # credentialParameter: # ARN of the secret containing the private repository credentials.

After configuring the manifest, users can run app deploy to deploy their application with sidecar container.

Accommodate with Current Commands

app show
app show requires no changes.

app logs
app logs will includes the log of the sidecar container.

app status
app status requires no changes.

Implicit Sidecars

Since for implicit sidecars the setting will be case by case. Here we will start with Firelens.

Manifest

logging:                              # Enable Firelens to route your logs (to CloudWatch by default)
  destination:                        # Configure where to send logs to.
    Name: cloudwatch
    # includePattern: ^[a-z][aeiou].*$
    # excludePattern: ^.*[aeiou]$
  enableMetadata: false               # Enable ECS log metadata or not.
  # secretOptions:                      # The secrets to pass to the log configuration from AWS Systems Manager (SSM) Parameter Store.
    # LOG_TOKEN: LOG_TOKEN              # The key is the name of the environment variable, the value is the name of the SSM parameter. 
  # configFile: ./extra.conf            # Path to the local config file for Firelens. Specified to override other configurations.
  # permissionFile: ./permissions.json  # Path to the optional permission file if "configFile" is set.

By default, we'll set the destination to be CloudWatch, and users can modify the destination to somewhere else. However, permission file might be required. See more Firelens example in Appendix.

Accommodate with Current Commands

app show
app show requires no changes.

app logs
app logs will show log of the main container and Firelens sidecar container if destination is set to "cloudwatch". However, it will only show the log of the sidecar container if the main app logs are routed to elsewhere (since it will be difficult for us to get those logs after they are routed to their destinations).

app status
app status requires no changes.

Generic Sidecars

For generic sidecars that we don't have a pattern yet, users can add those sidecars with addon stack. However, since addon stack can only add new resources/policies, if their sidecar containers require any main CFN changes, then they need to modify the CFN template generated by app package. In the future we might have a flag in app deploy that allows them to deploy their modified CFN template generated by app package.

Appendix

Send to multiple destinations

logging:                              # Enable Firelens to route your logs (to CloudWatch by default)
  destination:                        # Configure where to send logs to.  
    # includePattern: ^[a-z][aeiou].*$
    # excludePattern: ^.*[aeiou]$
  enableMetadata: false               # Enable ECS log metadata or not.
  # secretOptions:                      # The secrets to pass to the log configuration from AWS Systems Manager (SSM) Parameter Store.
    # LOG_TOKEN: LOG_TOKEN              # The key is the name of the environment variable, the value is the name of the SSM parameter. 
  configFile: ./extra.conf            # Path to the local config file for Firelens. Specified to override other configurations.
  permissionFile: ./permissions.json  # Path to the optional permission file if "configFile" is set.

extra.conf

[OUTPUT]
    Name   firehose
    Match  *
    region us-west-2
    delivery_stream stream-one

[OUTPUT]
    Name   firehose
    Match  *
    region us-west-2
    delivery_stream stream-two

permissions.json

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Action": [
            "firehose:PutRecordBatch",
        ],
        "Resource": "*"
    }]
}

Send logs to datadog

logging:                              # Enable Firelens to route your logs (to CloudWatch by default)
  destination:                        # Configure where to send logs to.  
    Name: datadog,
    # includePattern: ^[a-z][aeiou].*$
    # excludePattern: ^.*[aeiou]$
    Host: http-intake.logs.datadoghq.com
    TLS: on
    dd_service: my-httpd-service
    dd_source: httpd
    dd_tags: project:example
    provider: ecs
  enableMetadata: false               # Enable ECS log metadata or not.
  # secretOptions:                      # The secrets to pass to the log configuration from AWS Systems Manager (SSM) Parameter Store.
    # LOG_TOKEN: LOG_TOKEN              # The key is the name of the environment variable, the value is the name of the SSM parameter. 
  # configFile: ./extra.conf            # Path to the local config file for Firelens. Specified to override other configurations.
  # permissionFile: ./permissions.json  # Path to the optional permission file if "configFile" is set.
@iamhopaul123 iamhopaul123 added the type/design Issues that are design proposals. label Apr 27, 2020
@iamhopaul123 iamhopaul123 self-assigned this Apr 27, 2020
@iamhopaul123 iamhopaul123 added this to In Progress in Roadmap 🗺️ Apr 27, 2020
@iamhopaul123 iamhopaul123 changed the title [design] sidecar support [Feature] sidecar support Apr 27, 2020
@iamhopaul123 iamhopaul123 moved this from In Progress to Design in Roadmap 🗺️ Apr 27, 2020
@iamhopaul123 iamhopaul123 changed the title [Feature] sidecar support [Feature] Sidecar support Apr 27, 2020
@iamhopaul123
Copy link
Contributor Author

iamhopaul123 commented May 18, 2020

Milestone

mergify bot pushed a commit that referenced this issue Jun 8, 2020
<!-- Provide summary of changes -->
Partially address #875. With this PR now we can deploy a Copilot service with Firelens as the log driver to deliver logs of the main container to destinations.

Users can config Firelens in two ways:

1. Set up configurations in the manifest (unable to sent to multiple destinations though).
2. Configure using fluentbit config file. Note that this requires users to build their own custom fluentbit image and specifying their config file path.

Additionally users might need to add permissions to task role if necessary. And they are able to add their own permissions by using Copilot addons feature. Any addons policy will be added to the task role.

This PR also adjusts `svc logs` to accommodate Firelens changes.
<!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" -->

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
@efekarakus efekarakus moved this from Design to Complete in Roadmap 🗺️ Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/design Issues that are design proposals.
Projects
Status: Complete
Development

No branches or pull requests

1 participant