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: Introduce policy to received_bytes #16056

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

DylanGuedes
Copy link
Contributor

What this PR does / why we need it:
Introduce the policy label to the received_bytes metric family to be able to distinguish between different policies ingestion.

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

@DylanGuedes DylanGuedes force-pushed the introduce-policy-to-received-bytes branch 2 times, most recently from 5324437 to 9f8915b Compare February 3, 2025 16:35
Base automatically changed from add-stream-mapping-to-loki to main February 5, 2025 10:32
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Feb 5, 2025
@DylanGuedes DylanGuedes force-pushed the introduce-policy-to-received-bytes branch from 9f8915b to fa2f99e Compare February 5, 2025 11:06
@pull-request-size pull-request-size bot added size/L and removed size/XL labels Feb 5, 2025
@DylanGuedes DylanGuedes force-pushed the introduce-policy-to-received-bytes branch from edf28f0 to 9006a87 Compare February 5, 2025 23:35
@DylanGuedes DylanGuedes marked this pull request as ready for review February 6, 2025 16:44
@DylanGuedes DylanGuedes requested a review from a team as a code owner February 6, 2025 16:44
Copy link
Contributor

@salvacorts salvacorts left a comment

Choose a reason for hiding this comment

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

LGTM! Left some comments. Before merging I think we should"

  • Make sure no one besides Loki is using the push.Stats object
  • Test in dev (even ops) to make sure this works as expected.

@@ -111,7 +116,7 @@ func (t *PushTarget) run() error {
func (t *PushTarget) handleLoki(w http.ResponseWriter, r *http.Request) {
logger := util_log.WithContext(r.Context(), util_log.Logger)
userID, _ := tenant.TenantID(r.Context())
req, err := push.ParseRequest(logger, userID, r, nil, push.EmptyLimits{}, push.ParseLokiRequest, nil, nil, false)
req, err := push.ParseRequest(logger, userID, r, nil, push.EmptyLimits{}, push.ParseLokiRequest, nil, t.PolicyResolver, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about passing nil here? Then the parsers can do:

var policy string
if policyResolver != nil {
   policy = policyResolver...
}

@@ -1124,6 +1124,10 @@ func (o *Overrides) EnforcedLabels(userID string) []string {
return o.getOverridesForUser(userID).EnforcedLabels
}

func (o *Overrides) PolicyFor(userID string, lbs labels.Labels) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this one is unused?

@@ -439,6 +491,10 @@ func (f *fakeLimits) OTLPConfig(_ string) OTLPConfig {
return DefaultOTLPConfig(defaultGlobalOTLPConfig)
}

func (f *fakeLimits) PolicyFor(_ string, lbs labels.Labels) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

If unused, we can remove this one as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need a PolicyFor implementation and i'm using the environment label to tell which policy to use

expectedStructuredMetadataBytes int
expectedBytes int
expectedLines int
expectedStructuredMetadataBytes map[string]int
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a test here with multiple named and unnamed policies

Copy link
Contributor

Choose a reason for hiding this comment

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

Also passing nil as the policyResolver, in which case only one item per map should be expected ("")

}

totalNumLines := int64(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is more idiomatic

var totalNumLines int64

@@ -37,20 +37,21 @@ const (

func newPushStats() *Stats {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I know this one was already here, but I think it makes more sense to move this new function to push.go right below the definition of Stats

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol good find, totally overlooked that stats were defined in the other file. fixed.

pkg/loghttp/push/otlp.go Outdated Show resolved Hide resolved
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