apps/jetty.go (65 lines of code) (raw):
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apps
import (
"context"
"fmt"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator/fluentbit"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator/otel"
)
type MetricsReceiverJetty struct {
confgenerator.ConfigComponent `yaml:",inline"`
confgenerator.MetricsReceiverSharedJVM `yaml:",inline"`
confgenerator.MetricsReceiverSharedCollectJVM `yaml:",inline"`
}
const defaultJettyEndpoint = "localhost:1099"
func (r MetricsReceiverJetty) Type() string {
return "jetty"
}
func (r MetricsReceiverJetty) Pipelines(_ context.Context) ([]otel.ReceiverPipeline, error) {
targetSystem := "jetty"
if r.MetricsReceiverSharedCollectJVM.ShouldCollectJVMMetrics() {
targetSystem = fmt.Sprintf("%s,%s", targetSystem, "jvm")
}
return r.MetricsReceiverSharedJVM.
WithDefaultEndpoint(defaultJettyEndpoint).
ConfigurePipelines(
targetSystem,
[]otel.Component{
otel.NormalizeSums(),
otel.MetricsTransform(
otel.AddPrefix("workload.googleapis.com"),
),
otel.ModifyInstrumentationScope(r.Type(), "1.0"),
},
)
}
func init() {
confgenerator.MetricsReceiverTypes.RegisterType(func() confgenerator.MetricsReceiver { return &MetricsReceiverJetty{} })
}
type LoggingProcessorJettyAccess struct {
confgenerator.ConfigComponent `yaml:",inline"`
}
func (p LoggingProcessorJettyAccess) Components(ctx context.Context, tag string, uid string) []fluentbit.Component {
return genericAccessLogParser(ctx, p.Type(), tag, uid)
}
func (LoggingProcessorJettyAccess) Type() string {
return "jetty_access"
}
type LoggingReceiverJettyAccess struct {
LoggingProcessorJettyAccess `yaml:",inline"`
ReceiverMixin confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly"`
}
func (r LoggingReceiverJettyAccess) Components(ctx context.Context, tag string) []fluentbit.Component {
if len(r.ReceiverMixin.IncludePaths) == 0 {
r.ReceiverMixin.IncludePaths = []string{
"/opt/logs/*.request.log",
}
}
c := r.ReceiverMixin.Components(ctx, tag)
c = append(c, r.LoggingProcessorJettyAccess.Components(ctx, tag, "jetty_access")...)
return c
}
func init() {
confgenerator.LoggingProcessorTypes.RegisterType(func() confgenerator.LoggingProcessor { return &LoggingProcessorJettyAccess{} })
confgenerator.LoggingReceiverTypes.RegisterType(func() confgenerator.LoggingReceiver { return &LoggingReceiverJettyAccess{} })
}