Skip to content

Add treatMissingData as an alias for treatMissingDataOverride #674

@dimakuv

Description

@dimakuv

Version

ALL

Steps and/or minimal code example to reproduce

I noticed that treatMissingData is silently ignored when (incorrectly) creating custom monitoring, smth like this:

const snsMetricGroup = {
    metrics: [
        {
            metric: snsMetric,
            addAlarm: {
                Warning: {
                    ...
                    treatMissingData: TreatMissingData.NOT_BREACHING,
                    comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
                }
            }
        }
    ],
};

this.monitoring.monitorCustom({
    ...
    metricGroups: [snsMetricGroup]
});

The interesting part is that comparisonOperator is not silently ignored.

This happens because:

Now if we look at the implementation of CustomAlarmFactory::addCustomAlarm() which is being called by monitorCustom() from my code snippet, we see this non-uniform behavior:

return this.alarmFactory.addAlarm(metric, {
...props,
disambiguator,
treatMissingData:
props.treatMissingDataOverride ?? TreatMissingData.MISSING,
threshold: props.threshold,
comparisonOperator:
props.comparisonOperatorOverride ?? props.comparisonOperator,
alarmDedupeStringSuffix: props.dedupeString,
alarmNameSuffix,
alarmDescription:
props.additionalDescription ??
`Threshold of ${props.threshold} has been breached.`,
});

  • Notice how comparisonOperator can be any of props.comparisonOperatorOverride and props.comparisonOperator defined by the user.
  • Notice how treatMissingData can only be overriden by props.treatMissingDataOverride, otherwise it defaults to the constant MISSING.

This is not a bug per se, but this is something that is easy to get wrong. It would make sense for developers (for readability) to allow only two options:

  • both comparisonOperator and treatMissingData
  • both comparisonOperatorOverride and treatMissingDataOverride
  • but not a mix of comparisonOperator and treatMissingDataOverride

Looking at git blame, I see that this inconsistency was introduced when this public GitHub repo was created: 8d7ce03. So this happens in all versions of CDK Monitoring Constructs.

Expected behavior

I would argue that the easiest fix would be to add the treatMissingData to CustomThreshold interface, and modify the CustomAlarmFactory::addCustomAlarm() implementation to fall back to this new field if no treatMissingDataOverride is set.

Actual behavior

Silent bug in our alarms, as discussed above (the alarms used TreatMissingData.MISSING instead of the requested TreatMissingData.NOT_BREACHING).

Other details

Slightly related issue: #669

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions