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

Add loki.source.api component #3648

Merged
merged 43 commits into from
May 5, 2023
Merged

Add loki.source.api component #3648

merged 43 commits into from
May 5, 2023

Conversation

thampiotr
Copy link
Contributor

@thampiotr thampiotr commented Apr 26, 2023

PR Description

Adds a new component which embeds promtail's loki push API.

Which issue(s) this PR fixes

Fixes #2767

Notes to the Reviewer

Looking for early feedback on:

  • confirm this is the right name for the component given it can also expose GRPC
  • confirm the river config format is following best practices
  • confirm what river config default values would be desired

PR Checklist

Copy link
Member

@tpaschalis tpaschalis left a comment

Choose a reason for hiding this comment

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

Nice one, we're getting somewhere!

component/loki/source/http/http.go Outdated Show resolved Hide resolved
component/loki/source/http/http.go Outdated Show resolved Hide resolved
component/loki/source/http/http.go Outdated Show resolved Hide resolved
component/loki/write/write.go Outdated Show resolved Hide resolved
component/loki/source/http/http.go Outdated Show resolved Hide resolved
component/loki/source/http/internal/lokipush/pushtarget.go Outdated Show resolved Hide resolved
component/loki/source/http/internal/lokipush/pushtarget.go Outdated Show resolved Hide resolved
component/loki/source/http/http.go Outdated Show resolved Hide resolved
@thampiotr thampiotr changed the title [draft] loki.source.http [draft] loki.source.api Apr 26, 2023
@thampiotr thampiotr marked this pull request as ready for review April 27, 2023 14:33
@thampiotr thampiotr changed the title [draft] loki.source.api loki.source.api Apr 27, 2023
@thampiotr thampiotr changed the title loki.source.api Add loki.source.api component Apr 27, 2023
Comment on lines 85 to 88
err := srv.Run()
if err != nil {
level.Error(t.logger).Log("msg", "loki.source.api server shutdown with error", "err", err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should consider some recovery mechanism for the case when the server dies?

Copy link
Member

Choose a reason for hiding this comment

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

Were you thinking of something in particular? In the simplest case, we could store a false for the server's readiness check and display in the component's debug info?

I don't think this should block us either way.

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, I can review this after the unification of the Server work lands.

Comment on lines +122 to +124
// NOTE: This code is copied from Promtail (3478e180211c17bfe2f3f3305f668d5520f40481) with changes kept to the minimum.
// Only the HTTP handler functions are copied to allow for flow-specific server configuration and lifecycle management.
func (s *PushAPIServer) handleLoki(w http.ResponseWriter, r *http.Request) {
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 am in favour of adopting this approach instead - we can simplify a lot of surrounding code and only copy the handler functions.

Copy link
Contributor Author

@thampiotr thampiotr left a comment

Choose a reason for hiding this comment

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

Updated to use the new server - PTAL

Copy link
Member

@tpaschalis tpaschalis left a comment

Choose a reason for hiding this comment

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

LGTM % docs fixes and few nits! ^^

docs/sources/flow/reference/components/loki.source.api.md Outdated Show resolved Hide resolved
docs/sources/flow/reference/components/loki.source.api.md Outdated Show resolved Hide resolved
docs/sources/flow/reference/components/loki.source.api.md Outdated Show resolved Hide resolved
docs/sources/flow/reference/components/loki.source.api.md Outdated Show resolved Hide resolved
docs/sources/flow/reference/components/loki.source.api.md Outdated Show resolved Hide resolved
Comment on lines +82 to +121
func (s *PushAPIServer) SetLabels(labels model.LabelSet) {
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
s.labels = labels
}

func (s *PushAPIServer) getLabels() model.LabelSet {
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
return s.labels.Clone()
}

func (s *PushAPIServer) SetKeepTimestamp(keepTimestamp bool) {
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
s.keepTimestamp = keepTimestamp
}

func (s *PushAPIServer) getKeepTimestamp() bool {
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
return s.keepTimestamp
}

func (s *PushAPIServer) SetRelabelRules(rules frelabel.Rules) {
s.rwMutex.Lock()
defer s.rwMutex.Unlock()
s.relabelRules = frelabel.ComponentToPromRelabelConfigs(rules)
}

func (s *PushAPIServer) getRelabelRules() []*relabel.Config {
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()
newRules := make([]*relabel.Config, len(s.relabelRules))
for i, r := range s.relabelRules {
var rCopy = *r
newRules[i] = &rCopy
}
return newRules
}
Copy link
Member

Choose a reason for hiding this comment

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

(nit, not a blocker) I'm not super convinced about the added complexity yet; in truth I don't imagine it will be often that people change the relabel rules or labels by hand that we'd win anything over not having to restart the server every time, and needing the setter/getter/having to copy the fields approach etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the other hand, detecting whether server needs a restart wasn't very pretty either. I had both implementations locally at some point, and personally I found this one to be easier to read.

thampiotr and others added 5 commits May 5, 2023 12:35
@tpaschalis tpaschalis merged commit af52a4e into main May 5, 2023
@tpaschalis tpaschalis deleted the thampiotr/loki_source_http branch May 5, 2023 13:18
clayton-cornell pushed a commit that referenced this pull request Aug 14, 2023
clayton-cornell pushed a commit that referenced this pull request Aug 14, 2023
@github-actions github-actions bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Feb 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loki.source.http: Receive log entries from HTTP calls
2 participants