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 Meter
s have been added:
AgeGauge
MaxGauge
MonotonicCounter
MonotonicCounterUint
Gauge
with 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¶
Config
is 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,
Counter
is 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.
BucketCounter
has 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
.BucketDistributionSummary
has 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, considerDistributionSummary
orPercentileDistriution
summary.BucketFunctions
has 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.BucketTimer
has 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, considerTimer
orPercentileTimer
.IntervalCounter
has been removed. This is a composite type that has aCounter
and a duration that measures the age since the last increment. Create aCounter
and anAgeGauge
that is set tonow()
after each increment, with the same name and tags applied.LongTaskTimer
has 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 asetInterval
to track job status while it remains active, and update aGauge
metric with the total number of seconds elapsed.PolledMeter
has been removed. Implement asetInterval
to track the value of interest at a 1-minute interval, and update aGauge
metric with the value. Alternatively, consider aGauge
with a TTL, or anAgeGauge
.HttpClient
has been removed, and it was never exported. Use the standardhttps
client, or another library, instead.Meter
s no longer have ameasure()
method. Meters are now stateless and do not store measurements.Registry
no longer has astart()
function. TheRegistry
is now effectively stateless and there is nothing to start other than opening the output location.Registry
no 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.Registry
no longer reportsspectator.measurements
metrics. Instead, you can use similar metrics fromspectatord
for visibility.Registry
no 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.Registry
no longer allows setting a different logger after creation. A custom logger can be set in theConfig
before creating the Registry.
Migration Steps¶
- Make sure you're not relying on any of the removed functionality.
- Update imports for
Config
,Registry
, and anyMeter
s andWriter
s 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
PercentileDistributionSummary
orPercentileTimer
, then you need to update your code to use the respective functions provided by theRegistry
to initialize these meters. - Remove the dependency on the
spectator-js
internal configuration library - it is no longer required. - There is no longer an option to
start()
orstop()
theRegistry
at runtime. If you need to configure aRegistry
that doesn't emit metrics, for testing purposes, you can set theConfig
objectlocation
parameter tonone
to configure a no-op writer.