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

Implement ingester API to return stream rates #7176

Merged
merged 15 commits into from
Oct 5, 2022

Conversation

MasslessParticle
Copy link
Contributor

@MasslessParticle MasslessParticle commented Sep 15, 2022

This PR introduces an API on the Ingester that reports all current streams in memory and their current rate in bytes/second. The reponse from the API contains a slice of StreamRate structs:

type StreamRate struct {
	StreamHash        uint64 `protobuf:"varint,1,opt,name=streamHash,proto3" json:"streamHash,omitempty"`
	StreamHashNoShard uint64 `protobuf:"varint,2,opt,name=streamHashNoShard,proto3" json:"streamHashNoShard,omitempty"`
	Rate              int64  `protobuf:"varint,3,opt,name=rate,proto3" json:"rate,omitempty"`
}

In the interest of space on the caller and in transmission, only hashes and rates are sent.

  • StreamHash will be used to deduplicate replicas
  • StreamHashNoShard will be used to aggregate a sharded stream's total rate.

Rate calculation will be in a follow on PR

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0.2%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Contributor

@jeschkies jeschkies left a comment

Choose a reason for hiding this comment

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

Interesting. I've always wondered how rate limiting was implemented. I wish the algorithm would expose the actual rate :/

@@ -387,6 +397,7 @@ func (s *stream) validateEntries(entries []logproto.Entry, isReplay bool) ([]log
}
}

s.rateCalculator.Record(int64(totalBytes))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this not using validBytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This preserves the current behavior where stream rate limits are calculated against all the bytes in the stream, not just the valid ones. I assume we do it this way because the rate limit is to protect the ingester and we process every entry, valid or not.

Comment on lines 32 to 36
t := time.NewTicker(1000 / bucketCount * time.Millisecond)
for range t.C {
rate := c.sample.Swap(0)
c.storeNewRate(rate)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this never stopped?

pkg/logproto/logproto.proto Outdated Show resolved Hide resolved
pkg/logproto/logproto.proto Outdated Show resolved Hide resolved
pkg/ingester/rate_calculator_test.go Outdated Show resolved Hide resolved
pkg/ingester/instance_test.go Outdated Show resolved Hide resolved
pkg/ingester/instance_test.go Outdated Show resolved Hide resolved
pkg/ingester/instance_test.go Outdated Show resolved Hide resolved
pkg/ingester/instance_test.go Outdated Show resolved Hide resolved
pkg/ingester/instance_test.go Outdated Show resolved Hide resolved
DylanGuedes and others added 4 commits September 26, 2022 15:29
**What this PR does / why we need it**:
Stop the rateCalculator timer when stream is about to be removed.

**Which issue(s) this PR fixes**:
N/A
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0.2%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0.1%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

-           ingester	-0.2%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Contributor

@DylanGuedes DylanGuedes left a comment

Choose a reason for hiding this comment

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

lgtm

just a small observation that shouldn't change anything

pkg/ingester/ingester.go Show resolved Hide resolved
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

-           ingester	-0.3%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@MasslessParticle MasslessParticle merged commit e3e4e27 into main Oct 5, 2022
@MasslessParticle MasslessParticle deleted the tpatterson/ingester-stream-api branch October 5, 2022 16:44
lxwzy pushed a commit to lxwzy/loki that referenced this pull request Nov 7, 2022
This PR introduces an API on the Ingester that reports all current
streams in memory and their current rate in bytes/second. The reponse
from the API contains a slice of `StreamRate` structs:

```go
type StreamRate struct {
	StreamHash        uint64 `protobuf:"varint,1,opt,name=streamHash,proto3" json:"streamHash,omitempty"`
	StreamHashNoShard uint64 `protobuf:"varint,2,opt,name=streamHashNoShard,proto3" json:"streamHashNoShard,omitempty"`
	Rate              int64  `protobuf:"varint,3,opt,name=rate,proto3" json:"rate,omitempty"`
}
```

In the interest of space on the caller and in transmission, only hashes
and rates are sent.
- `StreamHash` will be used to deduplicate replicas
- `StreamHashNoShard` will be used to aggregate a sharded stream's total
rate.

Co-authored-by: Dylan Guedes <djmgguedes@gmail.com>
changhyuni pushed a commit to changhyuni/loki that referenced this pull request Nov 8, 2022
This PR introduces an API on the Ingester that reports all current
streams in memory and their current rate in bytes/second. The reponse
from the API contains a slice of `StreamRate` structs:

```go
type StreamRate struct {
	StreamHash        uint64 `protobuf:"varint,1,opt,name=streamHash,proto3" json:"streamHash,omitempty"`
	StreamHashNoShard uint64 `protobuf:"varint,2,opt,name=streamHashNoShard,proto3" json:"streamHashNoShard,omitempty"`
	Rate              int64  `protobuf:"varint,3,opt,name=rate,proto3" json:"rate,omitempty"`
}
```

In the interest of space on the caller and in transmission, only hashes
and rates are sent.
- `StreamHash` will be used to deduplicate replicas
- `StreamHashNoShard` will be used to aggregate a sharded stream's total
rate.

Co-authored-by: Dylan Guedes <djmgguedes@gmail.com>
Abuelodelanada pushed a commit to canonical/loki that referenced this pull request Dec 1, 2022
This PR introduces an API on the Ingester that reports all current
streams in memory and their current rate in bytes/second. The reponse
from the API contains a slice of `StreamRate` structs:

```go
type StreamRate struct {
	StreamHash        uint64 `protobuf:"varint,1,opt,name=streamHash,proto3" json:"streamHash,omitempty"`
	StreamHashNoShard uint64 `protobuf:"varint,2,opt,name=streamHashNoShard,proto3" json:"streamHashNoShard,omitempty"`
	Rate              int64  `protobuf:"varint,3,opt,name=rate,proto3" json:"rate,omitempty"`
}
```

In the interest of space on the caller and in transmission, only hashes
and rates are sent.
- `StreamHash` will be used to deduplicate replicas
- `StreamHashNoShard` will be used to aggregate a sharded stream's total
rate.

Co-authored-by: Dylan Guedes <djmgguedes@gmail.com>
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.

4 participants