Skip to content

Commit 2132d77

Browse files
authored
[V2 API] Merger support for observation API (#1094)
1 parent a7295dc commit 2132d77

File tree

18 files changed

+353
-195
lines changed

18 files changed

+353
-195
lines changed

cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ var (
6868
tmcfCsvBucket = flag.String("tmcf_csv_bucket", "", "The GCS bucket that contains tmcf and csv files")
6969
tmcfCsvFolder = flag.String("tmcf_csv_folder", "", "GCS folder for an import. An import must have a unique prefix within a bucket.")
7070
memdbPath = flag.String("memdb_path", "", "File path of memdb config")
71+
// Remote mixer url. The API serves merged data from local and remote mixer
72+
remoteMixerURL = flag.String("remote_mixer_url", "", "Remote mixer url to fetch and merge data for API response.")
7173
// Profile startup memory instead of listening for requests
7274
startupMemoryProfile = flag.String("startup_memprof", "", "File path to write the memory profile of mixer startup to")
7375
// Serve live profiles of the process (CPU, memory, etc.) over HTTP on this port
@@ -174,6 +176,7 @@ func main() {
174176
*mixerProject,
175177
*bqDataset,
176178
*schemaPath,
179+
*remoteMixerURL,
177180
)
178181
if err != nil {
179182
log.Fatalf("Failed to create metadata: %v", err)

internal/merger/observation.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package merger provides function to merge V2 API ressponses
16+
package merger
17+
18+
import (
19+
pbv2 "github.com/datacommonsorg/mixer/internal/proto/v2"
20+
)
21+
22+
// MergeObservation merges two V2 observation response.
23+
func MergeObservation(
24+
o1, o2 *pbv2.ObservationResponse) (*pbv2.ObservationResponse, error) {
25+
for v, vData := range o2.ByVariable {
26+
if _, ok := o1.ByVariable[v]; !ok {
27+
o1.ByVariable[v] = &pbv2.VariableObservation{
28+
ByEntity: map[string]*pbv2.EntityObservation{},
29+
}
30+
}
31+
for e, eData := range vData.ByEntity {
32+
if _, ok := o1.ByVariable[v].ByEntity[e]; !ok {
33+
o1.ByVariable[v].ByEntity[e] = &pbv2.EntityObservation{
34+
OrderedFacets: []*pbv2.FacetObservation{},
35+
}
36+
}
37+
eData.OrderedFacets = append(
38+
eData.OrderedFacets,
39+
o1.ByVariable[v].ByEntity[e].OrderedFacets...,
40+
)
41+
}
42+
}
43+
for facetID, facet := range o2.Facets {
44+
o1.Facets[facetID] = facet
45+
}
46+
return o1, nil
47+
}

internal/proto/debug.pb.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/entity.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/service/mixer_grpc.pb.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/stat.pb.go

Lines changed: 37 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/stat_var.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/v1/event.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/v2/event.pb.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/v2/observation.pb.go

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)