You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Enis Sert <es...@google.com> on 2021/09/01 03:59:29 UTC

[Question] How does one test Counters?

Hi,

I'm planning to add an `org.apache.beam.sdk.metrics.Counter` to my Beam PR
and bump it when some event happens, similar to
https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImpl.java#L988.
However, I couldn't figure out how to test it with unit tests (i.e. I can't
verify that the counter is incremented at all, but I can verify that
the block containing it is executed). Can someone share an example?

Thanks,
esert

Re: [Question] How does one test Counters?

Posted by Luke Cwik <lc...@google.com>.
The example that Jeff gave where testing the metrics by querying the
pipeline is the best way to go.

There are a few places where the metrics container is setup and queried
directly but this is only done in a few cases where we aren't testing a
DoFn itself.


On Wed, Sep 1, 2021 at 6:53 AM Jeff Klukas <jk...@mozilla.com> wrote:

> We have a few transform-level tests where we check counter behavior in
> Mozilla's telemetry pipeline codebase. See:
>
>
> https://github.com/mozilla/gcp-ingestion/blob/fa98ac0c8fa09b5671a961062e6cf0985ec48b0e/ingestion-beam/src/test/java/com/mozilla/telemetry/decoder/GeoIspLookupTest.java#L77-L83
>
> But I'm not familiar with how much metrics testing exists within the
> apache/beam codebase.
>
> On Wed, Sep 1, 2021 at 12:08 AM Enis Sert <es...@google.com> wrote:
>
>> Hi,
>>
>> I'm planning to add an `org.apache.beam.sdk.metrics.Counter` to my Beam
>> PR and bump it when some event happens, similar to
>> https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImpl.java#L988.
>> However, I couldn't figure out how to test it with unit tests (i.e. I can't
>> verify that the counter is incremented at all, but I can verify that
>> the block containing it is executed). Can someone share an example?
>>
>> Thanks,
>> esert
>>
>

Re: [Question] How does one test Counters?

Posted by Jeff Klukas <jk...@mozilla.com>.
We have a few transform-level tests where we check counter behavior in
Mozilla's telemetry pipeline codebase. See:

https://github.com/mozilla/gcp-ingestion/blob/fa98ac0c8fa09b5671a961062e6cf0985ec48b0e/ingestion-beam/src/test/java/com/mozilla/telemetry/decoder/GeoIspLookupTest.java#L77-L83

But I'm not familiar with how much metrics testing exists within the
apache/beam codebase.

On Wed, Sep 1, 2021 at 12:08 AM Enis Sert <es...@google.com> wrote:

> Hi,
>
> I'm planning to add an `org.apache.beam.sdk.metrics.Counter` to my Beam
> PR and bump it when some event happens, similar to
> https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImpl.java#L988.
> However, I couldn't figure out how to test it with unit tests (i.e. I can't
> verify that the counter is incremented at all, but I can verify that
> the block containing it is executed). Can someone share an example?
>
> Thanks,
> esert
>