-
Notifications
You must be signed in to change notification settings - Fork 486
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
Conversation
There was a problem hiding this 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!
err := srv.Run() | ||
if err != nil { | ||
level.Error(t.logger).Log("msg", "loki.source.api server shutdown with error", "err", err) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
There was a problem hiding this 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! ^^
component/loki/source/api/internal/lokipush/push_api_server_test.go
Outdated
Show resolved
Hide resolved
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
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:
PR Checklist
loki.source.+
network targets #3581