Skip to content
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

feat: add limits package #16489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

grobinson-grafana
Copy link
Contributor

@grobinson-grafana grobinson-grafana commented Feb 27, 2025

What this PR does / why we need it:

This commit adds a new limits package for enforcing per-tenant limits. It is the first of a number of pull requests to move code from feat/usage-tracker into main.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@grobinson-grafana grobinson-grafana requested a review from a team as a code owner February 27, 2025 14:20
@grobinson-grafana grobinson-grafana force-pushed the grobinson/add-limits-pkg branch 6 times, most recently from 5d08a8c to 56df031 Compare February 28, 2025 13:56
This commit adds a new limits package for enforcing per-tenant limits.

// EncodeStreamMetadata encodes the stream metadata into a Kafka record
// using the tenantID as the key and partition as the target partition
func EncodeStreamMetadata(partition int32, topic string, tenantID string, streamHash uint64) *kgo.Record {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@periklis why don't we change it to (*kgo.Record, error)? Then we can return an error on line 215?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree on that too, we should now hide the error

// DecodeStreamMetadata decodes a Kafka record into a StreamMetadata.
// It returns the decoded metadata and any error encountered.
func DecodeStreamMetadata(record *kgo.Record) (*logproto.StreamMetadata, error) {
if record == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@periklis Do we need these two checks? It should be expected that the caller passes a non-nil record that also has a non-nil record.Value?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with that we can drop them now.


var (
tenantPartitionDesc = prometheus.NewDesc(
constants.Loki+"_ingest_limits_partitions",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is no longer recommended, almost all of our new code adds loki as a string literal.

metadata map[string]map[int32][]streamMetadata // tenant -> partitionID -> streamMetadata

// Track partition assignments
mtxAssingedPartitions sync.RWMutex
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to remove this, we will just use mtx.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you have already removed that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but it regressed somehow, need to remove it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants