<commit_before>// Copyright 2015-2017 trivago GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package router

import (
	"github.com/trivago/gollum/core"
)

// Broadcast router plugin
//
// The "Broadcast" plugin relays all messages sent to [Stream] to all
// produces connected to [Stream].
//
// With the default options, this plugin has no practical effect. Using
// the Filters and TimeoutMs options, it is possible to restrict and control
// the messages being passed.
//
// Configuration example:
//
// # Generate junk messages
// JunkGenerator:
//   Type: "consumer.Profiler"
//   Message: "%20s"
//   Streams: "junkstream"
//   Characters: "abcdefghijklmZ"
//   KeepRunning: true
//   Runs: 10000
//   Batches: 3000000
//   DelayMs: 500
// # Filter out messsages including 'Z' and broadcast them
// JunkRouterBroad:
//   Type: "router.Broadcast"
//   Stream: "junkstream"
//   Filters:
//     - JunkRegexp:
//         Type: "filter.RegExp"
//         Expression: "Z"
// # Produce filtered messages from 'junkstream' to stdout
// JunkPrinter00:
//   Type: "producer.Console"
//   Streams: "junkstream"
//   Modulators:
//     - "format.Envelope":
//         Prefix: "[junkdist_00] "
// # Produce filtered messages from 'junkstream' to stdout
// JunkPrinter01:
//   Type: "producer.Console"
//   Streams: "junkstream"
//   Modulators:
//     - "format.Envelope":
//         Prefix: "[junkdist_01] "
//
type Broadcast struct {
	core.SimpleRouter `gollumdoc:"embed_type"`
}

func init() {
	core.TypeRegistry.Register(Broadcast{})
}

// Configure initializes this distributor with values from a plugin config.
func (router *Broadcast) Configure(conf core.PluginConfigReader) {
}

// Start the router
func (router *Broadcast) Start() error {
	return nil
}

// Enqueue enques a message to the router
func (router *Broadcast) Enqueue(msg *core.Message) error {
	producers := router.GetProducers()
	if len(producers) == 0 {
		return core.NewModulateResultError(
			"Router %s: no producers configured", router.GetID())
	}

	timeout := router.GetTimeout()
	lastProdIdx := len(producers) - 1
	for _, prod := range producers[:lastProdIdx] {<commit_msg>update plugin docs for router.broadcast<commit_after>// Copyright 2015-2017 trivago GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package router

import (
	"github.com/trivago/gollum/core"
)

// Broadcast router
//
// This router implements the default behavior of routing all messages to all
// producers registered to the configured stream.
//
// Examples
//
//  rateLimiter:
//    Type: router.Broadcast
//    Stream: errorlogs
//    Filters:
//      - filter.Rate:
//        MessagesPerSec: 200
type Broadcast struct {
	core.SimpleRouter `gollumdoc:"embed_type"`
}

func init() {
	core.TypeRegistry.Register(Broadcast{})
}

// Configure initializes this distributor with values from a plugin config.
func (router *Broadcast) Configure(conf core.PluginConfigReader) {
}

// Start the router
func (router *Broadcast) Start() error {
	return nil
}

// Enqueue enques a message to the router
func (router *Broadcast) Enqueue(msg *core.Message) error {
	producers := router.GetProducers()
	if len(producers) == 0 {
		return core.NewModulateResultError(
			"Router %s: no producers configured", router.GetID())
	}

	timeout := router.GetTimeout()
	lastProdIdx := len(producers) - 1
	for _, prod := range producers[:lastProdIdx] {
{'fraction_non_alphanumeric': 0.11796733212341198, 'fraction_numerical': 0.012704174228675136, 'mean_word_length': 3.3827037773359843, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7349049', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1294, 'n_words': 462}