Skip to content

Commit

Permalink
[exporter/mezmoexporter] unexport mezmo structs (#24842)
Browse files Browse the repository at this point in the history
Unexport the `MezmoLogLine` and `MezmoLogBody` structs. They don't need to be exported as part of the Go API.
  • Loading branch information
atoulme committed Aug 3, 2023
1 parent 7fc60e5 commit f4f04fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .chloggen/unexport-mezmo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: mezmoexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Unexport the `MezmoLogLine` and `MezmoLogBody` structs

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24842]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
10 changes: 5 additions & 5 deletions exporter/mezmoexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ type mezmoExporter struct {
wg sync.WaitGroup
}

type MezmoLogLine struct {
type mezmoLogLine struct {
Timestamp int64 `json:"timestamp"`
Line string `json:"line"`
App string `json:"app"`
Level string `json:"level"`
Meta map[string]string `json:"meta"`
}

type MezmoLogBody struct {
Lines []MezmoLogLine `json:"lines"`
type mezmoLogBody struct {
Lines []mezmoLogLine `json:"lines"`
}

func newLogsExporter(config *Config, settings component.TelemetrySettings, buildInfo component.BuildInfo, logger *zap.Logger) *mezmoExporter {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (m *mezmoExporter) stop(context.Context) (err error) {
func (m *mezmoExporter) logDataToMezmo(ld plog.Logs) error {
var errs error

var lines []MezmoLogLine
var lines []mezmoLogLine

// Convert the log resources to mezmo lines...
resourceLogs := ld.ResourceLogs()
Expand Down Expand Up @@ -118,7 +118,7 @@ func (m *mezmoExporter) logDataToMezmo(ld plog.Logs) error {
logLevel = "info"
}

line := MezmoLogLine{
line := mezmoLogLine{
Timestamp: tstamp,
Line: truncateString(log.Body().Str(), maxMessageSize),
App: truncateString(app, maxAppnameLen),
Expand Down
10 changes: 5 additions & 5 deletions exporter/mezmoexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type testServer struct {
url string
}

type httpAssertionCallback func(req *http.Request, body MezmoLogBody) (int, string)
type httpAssertionCallback func(req *http.Request, body mezmoLogBody) (int, string)
type testServerParams struct {
t *testing.T
assertionsCallback httpAssertionCallback
Expand All @@ -124,7 +124,7 @@ func createHTTPServer(params *testServerParams) testServer {
params.t.Fatal(err)
}

var logBody MezmoLogBody
var logBody mezmoLogBody
if err = json.Unmarshal(body, &logBody); err != nil {
w.WriteHeader(http.StatusUnprocessableEntity)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func createLogger() (*zap.Logger, *observer.ObservedLogs) {
func TestLogsExporter(t *testing.T) {
httpServerParams := testServerParams{
t: t,
assertionsCallback: func(req *http.Request, body MezmoLogBody) (int, string) {
assertionsCallback: func(req *http.Request, body mezmoLogBody) (int, string) {
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
assert.Equal(t, "mezmo-otel-exporter/"+buildInfo.Version, req.Header.Get("User-Agent"))
return http.StatusOK, ""
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestLogsExporter(t *testing.T) {
func TestAddsRequiredAttributes(t *testing.T) {
httpServerParams := testServerParams{
t: t,
assertionsCallback: func(req *http.Request, body MezmoLogBody) (int, string) {
assertionsCallback: func(req *http.Request, body mezmoLogBody) (int, string) {
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
assert.Equal(t, "mezmo-otel-exporter/"+buildInfo.Version, req.Header.Get("User-Agent"))

Expand Down Expand Up @@ -240,7 +240,7 @@ func Test404IngestError(t *testing.T) {

httpServerParams := testServerParams{
t: t,
assertionsCallback: func(req *http.Request, body MezmoLogBody) (int, string) {
assertionsCallback: func(req *http.Request, body mezmoLogBody) (int, string) {
return http.StatusNotFound, `{"foo":"bar"}`
},
}
Expand Down

0 comments on commit f4f04fe

Please sign in to comment.