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

Beatless initial PR #8485

Merged
merged 102 commits into from
Oct 19, 2018
Merged

Beatless initial PR #8485

merged 102 commits into from
Oct 19, 2018

Conversation

ph
Copy link
Contributor

@ph ph commented Sep 28, 2018

This PR provide the following

  1. Plugin infra for developing providers and functions
  2. A local stdin provider only used for testing, I will remove it in the
    final version.
  3. AWS provider and function types for:
  • Cloudwatch logs
  • SQS
  • Kinesis
  • Api web gateway proxy
  1. License checker
  2. Packaging of artifact
  3. Runners
  4. CLI infrastructure
  5. CLI to push a cloudwatch logs function.
  6. CLI to delete any function
  7. Processors support.
  8. Types to validate value from the users and the lambda function.

What it doesn't provides

  • ECS and full event extraction. (NOT for v1)
  • Specifying the AWS credentials in the configuration
  • CLI for SQS, Kinesis, API
  • Robust CLI interaction with the API, rollback on failure / versioning.
  • Removal of not supported outputs
  • Removal of seccomp check
  • Integration tests
  • Updated build task to produce containing the user executable beat and
    the linux beats.
  • Concurrency / memory settings

Vendored

  • aws/aws-lambda-go
  • aws/aws-sdk-go-v2

Note: The PR look much bigger because of the vendored files.

Notes 2:

Make sure you add this to your config YAMl, I wan't to make the following the default options but it would have been really messy to do it in this PR.

# Disable anything that could be send to disk
path.data: /tmp
path.logs: /tmp/logs
logging.to_stderr: true
logging.to_files: false
#logging.level: debug
setup.template.enabled: true
queue.mem:
  events: 50
  flush.min_events: 1
  flush.timeout: 0.5s

related work

@ph ph added in progress Pull request is currently in progress. Functionbeat labels Sep 28, 2018
@ph ph changed the title CLI improvements [WIP] CLI improvements Sep 28, 2018
// feature are grouped by namespace, a namespace is a kind of plugin like outputs, inputs, or queue.
// The feature name must be unique.
type registry struct {
type FeatureRegistry struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type name will be used as feature.FeatureRegistry by other packages, and that stutters; consider calling this Registry

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for naming the type 'Registry'. Let's replace the global 'Registry' variable with func GlobalRegistry() *Registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah much better, it will lead to less fragile code. :)

@@ -28,26 +28,26 @@ import (

type mapper map[string]map[string]Featurable

// Registry implements a global registry for any kind of feature in beats.
// Registry implements a global FeatureRegistry for any kind of feature in beats.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on exported type FeatureRegistry should be of the form "FeatureRegistry ..." (with optional leading article)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indeed reads somewhat funny.

@ph ph added the blocked label Sep 28, 2018
@ph ph force-pushed the fix/beatless-cli-improved branch from 136c136 to 56d7d16 Compare October 2, 2018 17:16
@ph ph added review and removed blocked in progress Pull request is currently in progress. labels Oct 2, 2018
@ph ph changed the title [WIP] CLI improvements Beatless initial PR Oct 2, 2018
@ph ph assigned ruflin and kvch Oct 2, 2018
@ph
Copy link
Contributor Author

ph commented Oct 2, 2018

@kvch @ruflin go ahead for first round of review, I am still working on the CLI so expect them to changes but I see no reason to not start reviewing this.

@ph
Copy link
Contributor Author

ph commented Oct 2, 2018

I think I will migrate the to the cloud formation api instead this look like a more solid way of doing it.

@ph ph assigned urso Oct 3, 2018
@ph
Copy link
Contributor Author

ph commented Oct 3, 2018

@urso @ruflin @kvch Do not takes too much times into reviewing the CLI code in the cloudwatchlogs.go I've migrated everything to the cloudformation API which provided a lot more stable experience.

"github.com/elastic/beats/x-pack/beatless/provider"
)

var stdinName = "stdin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

scanner.Split(bufio.ScanLines)

for scanner.Scan() {
if scanner.Err() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's enough to call scanner.Err once, if you rewrite the code a little:

if err := scanner.Err(); err != nil {
    errChan <- err
    return
}

"github.com/elastic/beats/libbeat/logp"
)

var handlerName = "beatless"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this variable here? Although it's in the same package, but it's used in x-pack/beatless/provider/aws/cloudwatch_logs.go.
This also could be const.

"github.com/elastic/beats/libbeat/logp"
)

var errNeverRun = errors.New("executer was never executed")
Copy link
Contributor

@kvch kvch Oct 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please group the variables together.

var (
    errNeverRun = errors.New("executer was never executed")
    errCannotAdd = errors.New("cannot add to an already executed executer")
    errAlreadyExecuted = errors.New("executer already executed")
)


func newExecutor(log *logp.Logger, context *executorContext) *executor {
if log == nil {
log = logp.NewLogger("executer")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be "executor".

}
}
if err == nil {
e.log.Debug("all operations successful")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all operations have been successful"?

@ph ph force-pushed the fix/beatless-cli-improved branch from 9095553 to 908966b Compare October 4, 2018 15:00
// specific language governing permissions and limitations
// under the License.

package php_fpm

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use an underscore in package name


// +build !integration

package node_stats

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use an underscore in package name

)
}

// OrderIntervalLogs, when given a log filename in the form [prefix]-[formattedDate]-n

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on exported function OrderIntervalLogs should be of the form "OrderIntervalLogs ..."

@@ -48,11 +49,14 @@ func makeURL(url, path string, params url.Values) string {
return strings.Join([]string{url, path, "?", params.Encode()}, "")
}

func Export(client *http.Client, conn string, dashboard string, out string) error {
func Export(client *http.Client, conn string, spaceID string, dashboard string, out string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported function Export should have comment or be unexported

@ph
Copy link
Contributor Author

ph commented Oct 4, 2018

depends on #8573

@ph
Copy link
Contributor Author

ph commented Oct 4, 2018

@ruflin As discussed I have added the following command beatless function package this will generate a package that you can push manually or via another CLI to lambda. By default it will create a package.zip in the working folder, but you can override that with -o

Also, this PR is a lot more robust when deploying, updating or removing a cloudwatch function, it require permission on cloudformation, but it will make the operation atomic, and will take into consideration the changes that you add.

I have updated the configuration to correctly expose lambda specific settings:

beatless.provider.aws.functions:
  # Define the list of function availables, each function required to have a unique name.
  - name: fn_cloudwatch_logs
    type: cloudwatch_logs

    # Description of the method to help identify them when you run multiples functions.
    description: "listen to cloudwatch logs"
    #
    # Concurrency, is the reserved number of instance for that function.
    # Default is unreserved.
    #
    # Note: There is a hard limit of 1000 of running function of any kind per account.
    # concurrency: 5
    #
    # The maximum memory allocated for this function, the configured size must be a factor of 64.
    # There is a hard limit of 3008MiB for each function. Default is 128MiB.
    # memory_size: 128MiB
    #
    # Dead letter queue configuration, this must be set to an ARN pointing to a SQS queue.
    # dead_letter_config.target_arn:
    #
    # Optional fields that you can specify to add additional information to the
    # output. Fields can be scalar values, arrays, dictionaries, or any nested
    # combination of these.
    #fields:
    #  env: staging

    # List of cloudwatch log group registered to that function.
    triggers:
      - log_group_name: /aws/lambda/beatless-cloudwatch_logs
        filter_pattern: mylog_
    #
    # Define custom processors for this function.
    # processors:
    #   - dissect:
    #       tokenizer: "%{key1} %{key2}"

Once the PR #8573 is merged it will be a PR the same size that you had before.

@ph ph force-pushed the fix/beatless-cli-improved branch from 8a92d96 to edd2dfa Compare October 5, 2018 13:39
@ph ph force-pushed the fix/beatless-cli-improved branch from 2b8742c to 0f84be5 Compare October 19, 2018 12:42
@ph
Copy link
Contributor Author

ph commented Oct 19, 2018

I've rebased this PR on top of the feature branch you can now create artifact of beatless and push the function using theses artifacts.

@ph ph merged commit 26e6adb into elastic:feature-beatless Oct 19, 2018
ph added a commit that referenced this pull request Oct 24, 2018
## This PR provides the following

1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

## What it doesn't provides

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings
ph added a commit that referenced this pull request Oct 24, 2018
## This PR provides the following

1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

## What it doesn't provides

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings
ph added a commit that referenced this pull request Oct 24, 2018
## This PR provides the following

1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs/sqs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

## What it doesn't provides

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings
@ph ph added the v6.5.0 label Oct 24, 2018
ph added a commit to ph/beats that referenced this pull request Oct 24, 2018
1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs/sqs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings

(cherry picked from commit 3ef0b4e)
ph added a commit that referenced this pull request Oct 24, 2018
Cherry-pick of PR #8485 to 6.x branch. Original message: 

## This PR provide the following

1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

## What it doesn't provides

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings

## Vendored

- aws/aws-lambda-go
- aws/aws-sdk-go-v2

---

**Note:** The PR look much bigger because of the vendored files.

**Notes 2:** 

Make sure you add this to your config YAMl, I wan't to make the following the default options but it would have been really messy to do it in this PR.

```
# Disable anything that could be send to disk
path.data: /tmp
path.logs: /tmp/logs
logging.to_stderr: true
logging.to_files: false
#logging.level: debug
setup.template.enabled: true
queue.mem:
  events: 50
  flush.min_events: 1
  flush.timeout: 0.5s
```

## related work
- #8449
- #8443
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
## This PR provides the following

1. Plugin infra for developing providers and functions
2. A local stdin provider only used for testing, I will remove it in the
final version.
3. AWS provider and function types for:
  - Cloudwatch logs
  - SQS
  - Kinesis
  - Api web gateway proxy
4. License checker
5. Packaging of artifact
6. Runners
7. CLI infrastructure
8. CLI to push a cloudwatch logs function.
9. CLI to delete any function
10. Processors support.
11. Types to validate value from the users and the lambda function.

## What it doesn't provides

- ECS and full event extraction. (NOT for v1)
- Specifying the AWS credentials in the configuration
- CLI for SQS, Kinesis, API
- Robust CLI interaction with the API, rollback on failure / versioning.
- Removal of not supported outputs
- Removal of seccomp check
- Integration tests
- Updated build task to produce containing the user executable beat and
the linux beats.
- Concurrency / memory settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants