/**
Generates random alphanumeric strings and writes it to a specified file at specified line rate(lps) and for specified duration.
*/
Generates random alphanumeric strings and writes it to a specified file at specified line rate(lps) and for specified duration.
/ ** Generates random alphanumeric strings and writes it to a specified file at specified line rate ( lps ) and for specified duration . * /
func GenerateAlphaNumeric(promRegistry *prometheus.Registry, props *LoadGenProperties) {
	fmt.Print("Generating random alphanumeric characters...")
	var log = logrus.New()
	var fileArray = make([]*os.File, props.FileCount, props.FileCount)
	var logHandlers = make([]*logrus.Logger, props.FileCount, props.FileCount)
	if props.Rotate == true {
		fmt.Println("log rotation enabled")
		logHandlers = props.fetchLogHandlers(true)
		props.setupLogRotation(props.FilePath, logHandlers)
	} else {
		fileArray, _ = props.fileRef()
	}
	rateLimit := ratelimit.New(int(props.Lps))
	timer := time.After(props.durationInSeconds())
	var totalLineCount float64
	var singleLineCount float64
	var multiLineCount float64
	singleLineResult := props.buildLine()
	multiLineResult := props.buildMultiLine()
	numberOfFiles := int(props.FileCount)
	fileCountIndex := 0
	prev := time.Now()
	counter := metrics.NewCounter()
	goGenMetricsRegistry := metrics.NewRegistry()
	goGenMetricsRegistry.Register("total_events_processed", counter)
	metricsLogger := logrus.New()
	metricsLogger.Out = os.Stdout
	metricsLogger.Formatter = utility.GetFormatter(true)
	go metrics.Log(goGenMetricsRegistry, 1*time.Second, metricsLogger)
	var promCounter, promTotalBytesProcessedCounter prometheus.Counter
	if props.EnableMetrics {
		promCounter = metricsUtility.GetEventsProcessedCounter()
		promTotalBytesProcessedCounter = metricsUtility.GetTotalBytesProcessedCounter()
		promRegistry.MustRegister(promCounter)
		promRegistry.MustRegister(promTotalBytesProcessedCounter)
	}
	metrics.NewRegisteredFunctionalGauge("bytes-per-second", goGenMetricsRegistry, func() int64 {
		value := props.LineLength * props.Lps
		if props.EnableMetrics {
			promTotalBytesProcessedCounter.Add(float64(value))
		}
		return value
	})
	for {
		now := rateLimit.Take()
		select {
		case _ = <-timer:
			wrapUpTask(props, int64(totalLineCount))
			return
		default:
			{
				counter.Inc(1)
				if props.EnableMetrics {
					promCounter.Add(1)
				}
			}
		}
		if !props.Rotate {
			log.Out = fileArray[fileCountIndex]
			if props.LogFormat == nil {
				log.SetFormatter(utility.GetFormatter(true))
			} else {
				log.SetFormatter(props.LogFormat)
			}
		} else {
			log = logHandlers[fileCountIndex]
		}
		if int(multiLineCount/totalLineCount*100) <= props.MultiLinePercent && props.MultiLinePercent != 0 {
			log.Info(multiLineResult)
			multiLineCount++
		} else {
			log.Info(singleLineResult)
			singleLineCount++
		}
		if fileCountIndex == numberOfFiles-1 {
			fileCountIndex = 0
		} else {
			fileCountIndex++
		}
		now.Sub(prev)
		prev = now
		totalLineCount++
	}
}
func GenerateAlphaNumeric ( promRegistry * prometheus . Registry , props * LoadGenProperties ) { fmt . Print ( " " ) var log = logrus . New ( ) var fileArray = make ( [ ] * os . File , props . FileCount , props . FileCount ) var logHandlers = make ( [ ] * logrus . Logger , props . FileCount , props . FileCount ) if props . Rotate == true { fmt . Println ( " " ) logHandlers = props . fetchLogHandlers ( true ) props . setupLogRotation ( props . FilePath , logHandlers ) } else { fileArray , _ = props . fileRef ( ) } rateLimit := ratelimit . New ( int ( props . Lps ) ) timer := time . After ( props . durationInSeconds ( ) ) var totalLineCount float64 var singleLineCount float64 var multiLineCount float64 singleLineResult := props . buildLine ( ) multiLineResult := props . buildMultiLine ( ) numberOfFiles := int ( props . FileCount ) fileCountIndex := 0 prev := time . Now ( ) counter := metrics . NewCounter ( ) goGenMetricsRegistry := metrics . NewRegistry ( ) goGenMetricsRegistry . Register ( " " , counter ) metricsLogger := logrus . New ( ) metricsLogger . Out = os . Stdout metricsLogger . Formatter = utility . GetFormatter ( true ) go metrics . Log ( goGenMetricsRegistry , 1 * time . Second , metricsLogger ) var promCounter , promTotalBytesProcessedCounter prometheus . Counter if props . EnableMetrics { promCounter = metricsUtility . GetEventsProcessedCounter ( ) promTotalBytesProcessedCounter = metricsUtility . GetTotalBytesProcessedCounter ( ) promRegistry . MustRegister ( promCounter ) promRegistry . MustRegister ( promTotalBytesProcessedCounter ) } metrics . NewRegisteredFunctionalGauge ( " " , goGenMetricsRegistry , func ( ) int64 { value := props . LineLength * props . Lps if props . EnableMetrics { promTotalBytesProcessedCounter . Add ( float64 ( value ) ) } return value } ) for { now := rateLimit . Take ( ) select { case _ = <- timer : wrapUpTask ( props , int64 ( totalLineCount ) ) return default : { counter . Inc ( 1 ) if props . EnableMetrics { promCounter . Add ( 1 ) } } } if ! props . Rotate { log . Out = fileArray [ fileCountIndex ] if props . LogFormat == nil { log . SetFormatter ( utility . GetFormatter ( true ) ) } else { log . SetFormatter ( props . LogFormat ) } } else { log = logHandlers [ fileCountIndex ] } if int ( multiLineCount / totalLineCount * 100 ) <= props . MultiLinePercent && props . MultiLinePercent != 0 { log . Info ( multiLineResult ) multiLineCount ++ } else { log . Info ( singleLineResult ) singleLineCount ++ } if fileCountIndex == numberOfFiles - 1 { fileCountIndex = 0 } else { fileCountIndex ++ } now . Sub ( prev ) prev = now totalLineCount ++ } }
Generates random alphanumeric strings and writes it to a specified file at specified line rate(lps) and for specified duration.
Generates random alphanumeric strings and writes it to a specified file at specified line rate ( lps ) and for specified duration .
//rate limiter settings //duration settings //metrics //prometheus stuff //export to prom