MockMetricsConfiguration

pydantic settings safir.metrics.MockMetricsConfiguration

Metrics configuration when metrics publishing is mocked.

Parameters:
  • _case_sensitive (bool | None, default: None)

  • _nested_model_default_partial_update (bool | None, default: None)

  • _env_prefix (str | None, default: None)

  • _env_file (Union[Path, str, Sequence[Union[Path, str]], None], default: PosixPath('.'))

  • _env_file_encoding (str | None, default: None)

  • _env_ignore_empty (bool | None, default: None)

  • _env_nested_delimiter (str | None, default: None)

  • _env_nested_max_split (int | None, default: None)

  • _env_parse_none_str (str | None, default: None)

  • _env_parse_enums (bool | None, default: None)

  • _cli_prog_name (str | None, default: None)

  • _cli_parse_args (bool | list[str] | tuple[str, ...] | None, default: None)

  • _cli_settings_source (Optional[CliSettingsSource[Any]], default: None)

  • _cli_parse_none_str (str | None, default: None)

  • _cli_hide_none_type (bool | None, default: None)

  • _cli_avoid_json (bool | None, default: None)

  • _cli_enforce_required (bool | None, default: None)

  • _cli_use_class_docs_for_groups (bool | None, default: None)

  • _cli_exit_on_error (bool | None, default: None)

  • _cli_prefix (str | None, default: None)

  • _cli_flag_prefix_char (str | None, default: None)

  • _cli_implicit_flags (bool | None, default: None)

  • _cli_ignore_unknown_args (bool | None, default: None)

  • _cli_kebab_case (bool | None, default: None)

  • _secrets_dir (Union[Path, str, Sequence[Union[Path, str]], None], default: None)

  • values (Any)

Show JSON schema
{
   "title": "MockMetricsConfiguration",
   "description": "Metrics configuration when metrics publishing is mocked.",
   "type": "object",
   "properties": {
      "appName": {
         "description": "The name of the application that is emitting these metrics",
         "title": "Application name",
         "type": "string"
      },
      "events": {
         "$ref": "#/$defs/EventsConfiguration",
         "title": "Events configuration"
      },
      "enabled": {
         "description": "If set to false, no events will be sent and all calls to publish events will be no-ops.",
         "title": "Whether to send events",
         "type": "boolean"
      },
      "mock": {
         "description": "If set to true, all event publishers will be unittest.mock.MagicMock instances which will record all calls to their publish methods.",
         "title": "Mock publishers",
         "type": "boolean"
      }
   },
   "$defs": {
      "EventsConfiguration": {
         "additionalProperties": false,
         "description": "Configuration for emitting events.",
         "properties": {
            "topicPrefix": {
               "default": "lsst.square.metrics.events",
               "description": "You probably should use the default here. It could be useful in development scenarios to change this.",
               "title": "Metrics topic prefix",
               "type": "string"
            }
         },
         "title": "EventsConfiguration",
         "type": "object"
      }
   },
   "required": [
      "appName",
      "enabled",
      "mock"
   ]
}

Config:
  • extra: str = ignore

  • populate_by_name: bool = True

  • validate_by_alias: bool = True

  • validate_by_name: bool = True

Fields:
field enabled: Annotated[bool, AfterValidator(lambda x: _require_bool(x, False))] [Required]

If set to false, no events will be sent and all calls to publish events will be no-ops.

Constraints:
  • func = <function <lambda> at 0x7f80c08920c0>

field mock: Annotated[bool, AfterValidator(lambda x: _require_bool(x, True))] [Required]

If set to true, all event publishers will be unittest.mock.MagicMock instances which will record all calls to their publish methods.

Constraints:
  • func = <function <lambda> at 0x7f80c08922a0>

make_manager(logger=None, *, kafka_clients=None)

Construct an EventManager.

Parameters:
  • logger (BoundLogger | None, default: None) – Logger to use for internal logging. If not given, the safir.metrics logger will be used.

  • kafka_clients (KafkaClients | None, default: None) – Kafka broker and admin client to use. If not given, a new Kafka broker and admin client will be created and automatically closed when the event manager is closed. If clients are provided, closing the event manager will have no effect on them and the caller is responsible for closing them.

Returns:

An event manager appropriate to the configuration.

Return type:

EventManager