Skip to content

Commit

Permalink
Merge c98a66b into 1714b1e
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Apr 1, 2020
2 parents 1714b1e + c98a66b commit 55a3ab5
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
2 changes: 1 addition & 1 deletion streamalert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""StreamAlert version."""
__version__ = '3.1.1'
__version__ = '3.1.2'
2 changes: 1 addition & 1 deletion streamalert/shared/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def athena_query_results_bucket(config):

return athena_config.get(
'results_bucket',
'{}.streamalert.athena-results'.format(prefix)
'{}-streamalert-athena-results'.format(prefix)
).strip()


Expand Down
7 changes: 2 additions & 5 deletions streamalert_cli/terraform/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
"""
from streamalert.shared import metrics
from streamalert.shared.config import athena_partition_buckets
from streamalert.shared.config import athena_partition_buckets, athena_query_results_bucket
from streamalert_cli.manage_lambda.package import AthenaPackage
from streamalert_cli.terraform.common import (
infinitedict,
Expand All @@ -40,10 +40,7 @@ def generate_athena(config):
prefix = config['global']['account']['prefix']
database = athena_config.get('database_name', '{}_streamalert'.format(prefix))

results_bucket_name = athena_config.get(
'results_bucket',
'{}-streamalert-athena-results'.format(prefix)
).strip()
results_bucket_name = athena_query_results_bucket(config)

queue_name = athena_config.get(
'queue_name',
Expand Down
2 changes: 1 addition & 1 deletion streamalert_cli/terraform/scheduled_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def generate_scheduled_queries_module_configuration(config):
# FIXME (derek.wang) DRY out this code
results_bucket = athena_query_results_bucket(config)

athena_s3_buckets = athena_partition_buckets(config)
athena_s3_buckets = sorted(athena_partition_buckets(config))

# Copy the config over directly
scheduled_queries_module = streamquery_config.get('config', {})
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/conf/scheduled_queries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"enabled": true,
"config": {
"destination_kinesis_stream": "unit-test_stream",
"sfn_timeout_secs": 3600,
"sfn_wait_secs": 30
},
"packs": {
"hourly": {
"description": "Runs all hourly queries. Once per day on :05",
"schedule_expression": "cron(5 * * * ? *)"
}
},
"lambda_config": {
"log_level": "info",
"log_retention_days": 14,
"memory": 128,
"timeout": 60,
"alarms_enabled": true,
"error_threshold": 1,
"error_period_secs": 3600,
"error_evaluation_periods": 2
}
}
70 changes: 70 additions & 0 deletions tests/unit/streamalert_cli/terraform/test_scheduled_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Copyright 2017-present Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from nose.tools import assert_equal

from streamalert_cli.config import CLIConfig
from streamalert_cli.terraform import scheduled_queries

CONFIG = CLIConfig(config_path='tests/unit/conf')


def test_generate_scheduled_queries():
"""CLI - Terraform Generate Scheduled Queries"""

expected_sq_config = {
'module': {
'scheduled_queries': {
'source': './modules/tf_scheduled_queries',
'destination_kinesis_stream': 'unit-test_stream',
'sfn_timeout_secs': 3600,
'sfn_wait_secs': 30,
'prefix': 'unit-test',
'account_id': '12345678910',
'region': 'us-west-1',
'athena_database': 'unit-test_streamalert',
'athena_results_bucket': 'unit-test-streamalert-athena-results',
'athena_s3_buckets': [
'bucket',
'unit-test-streamalert-data',
'unit-test-streamalerts'
],
'lambda_filename': 'scheduled_queries.zip',
'lambda_handler': 'streamalert.scheduled_queries.main.handler',
'query_packs': [
{
'name': 'hourly',
'schedule_expression': 'cron(5 * * * ? *)',
'description': 'Runs all hourly queries. Once per day on :05'
}
],
'lambda_log_level': 'info',
'lambda_memory': 128,
'lambda_timeout': 60,
'lambda_log_retention_days': 14,
'lambda_alarms_enabled': True,
'lambda_error_threshold': 1,
'lambda_error_period_secs': 3600,
'lambda_error_evaluation_periods': 2,
'lambda_alarm_actions': [
'arn:aws:sns:us-west-1:12345678910:unit-test_streamalert_monitoring'
],
}
}
}

result = scheduled_queries.generate_scheduled_queries_module_configuration(CONFIG)

assert_equal(result, expected_sq_config)

0 comments on commit 55a3ab5

Please sign in to comment.