Migrations
Migrating to 2.X¶
Version 2.X consists of a major rewrite that turns spectator-go into a thin client designed to send metrics through spectatord. As a result some functionality has been moved to other packages or removed.
New¶
Writers¶
spectator.Registry now supports different writers. The default writer is writer.UdpWriter which
sends metrics to spectatord through UDP.
See Usage > Output Location for more details.
Meters¶
The following new Meters have been added:
meter.MaxGaugemeter.Gaugewith TTL
Common Tags¶
A few local environment common tags are now automatically added to all Meters. Their values are read from the environment variables.
| Tag | Environment Variable |
|---|---|
| nf.container | TITUS_CONTAINER_NAME |
| nf.process | NETFLIX_PROCESS_NAME |
Tags from environment variables take precedence over tags passed on code when creating the Config.
Note that common tags sourced by spectatord can't be overwritten.
Config¶
Configis now created through a constructor which throws error if the passed in parameters are not valid.Configmembers are now private.
Moved¶
- Runtime metrics collection has been moved to spectator-go-runtime-metrics. Follow instructions in the README to enable collection.
- Some types have been moved to different packages. For example,
spectator.Counteris now inmeter.Counter.
Removed¶
spectator.HttpClienthas been removed. Use the standardhttp.Clientinstead.spectator.Meters no longer have aMeasure() []Measurementfunction. Meters are now stateless and do not store measurements.spectator.Clockhas been removed. Use the standardtimepackage instead. Thus,registry.Clock().Now()calls becometime.Now()calls.spectator.Configis simplified and local to this library. There is no longer a need to import the internal configuration library.spectator.Registryno longer has aStart()function. TheRegistryis now effectively stateless and there is nothing to start other than opening the output location.spectator.Registryno longer has aStop()function. Instead, useClose()to close the registry. Once the registry is closed, it can't be started again. This is intended for final clean up of sockets or file handles.spectator.Config.IpcTimerRecordhas been removed. Use ameter.Timerinstead to record Ipc metrics.spectator.MeterFactoryFunhas been removed. If you need to create a custom meter you can do so by wrapping one of the meters returned byspectator.Registry.spectator.Registryno longer reportsspectator.measurementsmetrics. Instead, you can use similar metrics fromspectatordfor visibility.spectator.Registryno longer keeps track of the Meters it creates. This means that you can't get a list of all Meters from the Registry. If you need to keep track of Meters, you can do so in your application code.Percentile*meters no longer support defining min/max values.spectator.Registryno longer allows setting a different logger after creation. A custom logger can be set in thespectator.Configbefore creating the Registry.- File-based configuration is no longer supported.
Migration Steps¶
- Make sure you're not relying on any of the removed functionality.
- Update imports for
ConfigandRegistry, and use themeterspackage instead ofspectatorfor Meters. - If you want to collect runtime metrics, add the spectator-go-runtime-metrics library, and follow the instructions in the README.
- If you use
PercentileDistributionSummaryorPercentileTimer, then you need to update your code to use the respective functions provided by theRegistryto initialize these meters. - Remove the dependency on the
spectator-gointernal configuration library - it is no longer required. - There is no longer an option to
start()orstop()theRegistryat runtime. If you need to configure aRegistrythat doesn't emit metrics, for testing purposes, you can use thespectator.Config.Locationoption withnoneto configure a no-op writer.