blob: 67ba1e62c4fa87e80f42748891e74b4d711b5b99 [file] [log] [blame]
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you 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
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package main
import (
basecmd ""
generatedopenapi ""
openapinamer ""
genericapiserver ""
swckprov ""
type Adapter struct {
// BaseURL is the address of OAP cluster
BaseURL string
// MetricRegex is a regular expression to filter metrics retrieved from OAP cluster
MetricRegex string
// RefreshRegistryInterval is the refresh window for syncing metrics with OAP cluster
RefreshRegistryInterval time.Duration
// Message is printed on successful startup
Message string
func main() {
defer logs.FlushLogs()
cmd := &Adapter{}
cmd.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(apiserver.Scheme))
cmd.OpenAPIConfig.Info.Title = "apache-skywalking-adapter"
cmd.OpenAPIConfig.Info.Version = "1.0.0"
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().StringVar(&cmd.BaseURL, "oap-addr", "http://oap:12800/graphql", "the address of OAP cluster")
cmd.Flags().StringVar(&cmd.MetricRegex, "metric-filter-regex", "", "a regular expression to filter metrics retrieved from OAP cluster")
cmd.Flags().DurationVar(&cmd.RefreshRegistryInterval, "refresh-interval", 10*time.Second,
"the interval at which to update the cache of available metrics from OAP cluster")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
if err := cmd.Flags().Parse(os.Args); err != nil {
klog.Fatalf("failed to parse arguments: %v", err)
p, err := swckprov.NewProvider(cmd.BaseURL, cmd.MetricRegex, cmd.RefreshRegistryInterval)
if err != nil {
klog.Fatalf("unable to build p: %v", err)
if err := cmd.Run(wait.NeverStop); err != nil {
klog.Fatalf("unable to run custom metrics adapter: %v", err)