Skip to content

feat(common.shim): Add batch to shim #16148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 23, 2025
Merged

Conversation

revilon1991
Copy link
Contributor

Summary

I want to use batch with shim within the method Write.

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #11902
resolves #10277

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Nov 5, 2024

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@revilon1991
Copy link
Contributor Author

!signed-cla

@revilon1991 revilon1991 force-pushed the shim_batch branch 2 times, most recently from 2cedc7c to f6ed0af Compare November 5, 2024 18:57
@mstrandboge
Copy link
Member

@revilon1991 Thanks for the PR! I see you commented for the CLA checker, but I don't see your username in the list. Could you double check that you submitted that? Thanks!

@mstrandboge mstrandboge self-assigned this Nov 13, 2024
@revilon1991
Copy link
Contributor Author

@DStrand1 which list? I don't know what I should do else

@revilon1991 revilon1991 changed the title add batch shim for output.execd feat(common.shim): Add batch to shim Nov 29, 2024
@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Nov 29, 2024
@revilon1991
Copy link
Contributor Author

!signed-cla

@mstrandboge mstrandboge assigned srebhan and unassigned mstrandboge Feb 24, 2025
@mstrandboge mstrandboge added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Feb 24, 2025
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@revilon1991 thank you for tackling this long-standing issues!

However, I think your code is far too complicated. Why not simply adding BatchSize as config parameter (as you do) with a default value of 1 (for backward compatibility). Then do something like

	metrics  := make([]telegraf.Metric, 0, s.BatchSize)
	scanner := bufio.NewScanner(s.stdin)
	for scanner.Scan() {
		// Read metrics from stdin
		m, err := parser.ParseLine(scanner.Text())
		if err != nil {
			fmt.Fprintf(s.stderr, "Failed to parse metric: %s\n", err)
			continue
		}
		metrics = append(metrics, m)

		// If we got more than our batch size, flush out the metrics
		// until we emptied the buffer enough.
		for len(metrics) >= s.BatchSize {
			if err = s.Output.Write(metrics[:s.BatchSize]); err != nil {
				fmt.Fprintf(s.stderr, "Failed to write metrics: %s\n", err)
			}
			metrics = metrics[s.BatchSize:]
		}
	}

	// Output all remaining metrics
	for len(metrics) >= s.BatchSize {
		if err = s.Output.Write(metrics[:s.BatchSize]); err != nil {
			fmt.Fprintf(s.stderr, "Failed to write metrics: %s\n", err)
		}
		metrics = metrics[s.BatchSize:]
	}

@srebhan srebhan added waiting for response waiting for response from contributor and removed ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. labels Feb 27, 2025
@telegraf-tiger
Copy link
Contributor

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!

@telegraf-tiger telegraf-tiger bot closed this Mar 13, 2025
@revilon1991
Copy link
Contributor Author

@srebhan hello, can you reopen this pr?

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Mar 22, 2025
@srebhan srebhan reopened this Apr 14, 2025
@srebhan
Copy link
Member

srebhan commented Apr 14, 2025

@revilon1991 sorry I missed your message! Reopened...

@revilon1991
Copy link
Contributor Author

@srebhan I’ve reviewed your code — yes, it fits in nicely and isn’t overly complex. It should work correctly as well. Thanks a lot for your contribution!

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @revilon1991 for your contribution!

@srebhan srebhan assigned skartikey and mstrandboge and unassigned srebhan Apr 17, 2025
@srebhan srebhan added external plugin Plugins that would be ideal external plugin and expedite being able to use plugin w/ Telegraf plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels Apr 17, 2025
@srebhan
Copy link
Member

srebhan commented Apr 17, 2025

@mstrandboge and @skartikey can we please get a review from both of you as I was involved in the code...

@telegraf-tiger
Copy link
Contributor

Copy link
Contributor

@skartikey skartikey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @srebhan for pushing those changes!

@skartikey skartikey merged commit b715237 into influxdata:master Apr 23, 2025
27 checks passed
@github-actions github-actions bot added this to the v1.35.0 milestone Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external plugin Plugins that would be ideal external plugin and expedite being able to use plugin w/ Telegraf feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External plugin does not adhere to metric_batch_size shim trigger output to write single metric
5 participants