Skip to content

Conversation

@grobinson-grafana
Copy link
Contributor

@grobinson-grafana grobinson-grafana commented Apr 17, 2025

What this PR does / why we need it:

This commit separates out the tests for GetPartitionConsumers from GetStreamUsage, and adds separate tests to assert the expected behavior of GetPartitionConsumers and the expected behavior of the cache.

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

This commit separates out the tests for GetPartitionConsumers
from GetStreamUsage, and adds separate tests to assert the expected
behavior of GetPartitionConsumers and the expected behavior of the
cache.
@grobinson-grafana grobinson-grafana requested a review from a team as a code owner April 17, 2025 14:56
}

func (g *RingStreamUsageGatherer) getPartitionConsumers(ctx context.Context, rs ring.ReplicationSet) (map[int32]string, error) {
func (g *RingStreamUsageGatherer) getPartitionConsumers(ctx context.Context, instances []ring.InstanceDesc) (map[int32]string, error) {
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 will using this for zone-awareness.

}
}

func TestRingStreamUsageGatherer_GetPartitionConsumers_CacheHitsAndMisses(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitting out this test will make it easier to test zone awareness.

const numPartitions = 2 // Using 2 partitions for simplicity in tests
const cacheTTL = 1 * time.Second

func TestRingStreamUsageGatherer_GetPartitionConsumers(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to test GetPartitionConsumers, as that is where the cache is used.

@grobinson-grafana grobinson-grafana force-pushed the grobinson/separate-tests-for-get-partition-consumers branch from c5fd1d8 to b58fbcb Compare April 18, 2025 10:28
@grobinson-grafana grobinson-grafana merged commit 1973701 into main Apr 18, 2025
122 checks passed
@grobinson-grafana grobinson-grafana deleted the grobinson/separate-tests-for-get-partition-consumers branch April 18, 2025 16:07
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