mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
MAIN HAD NOT COMPILED SINCE 2026-07-30. Commit 5e3210f759 rewrote tables.go in three telemetry packages and the sentrytypes Event struct without updating their consumers, while its message claimed the read paths 'build clean' — proven false with a detached worktree at clean HEAD. That is why the deployed backend is SHA-pinned and stale: CI could not build main at all. THE RENAME: /api/v1|v2|v3|v4/<rest> -> /v1/o11y/<rest> (290 replacements; the host already says api, so the path never does, and one live generation carries no version segments). 21 duplicate v1 registrations DELETED with their v2 twins kept — gorilla/mux is first-match, so after the collapse the v1 line would have shadowed v2 silently, with no error, forever: rules (6), dashboards (6), services/top_operations/entry_point_operations/ttl (5), features, query_range v3+v4 -> v5, metrics/dashboards. 16 orphaned handler funcs (430 lines) deleted. CONSUMERS MIGRATED to the one-way table names, never the reverse: tables.go's deletion of the versioned constants was deliberate (stated three times), and the new blocks are positional 1:1 rewrites of the old, so every resolution is a constant the same commit declared — SpanIndexV3->span, LogsV2->log, SamplesV4->metric, TimeseriesV4->series, UpdatedMetadata->descriptor, ambiguity on operation-vs-trace settled by tables.go's own inline comments. sentrytypes.Frame/Event.Frames/Event.Handled RECONSTRUCTED, not guessed: pinned independently by eventsql.go's projection, eventstore.go's scan targets and module.go's clampLine/InApp, and asserted literally by the pre-existing TestFramesRoundTrip. TraceSummary.Sample -> Message (event.error has no sample column). Event.Sample deleted: a field that always read "" while claiming to hold the occurrence JSON. PATH MANGLERS KILLED, both deployment shapes: mount.go rewriteExternalPath+ setPath deleted (it mapped /v1/o11y/services -> /api/services => 404 on the cloud-binary path — proven with a real test before deletion); server.go StripPrefix removed (it reduced /v1/o11y/services -> /services => the web catch-all answered index.html on the standalone path). versionless.go + versionless_test.go + both call sites deleted: its regex matched 0 of the registered routes and walked the router at every startup to register nothing — the second spelling of one path, gone with the mechanism that needed it. FRONTEND: prependBase '/api/v1/' -> '/v1/o11y/' (both baseURL branches), 17 /api/v1/assistant literals renamed (note: no assistant route exists in pkg/ — client-only surface, a real product gap, not papered over), 21 MSW mocks moved so they intercept the paths the app now requests. GATE, all executed: go build ./... green; go test ./... green (exit 0); 0 /api/v[0-9] references in pkg code (frontend's 5 are query-builder escaping fixtures); 0 duplicate (method,path) registrations; /v1/o11y/services survives both mount.go and server.go untouched. Co-authored-by: Hanzo Dev <[email protected]>
112 lines
3.6 KiB
Go
112 lines
3.6 KiB
Go
package telemetrymetadata
|
|
|
|
import (
|
|
"context"
|
|
"regexp"
|
|
"testing"
|
|
|
|
dsmock "github.com/hanzo-ds/mock"
|
|
"github.com/hanzoai/o11y/pkg/errors"
|
|
"github.com/hanzoai/o11y/pkg/flagger/flaggertest"
|
|
"github.com/hanzoai/o11y/pkg/instrumentation/instrumentationtest"
|
|
"github.com/hanzoai/o11y/pkg/telemetryaudit"
|
|
"github.com/hanzoai/o11y/pkg/telemetrylogs"
|
|
"github.com/hanzoai/o11y/pkg/telemetrymeter"
|
|
"github.com/hanzoai/o11y/pkg/telemetrymetrics"
|
|
"github.com/hanzoai/o11y/pkg/telemetrystore"
|
|
"github.com/hanzoai/o11y/pkg/telemetrystore/telemetrystoretest"
|
|
"github.com/hanzoai/o11y/pkg/telemetrytraces"
|
|
"github.com/hanzoai/o11y/pkg/types/telemetrytypes"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type regexMatcher struct {
|
|
}
|
|
|
|
func (m *regexMatcher) Match(expectedSQL, actualSQL string) error {
|
|
re, err := regexp.Compile(expectedSQL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !re.MatchString(actualSQL) {
|
|
return errors.NewInvalidInputf(errors.CodeInvalidInput, "expected query to contain %s, got %s", expectedSQL, actualSQL)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func TestGetFirstSeenFromMetricMetadata(t *testing.T) {
|
|
mockTelemetryStore := telemetrystoretest.New(telemetrystore.Config{}, ®exMatcher{})
|
|
mock := mockTelemetryStore.Mock()
|
|
|
|
metadata := NewTelemetryMetaStore(
|
|
instrumentationtest.New().ToProviderSettings(),
|
|
mockTelemetryStore,
|
|
telemetrytraces.DBName,
|
|
telemetrytraces.SpanAttributeTableName,
|
|
telemetrytraces.SpanKeyTableName,
|
|
telemetrytraces.SpanTableName,
|
|
telemetrymetrics.DBName,
|
|
telemetrymetrics.AttributeTableName,
|
|
telemetrymeter.DBName,
|
|
telemetrymeter.SamplesAgg1dTableName,
|
|
telemetrylogs.DBName,
|
|
telemetrylogs.LogTableName,
|
|
telemetrylogs.LogAttributeTableName,
|
|
telemetrylogs.LogKeyTableName,
|
|
telemetrylogs.LogResourceKeyTableName,
|
|
telemetryaudit.DBName,
|
|
telemetryaudit.AuditLogsTableName,
|
|
telemetryaudit.TagAttributesTableName,
|
|
telemetryaudit.LogAttributeKeysTblName,
|
|
telemetryaudit.LogResourceKeysTblName,
|
|
DBName,
|
|
AttributesMetadataLocalTableName,
|
|
ColumnEvolutionMetadataTableName,
|
|
flaggertest.New(t),
|
|
)
|
|
|
|
lookupKeys := []telemetrytypes.MetricMetadataLookupKey{
|
|
{
|
|
MetricName: "metric1",
|
|
AttributeName: "attr1",
|
|
AttributeValue: "val1",
|
|
},
|
|
{
|
|
MetricName: "metric2",
|
|
AttributeName: "attr2",
|
|
AttributeValue: "val2",
|
|
},
|
|
}
|
|
|
|
// Datastore tuple syntax is (x, y, z)
|
|
// the structure should lead to:
|
|
// SELECT ... WHERE (metric_name, attr_name, attr_string_value) IN ((?, ?, ?), (?, ?, ?)) ...
|
|
|
|
expectedQuery := `SELECT metric_name, attr_name, attr_string_value, min\(first_reported_unix_milli\) AS first_seen FROM event.metric_attribute WHERE \(metric_name, attr_name, attr_string_value\) IN \(\(\?, \?, \?\), \(\?, \?, \?\)\) GROUP BY metric_name, attr_name, attr_string_value ORDER BY first_seen`
|
|
|
|
// Note: regexMatcher uses regexp.MatchString, so we escape parens and ?
|
|
|
|
mock.ExpectQuery(expectedQuery).
|
|
WithArgs("metric1", "attr1", "val1", "metric2", "attr2", "val2").
|
|
WillReturnRows(dsmock.NewRows([]dsmock.ColumnType{
|
|
{Name: "metric_name", Type: "String"},
|
|
{Name: "attr_name", Type: "String"},
|
|
{Name: "attr_string_value", Type: "String"},
|
|
{Name: "first_seen", Type: "UInt64"},
|
|
}, [][]any{
|
|
{"metric1", "attr1", "val1", uint64(1000)},
|
|
{"metric2", "attr2", "val2", uint64(2000)},
|
|
}))
|
|
|
|
result, err := metadata.GetFirstSeenFromMetricMetadata(context.Background(), lookupKeys)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1000), result[lookupKeys[0]])
|
|
assert.Equal(t, int64(2000), result[lookupKeys[1]])
|
|
|
|
if err := mock.ExpectationsWereMet(); err != nil {
|
|
t.Errorf("there were unfulfilled expectations: %s", err)
|
|
}
|
|
}
|