| 56 | } |
| 57 | |
| 58 | func (e *httpEncoder) encodeData(connectionData *USMConnectionData[http.Key, *http.RequestStats], w io.Writer) (uint64, map[string]struct{}) { |
| 59 | var staticTags uint64 |
| 60 | dynamicTags := make(map[string]struct{}) |
| 61 | e.httpAggregationsBuilder.Reset(w) |
| 62 | |
| 63 | for _, kvPair := range connectionData.Data { |
| 64 | e.httpAggregationsBuilder.AddEndpointAggregations(func(httpStatsBuilder *model.HTTPStatsBuilder) { |
| 65 | key := kvPair.Key |
| 66 | stats := kvPair.Value |
| 67 | |
| 68 | httpStatsBuilder.SetPath(key.Path.Content.Get()) |
| 69 | httpStatsBuilder.SetFullPath(key.Path.FullPath) |
| 70 | httpStatsBuilder.SetMethod(uint64(model.HTTPMethod(key.Method))) |
| 71 | |
| 72 | for code, stats := range stats.Data { |
| 73 | httpStatsBuilder.AddStatsByStatusCode(func(w *model.HTTPStats_StatsByStatusCodeEntryBuilder) { |
| 74 | w.SetKey(int32(code)) |
| 75 | w.SetValue(func(w *model.HTTPStats_DataBuilder) { |
| 76 | w.SetCount(uint32(stats.Count)) |
| 77 | if latencies := stats.Latencies; latencies != nil { |
| 78 | |
| 79 | // TODO: can we get a streaming marshaller for latencies? |
| 80 | blob, _ := proto.Marshal(latencies.ToProto()) |
| 81 | w.SetLatencies(func(b *bytes.Buffer) { |
| 82 | b.Write(blob) |
| 83 | }) |
| 84 | } else { |
| 85 | w.SetFirstLatencySample(stats.FirstLatencySample) |
| 86 | } |
| 87 | }) |
| 88 | }) |
| 89 | |
| 90 | staticTags |= stats.StaticTags |
| 91 | for _, dynamicTag := range stats.DynamicTags { |
| 92 | dynamicTags[dynamicTag] = struct{}{} |
| 93 | } |
| 94 | } |
| 95 | }) |
| 96 | |
| 97 | } |
| 98 | return staticTags, dynamicTags |
| 99 | } |
| 100 | |
| 101 | func (e *httpEncoder) Close() { |
| 102 | if e == nil { |