(desc *Desc, opts SummaryOpts, labelValues ...string)
| 192 | } |
| 193 | |
| 194 | func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary { |
| 195 | if len(desc.variableLabels.names) != len(labelValues) { |
| 196 | panic(makeInconsistentCardinalityError(desc.fqName, desc.variableLabels.names, labelValues)) |
| 197 | } |
| 198 | |
| 199 | for _, n := range desc.variableLabels.names { |
| 200 | if n == quantileLabel { |
| 201 | panic(errQuantileLabelNotAllowed) |
| 202 | } |
| 203 | } |
| 204 | for _, lp := range desc.constLabelPairs { |
| 205 | if lp.GetName() == quantileLabel { |
| 206 | panic(errQuantileLabelNotAllowed) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if opts.Objectives == nil { |
| 211 | opts.Objectives = map[float64]float64{} |
| 212 | } |
| 213 | |
| 214 | if opts.MaxAge < 0 { |
| 215 | panic(fmt.Errorf("illegal max age MaxAge=%v", opts.MaxAge)) |
| 216 | } |
| 217 | if opts.MaxAge == 0 { |
| 218 | opts.MaxAge = DefMaxAge |
| 219 | } |
| 220 | |
| 221 | if opts.AgeBuckets == 0 { |
| 222 | opts.AgeBuckets = DefAgeBuckets |
| 223 | } |
| 224 | |
| 225 | if opts.BufCap == 0 { |
| 226 | opts.BufCap = DefBufCap |
| 227 | } |
| 228 | |
| 229 | if opts.now == nil { |
| 230 | opts.now = time.Now |
| 231 | } |
| 232 | if len(opts.Objectives) == 0 { |
| 233 | // Use the lock-free implementation of a Summary without objectives. |
| 234 | s := &noObjectivesSummary{ |
| 235 | desc: desc, |
| 236 | labelPairs: MakeLabelPairs(desc, labelValues), |
| 237 | counts: [2]*summaryCounts{{}, {}}, |
| 238 | } |
| 239 | s.init(s) // Init self-collection. |
| 240 | s.createdTs = timestamppb.New(opts.now()) |
| 241 | return s |
| 242 | } |
| 243 | |
| 244 | s := &summary{ |
| 245 | desc: desc, |
| 246 | now: opts.now, |
| 247 | |
| 248 | objectives: opts.Objectives, |
| 249 | sortedObjectives: make([]float64, 0, len(opts.Objectives)), |
| 250 | |
| 251 | labelPairs: MakeLabelPairs(desc, labelValues), |
no test coverage detected