Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

fix: sampler now samples correctly #100

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

justindsmith
Copy link
Contributor

Sampler was not adhering to the configured propability when not ALWAYS or
NEVER. Issue was that the Sampler was using Number.MAX_VALUE, which uses
1024-bits. There were two issues with this approach:

  1. The MAX_VALUE is NOT considered a "safe integer" and thus there are side
    effects during manipulation.
  2. The shouldSample method was only comparing the idUpperBound (based on
    1024-bits of data) to the lower 16 characters (64-bits) of a trace, which
    was resulting in the configured probabilty not being respected.

We now us a 52-bit number, which falls within the "safe integer" range (53-bits)
and is able to be fully represented by a 13-diget hex value. This allows the
value to:

  1. Be safely algorithmically manipulated without side effects.
  2. Be easily compared to the lower 52-bits (13 characters) of a traceId.

The tests have been updated to perform validation of traceIds that should and
should not be sampled given a probability.

fixes #99

Sampler was not adhering to the configured propability when not ALWAYS or
NEVER. Issue was that the Sampler was using Number.MAX_VALUE, which uses
1024-bits. There were two issues with this approach:

1. The MAX_VALUE is NOT considered a "safe integer" and thus there are side
   effects during manipulation.
2. The `shouldSample` method was only comparing the idUpperBound (based on
   1024-bits of data) to the lower 16 characters (64-bits) of a trace, which
   was resulting in the configured probabilty not being respected.

We now us a 52-bit number, which falls within the "safe integer" range (53-bits)
and is able to be fully represented by a 13-diget hex value. This allows the
value to:

1. Be safely algorithmically manipulated without side effects.
2. Be easily compared to the lower 52-bits (13 characters) of a traceId.

The tests have been updated to perform validation of traceIds that should and
should not be sampled given a probability.
The zpages tests were relying on the fact that the sampler was broken, they
have now been configured to always sample to make sure the tests pass.
@kjin
Copy link
Contributor

kjin commented Aug 23, 2018

@justindsmith Thanks!

@kjin kjin merged commit 7ca6aba into census-instrumentation:master Aug 23, 2018
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
Sampler was not adhering to the configured propability when not ALWAYS or
NEVER. Issue was that the Sampler was using Number.MAX_VALUE, which uses
1024-bits. There were two issues with this approach:

1. The MAX_VALUE is NOT considered a "safe integer" and thus there are side
   effects during manipulation.
2. The `shouldSample` method was only comparing the idUpperBound (based on
   1024-bits of data) to the lower 16 characters (64-bits) of a trace, which
   was resulting in the configured probabilty not being respected.

We now us a 52-bit number, which falls within the "safe integer" range (53-bits)
and is able to be fully represented by a 13-diget hex value. This allows the
value to:

1. Be safely algorithmically manipulated without side effects.
2. Be easily compared to the lower 52-bits (13 characters) of a traceId.

The tests have been updated to perform validation of traceIds that should and
should not be sampled given a probability.
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
Sampler was not adhering to the configured propability when not ALWAYS or
NEVER. Issue was that the Sampler was using Number.MAX_VALUE, which uses
1024-bits. There were two issues with this approach:

1. The MAX_VALUE is NOT considered a "safe integer" and thus there are side
   effects during manipulation.
2. The `shouldSample` method was only comparing the idUpperBound (based on
   1024-bits of data) to the lower 16 characters (64-bits) of a trace, which
   was resulting in the configured probabilty not being respected.

We now us a 52-bit number, which falls within the "safe integer" range (53-bits)
and is able to be fully represented by a 13-diget hex value. This allows the
value to:

1. Be safely algorithmically manipulated without side effects.
2. Be easily compared to the lower 52-bits (13 characters) of a traceId.

The tests have been updated to perform validation of traceIds that should and
should not be sampled given a probability.
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
Sampler was not adhering to the configured propability when not ALWAYS or
NEVER. Issue was that the Sampler was using Number.MAX_VALUE, which uses
1024-bits. There were two issues with this approach:

1. The MAX_VALUE is NOT considered a "safe integer" and thus there are side
   effects during manipulation.
2. The `shouldSample` method was only comparing the idUpperBound (based on
   1024-bits of data) to the lower 16 characters (64-bits) of a trace, which
   was resulting in the configured probabilty not being respected.

We now us a 52-bit number, which falls within the "safe integer" range (53-bits)
and is able to be fully represented by a 13-diget hex value. This allows the
value to:

1. Be safely algorithmically manipulated without side effects.
2. Be easily compared to the lower 52-bits (13 characters) of a traceId.

The tests have been updated to perform validation of traceIds that should and
should not be sampled given a probability.
@justindsmith justindsmith deleted the sampler branch August 24, 2018 23:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Probability Sampler does not respect probability
3 participants