Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow registering a custom label sink (#100)

authored by

Leon Shi and committed by
GitHub
4a9114b1 317bb9b4

+30 -2
+21
osprey_worker/src/osprey/worker/adaptor/hookspecs/osprey_hooks.py
··· 61 61 service base and utilizing the provided labels provider, or by overriding the labels provider to 62 62 fit your needs""" 63 63 raise NotImplementedError('register_labels_service_or_provider must be implemented by the plugin') 64 + 65 + 66 + @hookspec(firstresult=True) 67 + def register_label_output_sink(config: Config, labels_provider: LabelsProvider) -> BaseOutputSink | None: 68 + """ 69 + Optional: Register a custom label output sink. 70 + 71 + If a sink is returned, it will be used instead of the default LabelOutputSink. 72 + This allows plugins to provide custom label mutation handling (e.g., with additional 73 + analytics, webhooks, or other side effects). 74 + 75 + If None is returned or this hook is not implemented, the default LabelOutputSink is used. 76 + 77 + Args: 78 + config: The Osprey configuration object. 79 + labels_provider: The labels provider instance (from register_labels_service_or_provider). 80 + 81 + Returns: 82 + A custom BaseOutputSink for handling label mutations, or None to use the default. 83 + """ 84 + pass
+9 -2
osprey_worker/src/osprey/worker/adaptor/plugin_manager.py
··· 73 73 load_all_osprey_plugins() 74 74 sinks = flatten(plugin_manager.hook.register_output_sinks(config=config)) 75 75 76 - # Label udfs should only be registered if the labels provider is available 76 + # Label output sink should only be added if the labels provider is available 77 77 labels_provider = LABELS_PROVIDER.instance() 78 78 if labels_provider: 79 - sinks.append(LabelOutputSink(labels_provider)) 79 + # Check if a custom label output sink is provided by plugins 80 + custom_label_sink = plugin_manager.hook.register_label_output_sink( 81 + config=config, labels_provider=labels_provider 82 + ) 83 + if custom_label_sink: 84 + sinks.append(custom_label_sink) 85 + else: 86 + sinks.append(LabelOutputSink(labels_provider)) 80 87 81 88 return MultiOutputSink(sinks) 82 89