| 65 | } |
| 66 | |
| 67 | func (b *labelBuilder) CloseAndBuildLabels() (labels.Labels, bool) { |
| 68 | // We always run sanitizer first and then run per label limiter to ensure that |
| 69 | // per label limits are always applied after sanitizer. |
| 70 | // Pipeline: sanitize labels --> per-label cardinality limit --> entity/series limit |
| 71 | lbls := b.sanitizer.Sanitize(b.builder.Labels()) |
| 72 | lbls = b.perLabelLimiter.Limit(lbls) |
| 73 | // it's no longer safe to use the builder after this point, so we drop our |
| 74 | // reference to it. this may cause a nil panic if the builder is used after |
| 75 | // this point, but it's better than memory corruption. |
| 76 | builderPool.Put(b.builder) |
| 77 | b.builder = nil |
| 78 | |
| 79 | if !lbls.IsValid(model.UTF8Validation) { |
| 80 | return lbls, false |
| 81 | } |
| 82 | |
| 83 | return lbls, true |
| 84 | } |