I need to create environment-dependent parameterization, into the newrelic.yml file.
I want to use an Heroku env var that can assume different values depending on the environment.
How can I make it?
Do I need to create files like newrelic.development, newrelic.staging, ecc. ?
Or what?
I think it depends on the language you're trying to use. I know in PHP for example you can use ${ENV_VAR_NAME} in the config files and it will use such a value.
I don't know if that's true of all the agent languages but let me know what language you're using and perhaps I can nudge in the right direction
Related
I'm using the Golang google-cloud-sdk to get informations on resources (specifically here compute instances, but it doesn't really matter).
The gcloud cli allows to do something like this:
gcloud config set compute/zone ZONE
Which under the hood will write in ~/.config/gcloud/configurations/config_default those value as something that looks like an ini file.
Can the (go) sdk read config those config file ?
The cli also read the environment variable CLOUDSDK_COMPUTE_ZONE if not defined in the config file.
Can the sdk also read this variables ?
To sum up the question , how can I use the same config mechanism the gcloud cli uses with the Go sdk ?
To sum up the question , how can I use the same config mechanism the gcloud cli uses with the Go sdk ?
As far as I know, you can't. You need to specify the zone to all your operations.
Long time ago, someone asked about CLOUDSDK_CONFIG and the last response is cristal clear:
Resolved: we decided not to honor CLOUDSDK_CONFIG, in the interest of maintaining simplicity for the ADC spec.
https://github.com/googleapis/google-cloud-go/issues/288
And I think it's true for all the CLOUDSDK_* env.
In Go, you can specify a specific zoneinfo.zip file to be used by adding a ZONEINFO environment variable that points to the specific file you'd like to use for time zone information. This is great as it allows me to ensure that the versions of the IANA time zone database that I'm using on my front-end and my back-end are the same.
However, there does not appear to be any way to detect if use of the specified zone info file has failed. Looking at the source code (https://golang.org/src/time/zoneinfo.go), it looks like any errors using the specified file will fail quietly and then go will proceed to check for default OS locations or the default $GOROOT location to pull time zone information from there. This is not the behavior that I would prefer as I would like to know with certainty that I am using my specified version of zone info.
I've thought of the following in terms of solutions, but I'm not happy with any of them.
I can check that the environment variable is set myself, but this is at best a partial solution as it doesn't tell me if the file is actually usable by LoadLocation.
I can ensure none of the backup locations for zone info exist. This seems a bit extreme and means that I have to be extremely careful about the environment that the code is running in in both dev and production settings.
Does anyone know of a more elegant way to ensure that I am using the zoneinfo.zip file specified by my ZONEINFO environment variable?
Update: To address this problem I too inspiration from #chuckx's answer below and put together a Go package that takes the guess work out of which time zone database is being used. Included in the readme are instructions on how to get the correct version of the time zone database using a Go installation.
Maybe consider not relying on the environment variable?
If you're not averse to distributing the unzipped fileset, you can easily use LoadLocationFromTZData(name string, data []byte). The second argument is the contents of an individual timezone file.
For reference, the functionality for processing a zip file is found in the unexported function loadTzinfoFromZip().
Step-by-step approach extracted from #Slotherooo's comment:
Make a local version of time.loadTzinfoFromZip(zipfile, name string) ([]byte, error)
Use that method to extract the []byte for the desired location from a timeinfo.zip file
Use time.LoadLocationFromTZData() exclusively instead of time.LoadLocation
Every time I run this command below, it runs on the default database, note the database I've selected:
Config::set('database.connections.mysql.database', 'somedatabasename');
Artisan::call('migrate');
Anyone know what this is not working?
You could implement that by using different environments. For example, one config for testing environment, another for local / staging / production. Could you elaborate on what you're actually trying to achieve and what's the context so we can answer in more depth?
I'm currently writing a tutorial on setting up Wordpress on Heroku. Right now I'm using the ClearDB add-on which sets a CLEARDB_DATABASE_URL ENV variable automatically. Is it possible to alias the ENV variable through Heroku as DATABASE_URL?
It's not possible to alias an config var or refer to one from another. I asked a similar question and this is what they said:
I'm afraid that Config Variables can't refer to each other in this
way, as they are simple a collection of Names and Values, with no
interpolation or calculation available to the values.
You might like try a
profile
file...
I've had a similar issue - where I'm trying to use an app in a pipeline connected to 2 different heroku DB's - in order to keep all he environments consistent in code, I did the following:
Heroku Configs:
DATABASE_URL=XXXXXXXX - this was the first DB that heroku attached
HEROKU_POSTGRESQL_JADE_URL=XXXX - this was the second DB that heroku attached (the key name changes in each environment)
SECOND_DB_KEY_NAME=HEROKU_POSTGRESQL_JADE_URL
(ie. after each environment was set up - I added a reference to the new key)
This second DB key name, does not change if the DB credentials refresh.
In code, I then did the following at start up:
const databaseUrlKey = process.env.SECOND_DB_KEY_NAME
process.env['SECOND_DATABASE_URL'] = process.env[databaseUrlKey]
Maybe I'll just say something stupid, but why not just do this:
heroku config:set DATABASE_URL=CLEARDB_DATABASE_URL
In code:
ENV[ENV['DATABASE_URL']]
I'm not sure this information will be helpful for anyone but just in case:
This question involves an eroneous assertion. The ClearDB add-on does not set a CLEARDB_DATABASE_URL ENV variable. The ClearDB add-on creates a CLEARDB_DATABASE_URL config var. When the app is started an ENV variable is created from the config var. These two variables are different and could even have different values if you changed the ENV variable in your code base.
Of course, within your code base, you can do whatever you want with the ENV variables.
As to whether config vars can reference other config vars, or other ENV variables, or vica versa - I don't know. But surely this would be something pretty hacky, and contrary to intended use, and proper coding practice, and socially responsible behavior.
I was wondering if someone could help me.
I have started using version control (git) for my website which is using CodeIgniter.
Everytime i transfer files from my localhost host to my live server, i always have to go through all my files and change the config details.
I came across a post saying i could do all this with the ENVIRONMENT settings in the index.php file automatically based on the SERVER_NAME.
Has anybody done this before? if so, would it be possible to let me know how its done properly?
Cheers,
Try this for a start (index.php):
if ($_SERVER["HTTP_HOST"] == 'devserver1' || $_SERVER["HTTP_HOST"] == 'devserver2')
define('ENVIRONMENT', 'development');
else
define('ENVIRONMENT', 'production');
Then, whenever you need it, you check for the ENVIRONMENT constant (for example, different database settings, etc.). For localhost, simply check if the server is 'localhost' ($_SERVER["HTTP_HOST"] == 'localhost'), or whichever virtual host name you might be using.
You could always use environment variables
http://httpd.apache.org/docs/2.2/env.html
This will allow you to get the environment instead of hard coding the information in your code
This may also help you out
http://docstore.mik.ua/orelly/linux/apache/ch04_06.htm
Not sure if you're still needing help with this, but I had this issue a while ago and released a CodeIgniter module which is designed to automatically handle multiple environments.
I'm shameful to be plugging myself, but it's saved me lots of editing and it might be of use to anyone else that'll read this post in the future.
Here's the link to the Git repo: https://github.com/jedkirby/ci-multi-environments and this is a brief explanation of why and how I made the module: http://jedkirby.com/blog/2012/11/codeigniter-multiple-development-environments