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

Optimize regular expression for postgres config parsing #1395

Merged
merged 1 commit into from
Jan 5, 2017

Conversation

chris-rock
Copy link
Contributor

This PR optimizes the configuration parsing for PostgreSQL. Assuming we have the following configuration:

root@default-apt-ubuntu-1404:~# cat /etc/postgresql/9.4/main/postgresql.conf
# PostgreSQL configuration file
# This file was automatically generated and dropped off by chef!
# Please refer to the PostgreSQL documentation for details on
# configuration settings.

data_directory = '/var/lib/postgresql/9.4/main'
datestyle = 'iso, mdy'
default_text_search_config = 'pg_catalog.english'
external_pid_file = '/var/run/postgresql/9.4-main.pid'
hba_file = '/etc/postgresql/9.4/main/pg_hba.conf'
ident_file = '/etc/postgresql/9.4/main/pg_ident.conf'
listen_addresses = 'localhost'
log_connections = on
log_directory = 'pg_log'
log_disconnections = on
log_duration = on
log_hostname = on
log_line_prefix = '%t %u %d %h'
logging_collector = on
max_connections = 100
password_encryption = on
port = 5432
shared_buffers = '24MB'
ssl = off
ssl_ciphers = 'ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH'
unix_socket_directories = '/var/run/postgresql'

we need to parse the following types:

  • logging_collector = on
  • log_directory = 'pg_log'

This PR adapts to the regular expression to allow:

describe postgres_conf('/etc/postgresql/9.4/main/postgresql.conf') do
    its('logging_collector') { should eq 'on' }
    its('log_directory') { should eq 'pg_log' }
  end

@chris-rock chris-rock added Type: Enhancement Improves an existing feature in progress labels Jan 4, 2017
@chris-rock chris-rock changed the title WIP: optimize regular expression for postgres config parsing Optimize regular expression for postgres config parsing Jan 4, 2017
@chris-rock chris-rock force-pushed the chris-rock/postgres-config branch 3 times, most recently from d4085ce to cf26672 Compare January 5, 2017 11:38
Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Thank you @chris-rock , just one comment ;)

@@ -74,7 +74,10 @@ def read_content
raw_conf = read_file(to_read[0])
@content += raw_conf

params = SimpleConfig.new(raw_conf).params
opts = {
assignment_re: /^\s*([^=]*?)\s*=\s*[']*\s*(.*?)\s*[']*\s*$/,
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd change [']* to [']?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have an empty assignment? vv

a = 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't seen an empty assignment, but we should enable this. I'll update the unit tests accordingly.

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
@arlimus
Copy link
Contributor

arlimus commented Jan 5, 2017

lgtm 👍 +1

@arlimus arlimus merged commit db6f7f7 into master Jan 5, 2017
@arlimus arlimus deleted the chris-rock/postgres-config branch January 5, 2017 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants