Skip to content

Reject probe-type-specific validators at config time #1397

Closed

Description

@manugarg

Probe-type-specific validators are silently inert when attached to the wrong probe type.

http_validator type-asserts its input to *http.Response, and the new dns_validator (#1396) asserts *dns.Msg. When the assertion fails, Validate returns an error, and RunValidators logs it and continues:

https://github.com/cloudprober/cloudprober/blob/master/internal/validators/validators.go#L141-L144

So the validator never contributes a failure. A user who attaches dns_validator { authoritative: true } to an HTTP probe sees 100% success forever, with one log line per probe run. Same for http_validator on a non-HTTP probe. Related: validators are not supported at all for UDP / UDP_LISTENER probes, and configuring one there is silently ignored too.

This should be a config error at startup, not a runtime log.

Suggested approach

Check it in BuildProbeOptions, next to the existing negative_test check, which is the same shape:

https://github.com/cloudprober/cloudprober/blob/master/probes/options/options.go#L199-L201

var validatorProbeTypes = map[string][]configpb.ProbeDef_Type{
    "http_validator": {configpb.ProbeDef_HTTP},
    "dns_validator":  {configpb.ProbeDef_DNS},
}

BuildProbeOptions already has both halves in scope right where it calls validators.Init: p.GetValidator() (raw protos, oneof still intact) and p.GetType().

Notes on why there rather than elsewhere:

  • Not in each probe's Init: by then opts.Validators is []*validators.Validator, i.e. just {Name, Validate} — initValidator has erased the oneof type, so a probe can't tell what it was handed without adding a type field to the struct. It would also mean every probe rejecting every foreign validator (N x M) instead of one table.
  • Not in validators.Init: keeps the validator framework from having to know about probe types. probes/options already imports both.

The same table can cover the UDP case (no validators supported).

Activity

  1. Guflly commented on Aug 2, 2026

    @Guflly
    Contributor

    I'd like to work on this. I'll add config-time validation for incompatible probe and validator types, with focused tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions