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

Allow add items to array config via ENV #7323

Merged
merged 2 commits into from
Jan 4, 2017

Conversation

miry
Copy link
Contributor

@miry miry commented Sep 19, 2016

Allow to create a new templates or tags configs, if there are no records
in the default config.

Support next cases:

  • Without config file:
$ INFLUXDB_GRAPHITE_ENABLED=true INFLUXDB_GRAPHITE_TEMPLATES="stats.* .host.measurement.cpu,system.* .host.region.measurement*" influxd config

...
[[graphite]]
  enabled = true
  bind-address = ":2003"
  database = "graphite"
  retention-policy = ""
  protocol = "tcp"
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "1s"
  consistency-level = "one"
  templates = ["stats.* .host.measurement.cpu", "system.* .host.region.measurement*"]
  separator = "."
  udp-read-buffer = 0

....
  • With specified template rule:
[[graphite]]
  enabled = true
  templates = ["stats-config.* .host.measurement.cpu"]
$ INFLUXDB_GRAPHITE_ENABLED=true INFLUXDB_GRAPHITE_0_TEMPLATES_0="stats-over.* .host.measurement.cpu" influxd config
...
[[graphite]]
  enabled = true
  bind-address = ":2003"
  database = "graphite"
  retention-policy = ""
  protocol = "tcp"
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "1s"
  consistency-level = "one"
  templates = ["stats-over.* .host.measurement.cpu"]
  separator = "."
  udp-read-buffer = 0

....

As you see from the first example INFLUXDB_GRAPHITE_TEMPLATES separate rules by ,.

Fixes: #6943

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)
Required only if applicable

You can erase any checkboxes below this note if they are not applicable to your Pull Request.

  • Provide example syntax

@mention-bot
Copy link

@miry, thanks for your PR! By analyzing the annotation information on this pull request, we identified @gunnaraasen and @e-dard to be potential reviewers

@miry
Copy link
Contributor Author

miry commented Nov 22, 2016

@gunnaraasen and @e-dard can you check this PR?

@e-dard
Copy link
Contributor

e-dard commented Nov 23, 2016

@jackzampolin does this look like what you were after in #6943 ?

@jackzampolin
Copy link
Contributor

@e-dard Yeah that's basically it. Want to make it easy to do graphite parsing by setting templates with ENV. I would also ask @gunnaraasen as he worked on this code too.

Copy link
Member

@gunnaraasen gunnaraasen left a comment

Choose a reason for hiding this comment

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

Thanks @miry! Sorry for taking so long to review this PR. I only had a few small cosmetic changes.

@jwilder, can you take a quick look at this to make sure I didn't miss anything?

case reflect.Bool:
boolValue, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("failed to apply %v to %v using type %v and value '%v'", prefix, structKey, element.Type().String(), value)

Copy link
Member

Choose a reason for hiding this comment

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

Remove unnecessary newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. thank you.

case reflect.Float32, reflect.Float64:
floatValue, err := strconv.ParseFloat(value, element.Type().Bits())
if err != nil {
return fmt.Errorf("failed to apply %v to %v using type %v and value '%v'", prefix, structKey, element.Type().String(), value)

Copy link
Member

Choose a reason for hiding this comment

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

Remove unnecessary newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. thank you.

}
element.SetFloat(floatValue)
case reflect.Slice:
for j := 0; j < element.Len(); j++ {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add in the comment from the existing code back in here?

If the type is s slice, apply to each using the index as a suffix, e.g. GRAPHITE_0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment. also added comment bellow few lines.

key = strings.ToUpper(fmt.Sprintf("%s_%s", prefix, configName))
}
element.SetFloat(floatValue)
case reflect.Slice:
Copy link
Member

Choose a reason for hiding this comment

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

This case should also handle reflect.Array. I don't think arrays are used in the configuration at this moment, but might as well cover all the bases.

Copy link
Contributor Author

@miry miry Dec 1, 2016

Choose a reason for hiding this comment

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

We have array if I understand correctly. In next example there is templates option:

[[graphite]]
  protocol = "udp"
  templates = [
    "default.* .template.in.config"
  ]

And arrays converted as slice.

@miry
Copy link
Contributor Author

miry commented Dec 1, 2016

@gunnaraasen I have updated code according the comments.

@e-dard
Copy link
Contributor

e-dard commented Dec 1, 2016

@miry looks good. Can you add an entry to the CHANGELOG and make sure you give yourself credit!

@e-dard
Copy link
Contributor

e-dard commented Dec 1, 2016

@miry can you also rebase from master and push. I think the test failure is because Circle is testing the head ref rather than the merge result of this PR and master. Not sure why it's doing that. The test failure looks completely unrelated to your changes, and when I pulled down your branch it's pretty far behind master.

@miry
Copy link
Contributor Author

miry commented Dec 1, 2016

@e-dard sure

@miry miry changed the title Env array config Allow add items to array config via ENV Dec 5, 2016
@miry
Copy link
Contributor Author

miry commented Dec 5, 2016

@e-dard updated Changelog and rebased against master.

@fdrouet
Copy link

fdrouet commented Dec 7, 2016

awesome fix !! when could we expect to see that in a released version of Influxdb ?

@burdandrei
Copy link

Great fix! waiting it to be merged!

Allow to create a new templates or tags configs, if there are no records
in the default config.

Fixes: influxdata#6943
@miry
Copy link
Contributor Author

miry commented Dec 23, 2016

@e-dard @gunnaraasen @jackzampolin I have rebased against master.

@miry
Copy link
Contributor Author

miry commented Jan 3, 2017

@e-dard who can merge this pr?

@jwilder jwilder merged commit 1591544 into influxdata:master Jan 4, 2017
@jwilder
Copy link
Contributor

jwilder commented Jan 4, 2017

Thanks @miry!

@jwilder jwilder added this to the 1.2.0 milestone Jan 4, 2017
@miry miry deleted the env-array-config branch January 5, 2017 10:38
DenysGonchar added a commit to esl/amoc-arsenal-xmpp that referenced this pull request Sep 14, 2021
INFLUXDB_GRAPHITE_TEMPLATES expects multiple templates to be separated by ',' (see influxdata/influxdb#7323),
in the same time ',' is used to separate multiple additional tags for a single template (see https://docs.influxdata.com/influxdb/v1.8/supported_protocols/graphite/#adding-tags)
So unfortunately it's impossible to configure a template with multiple additional tags thru INFLUXDB_GRAPHITE_TEMPLATES env variable,
and providing a config file with templates is the only available option for this.

in order to check the whole influxdb config (including default values) you should start docker-compose setup and attach to the
influxdb container (note that execution of docker compose commands is done in the metrics directory):
    cd metrics
    docker compose up -d
    docker compose exec influxdb bash

then you can run this command in the influxdb container's shell:
    influxd config

the default configuration file for influxdb container is located at '/etc/influxdb/influxdb.conf', you can print its content or check
how the whole configuration looks like with it using these commands:
    cat /etc/influxdb/influxdb.conf
    INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf influxd config
DenysGonchar added a commit to esl/amoc-arsenal-xmpp that referenced this pull request Sep 17, 2021
INFLUXDB_GRAPHITE_TEMPLATES expects multiple templates to be separated by ',' (see influxdata/influxdb#7323),
in the same time ',' is used to separate multiple additional tags for a single template (see https://docs.influxdata.com/influxdb/v1.8/supported_protocols/graphite/#adding-tags)
So unfortunately it's impossible to configure a template with multiple additional tags thru INFLUXDB_GRAPHITE_TEMPLATES env variable,
and providing a config file with templates is the only available option for this.

in order to check the whole influxdb config (including default values) you should start docker-compose setup and attach to the
influxdb container (note that execution of docker compose commands is done in the metrics directory):
    cd metrics
    docker compose up -d
    docker compose exec influxdb bash

then you can run this command in the influxdb container's shell:
    influxd config

the default configuration file for influxdb container is located at '/etc/influxdb/influxdb.conf', you can print its content or check
how the whole configuration looks like with it using these commands:
    cat /etc/influxdb/influxdb.conf
    INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf influxd config
DenysGonchar added a commit to esl/amoc-arsenal-xmpp that referenced this pull request Sep 17, 2021
INFLUXDB_GRAPHITE_TEMPLATES expects multiple templates to be separated by ',' (see influxdata/influxdb#7323),
in the same time ',' is used to separate multiple additional tags for a single template (see https://docs.influxdata.com/influxdb/v1.8/supported_protocols/graphite/#adding-tags)
So unfortunately it's impossible to configure a template with multiple additional tags thru INFLUXDB_GRAPHITE_TEMPLATES env variable,
and providing a config file with templates is the only available option for this.

in order to check the whole influxdb config (including default values) you should start docker-compose setup and attach to the
influxdb container (note that execution of docker compose commands is done in the metrics directory):
    cd metrics
    docker compose up -d
    docker compose exec influxdb bash

then you can run this command in the influxdb container's shell:
    influxd config

the default configuration file for influxdb container is located at '/etc/influxdb/influxdb.conf', you can print its content or check
how the whole configuration looks like with it using these commands:
    cat /etc/influxdb/influxdb.conf
    INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf influxd config
DenysGonchar added a commit to esl/amoc-arsenal-xmpp that referenced this pull request Sep 21, 2021
INFLUXDB_GRAPHITE_TEMPLATES expects multiple templates to be separated by ',' (see influxdata/influxdb#7323),
in the same time ',' is used to separate multiple additional tags for a single template (see https://docs.influxdata.com/influxdb/v1.8/supported_protocols/graphite/#adding-tags)
So unfortunately it's impossible to configure a template with multiple additional tags thru INFLUXDB_GRAPHITE_TEMPLATES env variable,
and providing a config file with templates is the only available option for this.

in order to check the whole influxdb config (including default values) you should start docker-compose setup and attach to the
influxdb container (note that execution of docker compose commands is done in the metrics directory):
    cd metrics
    docker compose up -d
    docker compose exec influxdb bash

then you can run this command in the influxdb container's shell:
    influxd config

the default configuration file for influxdb container is located at '/etc/influxdb/influxdb.conf', you can print its content or check
how the whole configuration looks like with it using these commands:
    cat /etc/influxdb/influxdb.conf
    INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf influxd config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants