Migrations
Migrating to 3.X¶
Version 3.X consists of a major rewrite that turns spectator-js into a thin client designed to send metrics through spectatord. As a result some functionality has been moved to other packages or removed.
The library is now written in TypeScript, with support for both commonjs and module formats, so
types are readily available, and it will work in most contexts.
New¶
Writers¶
The Registry now supports different Writers. The default writer is UdpWriter, which sends metrics
to spectatord through UDP - these writers are configured through the Config object location
parameter.
See Usage > Output Location for more details.
Meters¶
The following new Meters have been added:
AgeGaugeMaxGaugeMonotonicCounterMonotonicCounterUintGaugewith TTL
See Usage > Meter Types for more details.
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 provides default values forundefined, and throws an error, if the passed in parameters are not valid.
Moved¶
- Runtime metrics collection remains available in spectator-js-nodejsmetrics, which has been updated to use this thin client library to report metrics. Follow instructions in the README to enable collection.
- Some types have been moved to different packages. For example,
Counteris now in./meter/counter.js, but it is also exported in the top-level index.
Removed¶
For the removed Meter classes, we observed little to no direct uses of them. They either represent advanced functionality which was not used or their capabilities are replicated in the currently available set of Meters.
BucketCounterhas been removed. This is a pattern on top of theCounter, which maps the value to a bucket dimension. If this was used properly, then create your own bucket function, add the dimension, and then use the underlying type. Alternatively, considerCounter.BucketDistributionSummaryhas been removed. This is a pattern on top of theDistributionSummary, which maps the value to a bucket dimension. If this aws used properly, then create your own bucket function, add the dimension, and then use the underlying type. Alternatively, considerDistributionSummaryorPercentileDistriutionsummary.BucketFunctionshas been removed. There should not have been direct uses of this class - it was a support class forBucketCounter,BucketDistributionSummary, andBucketTimer. It may be used as a model for recreating bucket functions locally.BucketTimerhas been removed. This is a pattern on top of theTimer, which maps the value to a bucket dimension. If this was used properly, then create your own bucket function, add the dimension, and then use the underlying type. Alternatively, considerTimerorPercentileTimer.IntervalCounterhas been removed. This is a composite type that has aCounterand a duration that measures the age since the last increment. Create aCounterand anAgeGaugethat is set tonow()after each increment, with the same name and tags applied.LongTaskTimerhas been removed. This is like anAgeGauge, except that it measures the time while executing some task. For example, if you have a 4-hour job that runs once a day, you could start it when the task starts and end it when the task ends. During the operating window, it would show how long the task has been running. Outside of that, interval it would show 0. Implement asetIntervalto track job status while it remains active, and update aGaugemetric with the total number of seconds elapsed.PolledMeterhas been removed. Implement asetIntervalto track the value of interest at a 1-minute interval, and update aGaugemetric with the value. Alternatively, consider aGaugewith a TTL, or anAgeGauge.HttpClienthas been removed, and it was never exported. Use the standardhttpsclient, or another library, instead.Meters no longer have ameasure()method. Meters are now stateless and do not store measurements.Registryno longer has astart()function. TheRegistryis now effectively stateless and there is nothing to start other than opening the output location.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.Registryno longer reportsspectator.measurementsmetrics. Instead, you can use similar metrics fromspectatordfor visibility.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.Registryno longer allows setting a different logger after creation. A custom logger can be set in theConfigbefore creating the Registry.
Migration Steps¶
- Make sure you're not relying on any of the removed functionality.
- Update imports for
Config,Registry, and anyMeters andWriters that are used for testing. - If you used one of the advanced meter types, such as
BucketCounter,BucketDistributionSummary,BucketTimer,IntervalCounter,LongTaskTimer, orPolledMeter, then choose a replacement implementation as suggested in the removed functionality section. Our internal code searches indicate that it was rare for any of these to be used, so you are most likely not affected by this change. - If you want to collect runtime metrics, then add the spectator-js-nodejsmetrics library, and follow the instructions in the README.
- If you use meters such as
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-jsinternal 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 set theConfigobjectlocationparameter tononeto configure a no-op writer.