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

Add support for the CLI to push a lambda to monitor SQS queues. #8649

Merged
merged 12 commits into from
Oct 24, 2018

Conversation

ph
Copy link
Contributor

@ph ph commented Oct 18, 2018

This all support to configure triggers in the configuration file to
allow a lambda function to monitor one or more queue.

Note: we assume that body of an SQS message is a string, it we receive
a json encoded string we can use the decode_json_fields.

@ph ph added in progress Pull request is currently in progress. Functionbeat labels Oct 18, 2018
@ph ph force-pushed the fix/beatless-cli-improved-sqs branch from c469a8c to ad4db30 Compare October 19, 2018 19:28
@ph ph changed the title [WIP] Add support for SQS for the deploy command [WIP] Add support for the CLI to push a lambda to monitor SQS queues. Oct 19, 2018
@ph ph added review and removed in progress Pull request is currently in progress. labels Oct 22, 2018
@ph ph requested a review from urso October 22, 2018 12:28
@ph ph changed the title [WIP] Add support for the CLI to push a lambda to monitor SQS queues. Add support for the CLI to push a lambda to monitor SQS queues. Oct 22, 2018
return "fnb" + s.config.Name + suffix
}

re := regexp.MustCompile("[:/-]")
Copy link

@urso urso Oct 22, 2018

Choose a reason for hiding this comment

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

This is kind of a constant. Let's move the init out of this function and introduce a global:

var reNormalizeNames = regexp.MustCompile("[:/-]")

It is not nice to have var as global constant, but this patterns catches errors/panics whenever the beat is started, not only when the regex is compiled by taking said code path.

A little trick (lisp-style) if ouy want to hide the regex (still creates a function pointer, though):

var normalizeSQSName = func() func(string) string {
  re := regex.MustCompile()
  return func(c string) string {
    return re.ReplaceAllString(c, "")
  }
}()

Copy link

Choose a reason for hiding this comment

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

As we remove these bytes, solution without regex:

func removeChars(s string, chars string) string {
  buf := &strings.Builder{}
  for len(s) > 0 {
    idx := strings.IndexAny(s, chars)
    if idx < 0 {
      if buf.Len() > 0 {
        buf.WriteString(s)
      }
      break
    }

    buf.WriteString(s[:idx])
    s = s[idx+1:]
  }

  if buf.Len() == 0 {
    return s
  }
  return buf.String()
}

Why is this missing from stdlib :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the above method in common/string.go and tests for it.

@ph
Copy link
Contributor Author

ph commented Oct 23, 2018

Updated with the reviews, added support for enabled: false in the 'yml'

@ph ph force-pushed the fix/beatless-cli-improved-sqs branch from 0956459 to 500de83 Compare October 23, 2018 20:10
@ph ph assigned urso Oct 23, 2018
@ph
Copy link
Contributor Author

ph commented Oct 23, 2018

@urso rebased, it will probably conflict with another PR I have open so lets try to get it merged soonish.

Copy link

@urso urso left a comment

Choose a reason for hiding this comment

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

LGTM. CI failure is unrelated.

Copy link

@urso urso left a comment

Choose a reason for hiding this comment

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

LGTM. CI failure is unrelated.

ph added 12 commits October 24, 2018 08:06
This all support to configure triggers in the configuration file to
allow a lambda function to monitor one or more queue.

Note: we assume that body of an SQS message is a string, it we receive
a json encoded string we can use the `decode_json_fields`.
@ph ph force-pushed the fix/beatless-cli-improved-sqs branch from 64ea8f4 to 2828f93 Compare October 24, 2018 12:16
@ph
Copy link
Contributor Author

ph commented Oct 24, 2018

I've rebased this PR on top of the feature branch as soon as everything is green I will merge it.

@ph ph merged this pull request into elastic:feature-beatless Oct 24, 2018
ph added a commit that referenced this pull request Oct 24, 2018
* Add support for the CLI to push a lambda to monitor SQS queues.

This all support to configure triggers in the configuration file to
allow a lambda function to monitor one or more queue.

Note: we assume that the body of an SQS message is a string, if we receive
a JSON encoded string we can use the `decode_json_fields`.
ph added a commit that referenced this pull request Oct 24, 2018
* Add support for the CLI to push a lambda to monitor SQS queues.

This all support to configure triggers in the configuration file to
allow a lambda function to monitor one or more queue.

Note: we assume that the body of an SQS message is a string, if we receive
a JSON encoded string we can use the `decode_json_fields`.
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…tic#8649)

* Add support for the CLI to push a lambda to monitor SQS queues.

This all support to configure triggers in the configuration file to
allow a lambda function to monitor one or more queue.

Note: we assume that the body of an SQS message is a string, if we receive
a JSON encoded string we can use the `decode_json_fields`.
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.

3 participants